Work on configuration
This commit is contained in:
		
					parent
					
						
							
								75d93b2aad
							
						
					
				
			
			
				commit
				
					
						8017fbb90f
					
				
			
		
					 3 changed files with 16 additions and 24 deletions
				
			
		|  | @ -27,9 +27,10 @@ | ||||||
|                     <div class="form-group"> |                     <div class="form-group"> | ||||||
|                         Select VM Configuration: |                         Select VM Configuration: | ||||||
|                         <select name="vm_image_id"> |                         <select name="vm_image_id"> | ||||||
|  |                             <option value="-1" selected> None </option> | ||||||
|                             {% for image in images %} |                             {% for image in images %} | ||||||
|                                  |                                  | ||||||
|                                 <option value="{{image.id}}">{{image.name}} </option> |                                 <option value="{{image.id}}"> {{image.name}} </option> | ||||||
|                                  |                                  | ||||||
|                             {% endfor %} |                             {% endfor %} | ||||||
|                         </select> |                         </select> | ||||||
|  |  | ||||||
|  | @ -394,7 +394,8 @@ class PaymentVMView(LoginRequiredMixin, FormView): | ||||||
|             specifications = request.session.get('template') |             specifications = request.session.get('template') | ||||||
| 
 | 
 | ||||||
|             vm_template_id = specifications.get('id', 1) |             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) |             final_price = specifications.get('price', 1) | ||||||
| 
 | 
 | ||||||
|  | @ -440,11 +441,12 @@ class PaymentVMView(LoginRequiredMixin, FormView): | ||||||
|             except UserHostingKey.DoesNotExist: |             except UserHostingKey.DoesNotExist: | ||||||
|                 pass |                 pass | ||||||
|              |              | ||||||
|  | 
 | ||||||
|             # Create a vm using logged user |             # Create a vm using logged user | ||||||
|             vm_id = manager.create_vm( |             vm_id = manager.create_vm( | ||||||
|                 template_id=vm_template_id, |                 template_id=vm_template_id, | ||||||
|                 ssh_key=user_key.public_key, |  | ||||||
|                 image_id=vm_image_id,  |                 image_id=vm_image_id,  | ||||||
|  |                 ssh_key=user_key.public_key, | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             # Create a Hosting Order |             # Create a Hosting Order | ||||||
|  | @ -586,7 +588,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): | ||||||
|         image_id = request.POST.get('vm_image_id') |         image_id = request.POST.get('vm_image_id') | ||||||
|         image = manager.get_image(image_id) |         image = manager.get_image(image_id) | ||||||
|         request.session['template'] = VirtualMachineTemplateSerializer(template).data |         request.session['template'] = VirtualMachineTemplateSerializer(template).data | ||||||
|         request.session['image'] = ImageSerializer(image).data |         #request.session['image'] = ImageSerializer(image).data | ||||||
|         return redirect(reverse('hosting:payment')) |         return redirect(reverse('hosting:payment')) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -110,33 +110,21 @@ class OpenNebulaManager(): | ||||||
|             return None |             return None | ||||||
| 
 | 
 | ||||||
|     def create_vm(self, template_id, image_id=None, ssh_key=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) |         template = self.get_template(template_id) | ||||||
|         vm_id = template.instantiate(name ='', pending=False, extra_template='') |         vm_id = template.instantiate(name ='', pending=False, extra_template='') | ||||||
|         image = self.get_image(image_id) |  | ||||||
| 
 | 
 | ||||||
|         image_name = "{image_name}{template_name}{vm_id}".format( |         extra_template= """<CONTEXT> | ||||||
|                 image_name=image.name, |                             <SSH_PUBLIC_KEY>{ssh_key}</SSH_PUBLIC_KEY> | ||||||
|                 template_name=template.name, |                            </CONTEXT> | ||||||
|                 vm_id = vm_id, |                         """ | ||||||
|                 ) |  | ||||||
| 
 | 
 | ||||||
|         image_id = image.clone(name=image_name) |         extra_template.format(ssh_key=ssh_key) | ||||||
| 
 | 
 | ||||||
|         self.oneadmin_client.call( |         self.oneadmin_client.call( | ||||||
|             oca.VmTemplate.METHODS['update'], |             oca.VirtualMachine.METHODS['update'], | ||||||
|             vm_id,  |             vm_id,  | ||||||
|             extra_template_formater.format( |             extra_template, | ||||||
|                 ssh_key=ssh_key, |  | ||||||
|                 image_id=image_id |  | ||||||
|                 ), |  | ||||||
|             # 0 = Replace / 1 = Merge |             # 0 = Replace / 1 = Merge | ||||||
|             1, |             1, | ||||||
|         ) |         ) | ||||||
|  | @ -282,7 +270,8 @@ class OpenNebulaManager(): | ||||||
|             public_images = [ |             public_images = [ | ||||||
|                     image |                     image | ||||||
|                     for image in self._get_image_pool() |                     for image in self._get_image_pool() | ||||||
|                     if 'public-' in image.name  |                     #XXX: Change this | ||||||
|  |                     if 'READY' in image.str_state | ||||||
|                     ] |                     ] | ||||||
|             return public_images |             return public_images | ||||||
|         except ConnectionRefusedError: |         except ConnectionRefusedError: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue