Revision 76f01c50

b/kamaki/client.py
34 34
import json
35 35
import logging
36 36

  
37
from base64 import b64encode
37 38
from httplib import HTTPConnection, HTTPSConnection
38 39
from urlparse import urlparse
39 40

  
......
126 127
        reply = self._get(path)
127 128
        return reply['server']
128 129
    
129
    def create_server(self, name, flavor, image):
130
    def create_server(self, name, flavor, image, personality=None):
131
        """personality is a list of (path, data) tuples"""
132
        
130 133
        req = {'name': name, 'flavorRef': flavor, 'imageRef': image}
134
        if personality:
135
            p = []
136
            for path, data in personality:
137
                contents = b64encode(data)
138
                p.append({'path': path, 'contents': contents})
139
            req['personality'] = p
140
        
131 141
        body = json.dumps({'server': req})
132 142
        reply = self._post('/servers', body)
133 143
        return reply['server']
b/kamaki/kamaki.py
246 246
                            help='use flavor FLAVOR_ID')
247 247
        parser.add_option('-i', dest='image', metavar='IMAGE_ID', default=1,
248 248
                            help='use image IMAGE_ID')
249

  
249
        parser.add_option('--personality', dest='personality', action='append',
250
                            metavar='PATH,SERVERPATH',
251
                            help='add a personality file')
252
    
250 253
    def main(self, name):
251 254
        flavor_id = int(self.flavor)
252 255
        image_id = int(self.image)
253
        reply = self.client.create_server(name, flavor_id, image_id)
256
        personality = []
257
        if self.personality:
258
            for p in self.personality:
259
                lpath, sep, rpath = p.partition(',')
260
                if not lpath or not rpath:
261
                    logging.error("Invalid personality argument '%s'", p)
262
                    return
263
                if not os.path.exists(lpath):
264
                    logging.error("File %s does not exist", lpath)
265
                    return
266
                with open(lpath) as f:
267
                    personality.append((rpath, f.read()))
268
        
269
        reply = self.client.create_server(name, flavor_id, image_id,
270
                                            personality)
254 271
        print_dict(reply)
255 272

  
256 273

  

Also available in: Unified diff