From 921fa209ce567ed2775002b80ad52ae5cac5acba Mon Sep 17 00:00:00 2001 From: Modulos Date: Sun, 14 May 2017 02:18:16 +0200 Subject: [PATCH] Merge image into template --- opennebula_api/models.py | 56 ++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index eb6d64a2..e225ce0f 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -146,26 +146,56 @@ class OpenNebulaManager(): {memory} {vcpu} {cpu} - + + {ssh} + + """ + try: + disk = template.template.disks[0] + image_id = disk.image_id + vm_specs = vm_specs_formatter.format( + vcpu=int(specs['cpu']), + cpu=0.1* int(specs['cpu']), + memory=1024 * int(specs['memory']), + ssh=ssh_key + + ) + vm_specs += """ fs {size} vd - - - {ssh} - - - """ - vm_id = template.instantiate(name ='', - pending=False, - extra_template=vm_specs_formatter.format( + {image_id} + + + """.format(size=1024 * int(specs['disk_size']), + image_id=image_id) + + except: + disk = template.template.disks[0] + image = disk.image + image_uname = disk.image_uname + + vm_specs = vm_specs_formatter.format( vcpu=int(specs['cpu']), cpu=0.1* int(specs['cpu']), - size=1024 * int(specs['disk_size']), memory=1024 * int(specs['memory']), ssh=ssh_key - ) - ) + + ) + vm_specs += """ + fs + {size} + vd + {image} + {image_uname} + + + """.format(size=1024 * int(specs['disk_size']), + image=image, + image_uname=image_uname) + vm_id = template.instantiate(name ='', + pending=False, + extra_template=vm_specs, ) try: self.oneadmin_client.call(