Work on configuration

This commit is contained in:
Modulos 2017-05-13 10:00:07 +02:00
parent 75d93b2aad
commit 8017fbb90f
3 changed files with 16 additions and 24 deletions

View file

@ -27,6 +27,7 @@
<div class="form-group">
Select VM Configuration:
<select name="vm_image_id">
<option value="-1" selected> None </option>
{% for image in images %}
<option value="{{image.id}}"> {{image.name}} </option>

View file

@ -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)
@ -440,11 +441,12 @@ 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'))

View file

@ -110,33 +110,21 @@ class OpenNebulaManager():
return None
def create_vm(self, template_id, image_id=None, ssh_key=None):
extra_template_formater = """<CONTEXT>
<SSH_PUBLIC_KEY>{ssh_key}</SSH_PUBLIC_KEY>
</CONTEXT>
<DISK>
<IMAGE_ID>{image_id}</IMAGE_ID>
</DISK>
"""
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= """<CONTEXT>
<SSH_PUBLIC_KEY>{ssh_key}</SSH_PUBLIC_KEY>
</CONTEXT>
"""
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: