Revision 79b7dbb7
b/snf-cyclades-app/synnefo/api/servers.py | ||
---|---|---|
303 | 303 |
|
304 | 304 |
# Ensure that request if for active flavor |
305 | 305 |
flavor = util.get_flavor(flavor_id, include_deleted=False) |
306 |
password = util.random_password() |
|
307 | 306 |
|
308 | 307 |
count = VirtualMachine.objects.filter(userid=request.user_uniq, |
309 | 308 |
deleted=False).count() |
... | ... | |
356 | 355 |
flavor=flavor, |
357 | 356 |
action="CREATE") |
358 | 357 |
|
358 |
password = util.random_password() |
|
359 |
|
|
360 |
# TODO: Just copied code from backend.py to fix the images backend_id |
|
361 |
# for archipelagos. Find a better way and remove double checks |
|
362 |
img_id = image['backend_id'] |
|
363 |
provider = None |
|
364 |
disk_template = flavor.disk_template |
|
365 |
if flavor.disk_template.startswith("ext"): |
|
366 |
disk_template, provider = flavor.disk_template.split("_", 1) |
|
367 |
if provider == 'vlmc': |
|
368 |
img_id = 'null' |
|
369 |
|
|
359 | 370 |
# dispatch server created signal |
360 | 371 |
server_created.send(sender=vm, created_vm_params={ |
361 |
'personality': personality, |
|
362 |
'password': password |
|
372 |
'img_id': img_id, |
|
373 |
'img_passwd': password, |
|
374 |
'img_format': str(image['format']), |
|
375 |
'img_personality': str(personality), |
|
376 |
'img_properties': str(image['metadata']), |
|
363 | 377 |
}) |
364 | 378 |
|
365 | 379 |
try: |
366 |
jobID = create_instance(vm, nic, flavor, image, password, personality)
|
|
380 |
jobID = create_instance(vm, nic, flavor, image) |
|
367 | 381 |
except GanetiApiError: |
368 | 382 |
vm.delete() |
369 | 383 |
raise |
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
301 | 301 |
source_date=etime, message=message, details=details) |
302 | 302 |
|
303 | 303 |
|
304 |
def create_instance(vm, public_nic, flavor, image, password, personality):
|
|
304 |
def create_instance(vm, public_nic, flavor, image, password=None):
|
|
305 | 305 |
"""`image` is a dictionary which should contain the keys: |
306 | 306 |
'backend_id', 'format' and 'metadata' |
307 | 307 |
|
... | ... | |
351 | 351 |
# kw['os'] = settings.GANETI_OS_PROVIDER |
352 | 352 |
kw['ip_check'] = False |
353 | 353 |
kw['name_check'] = False |
354 |
|
|
354 | 355 |
# Do not specific a node explicitly, have |
355 | 356 |
# Ganeti use an iallocator instead |
356 |
# |
|
357 | 357 |
#kw['pnode'] = rapi.GetNodes()[0] |
358 |
|
|
358 | 359 |
kw['dry_run'] = settings.TEST |
359 | 360 |
|
360 | 361 |
kw['beparams'] = { |
361 |
'auto_balance': True, |
|
362 |
'vcpus': flavor.cpu, |
|
363 |
'memory': flavor.ram} |
|
362 |
'auto_balance': True, |
|
363 |
'vcpus': flavor.cpu, |
|
364 |
'memory': flavor.ram} |
|
365 |
|
|
366 |
if provider == 'vlmc': |
|
367 |
image_id = 'null' |
|
368 |
else: |
|
369 |
image_id = image['backend_id'] |
|
364 | 370 |
|
365 | 371 |
kw['osparams'] = { |
366 |
'img_id': image['backend_id'], |
|
367 |
'img_passwd': password, |
|
372 |
'config_url': vm.config_url, |
|
373 |
# Store image id and format to Ganeti |
|
374 |
'img_id': image_id, |
|
368 | 375 |
'img_format': image['format']} |
369 |
if personality: |
|
370 |
kw['osparams']['img_personality'] = json.dumps(personality) |
|
371 |
|
|
372 |
if provider != None and provider == 'vlmc': |
|
373 |
kw['osparams']['img_id'] = 'null' |
|
374 | 376 |
|
375 |
kw['osparams']['img_properties'] = json.dumps(image['metadata']) |
|
377 |
if password: |
|
378 |
# Only for admin created VMs !! |
|
379 |
kw['osparams']['img_passwd'] = password |
|
376 | 380 |
|
377 | 381 |
# Defined in settings.GANETI_CREATEINSTANCE_KWARGS |
378 | 382 |
# kw['hvparams'] = dict(serial_console=False) |
383 |
|
|
379 | 384 |
log.debug("Creating instance %s", utils.hide_pass(kw)) |
380 | 385 |
with pooled_rapi_client(vm) as client: |
381 | 386 |
return client.CreateInstance(**kw) |
b/snf-cyclades-app/synnefo/vmapi/models.py | ||
---|---|---|
48 | 48 |
log.info("Setting vmapi params with key %s for %s", key, sender) |
49 | 49 |
backend.set(key, json_value) |
50 | 50 |
|
51 |
# inject sender (vm) with its parameters url
|
|
52 |
setattr(sender, 'params_url', "%s%s" % (settings.BASE_URL,
|
|
51 |
# inject sender (vm) with its configuration url
|
|
52 |
setattr(sender, 'config_url', "%s%s" % (settings.BASE_URL,
|
|
53 | 53 |
reverse('vmapi_server_params', |
54 | 54 |
args=[uuid]))) |
55 | 55 |
return uuid |
b/snf-cyclades-app/synnefo/vmapi/tests.py | ||
---|---|---|
66 | 66 |
params = {'password': 'X^942Jjfdsa', 'personality': {}} |
67 | 67 |
uuid = create_server_params(sender=vm, created_vm_params=params) |
68 | 68 |
|
69 |
self.assertEqual(vm.params_url, settings.BASE_URL + '/vmapi/server-params/%s' % uuid)
|
|
69 |
self.assertEqual(vm.config_url, settings.BASE_URL + '/vmapi/server-params/%s' % uuid)
|
|
70 | 70 |
key = "vmapi_%s" % uuid |
71 | 71 |
self.assertEqual(type(backend.get(key)), str) |
72 | 72 |
data = json.loads(backend.get(key)) |
Also available in: Unified diff