From 8017fbb90fcf9539a5e7ff52cc62c7c55eedc6d1 Mon Sep 17 00:00:00 2001 From: Modulos Date: Sat, 13 May 2017 10:00:07 +0200 Subject: [PATCH] Work on configuration --- .../hosting/create_virtual_machine.html | 3 +- hosting/views.py | 8 +++-- opennebula_api/models.py | 29 ++++++------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/hosting/templates/hosting/create_virtual_machine.html b/hosting/templates/hosting/create_virtual_machine.html index 405b2988..3618fd6b 100644 --- a/hosting/templates/hosting/create_virtual_machine.html +++ b/hosting/templates/hosting/create_virtual_machine.html @@ -27,9 +27,10 @@
Select VM Configuration: diff --git a/hosting/views.py b/hosting/views.py index 0025a40d..4f0699d3 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -394,7 +394,8 @@ class PaymentVMView(LoginRequiredMixin, FormView): specifications = request.session.get('template') vm_template_id = specifications.get('id', 1) - vm_image_id = request.session.get('image').get('id', 1) + + vm_image_id = request.session.get('image').get('id', None) final_price = specifications.get('price', 1) @@ -439,12 +440,13 @@ class PaymentVMView(LoginRequiredMixin, FormView): except UserHostingKey.DoesNotExist: pass + # Create a vm using logged user vm_id = manager.create_vm( template_id=vm_template_id, - ssh_key=user_key.public_key, image_id=vm_image_id, + ssh_key=user_key.public_key, ) # Create a Hosting Order @@ -586,7 +588,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): image_id = request.POST.get('vm_image_id') image = manager.get_image(image_id) request.session['template'] = VirtualMachineTemplateSerializer(template).data - request.session['image'] = ImageSerializer(image).data + #request.session['image'] = ImageSerializer(image).data return redirect(reverse('hosting:payment')) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index f543d0ec..2f8744e3 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -110,33 +110,21 @@ class OpenNebulaManager(): return None def create_vm(self, template_id, image_id=None, ssh_key=None): - extra_template_formater = """ - {ssh_key} - - - {image_id} - - """ template = self.get_template(template_id) vm_id = template.instantiate(name ='', pending=False, extra_template='') - image = self.get_image(image_id) - image_name = "{image_name}{template_name}{vm_id}".format( - image_name=image.name, - template_name=template.name, - vm_id = vm_id, - ) + extra_template= """ + {ssh_key} + + """ - image_id = image.clone(name=image_name) + extra_template.format(ssh_key=ssh_key) self.oneadmin_client.call( - oca.VmTemplate.METHODS['update'], + oca.VirtualMachine.METHODS['update'], vm_id, - extra_template_formater.format( - ssh_key=ssh_key, - image_id=image_id - ), + extra_template, # 0 = Replace / 1 = Merge 1, ) @@ -282,7 +270,8 @@ class OpenNebulaManager(): public_images = [ image for image in self._get_image_pool() - if 'public-' in image.name + #XXX: Change this + if 'READY' in image.str_state ] return public_images except ConnectionRefusedError: