Commit 76f01c50 authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Add personality support for server create

parent 5d1d131b
......@@ -34,6 +34,7 @@
import json
import logging
from base64 import b64encode
from httplib import HTTPConnection, HTTPSConnection
from urlparse import urlparse
......@@ -126,8 +127,17 @@ class Client(object):
reply = self._get(path)
return reply['server']
def create_server(self, name, flavor, image):
def create_server(self, name, flavor, image, personality=None):
"""personality is a list of (path, data) tuples"""
req = {'name': name, 'flavorRef': flavor, 'imageRef': image}
if personality:
p = []
for path, data in personality:
contents = b64encode(data)
p.append({'path': path, 'contents': contents})
req['personality'] = p
body = json.dumps({'server': req})
reply = self._post('/servers', body)
return reply['server']
......@@ -246,11 +246,28 @@ class CreateServer(Command):
help='use flavor FLAVOR_ID')
parser.add_option('-i', dest='image', metavar='IMAGE_ID', default=1,
help='use image IMAGE_ID')
parser.add_option('--personality', dest='personality', action='append',
help='add a personality file')
def main(self, name):
flavor_id = int(self.flavor)
image_id = int(self.image)
reply = self.client.create_server(name, flavor_id, image_id)
personality = []
if self.personality:
for p in self.personality:
lpath, sep, rpath = p.partition(',')
if not lpath or not rpath:
logging.error("Invalid personality argument '%s'", p)
if not os.path.exists(lpath):
logging.error("File %s does not exist", lpath)
with open(lpath) as f:
reply = self.client.create_server(name, flavor_id, image_id,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment