update fetchvmtemplates command
This commit is contained in:
		
					parent
					
						
							
								a4ca17e2ed
							
						
					
				
			
			
				commit
				
					
						2d1805f11d
					
				
			
		
					 1 changed files with 18 additions and 6 deletions
				
			
		| 
						 | 
					@ -10,16 +10,28 @@ class Command(BaseCommand):
 | 
				
			||||||
    help = '''Fetches the VM templates from OpenNebula and populates the dcl
 | 
					    help = '''Fetches the VM templates from OpenNebula and populates the dcl
 | 
				
			||||||
            VMTemplate model'''
 | 
					            VMTemplate model'''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_templates(self, manager, prefix):
 | 
				
			||||||
 | 
					        templates = manager.get_templates('%s-' % prefix)
 | 
				
			||||||
 | 
					        dcl_vm_templates = []
 | 
				
			||||||
 | 
					        for template in templates:
 | 
				
			||||||
 | 
					            template_name = template.name.lstrip('%s-' % prefix)
 | 
				
			||||||
 | 
					            template_id = template.id
 | 
				
			||||||
 | 
					            dcl_vm_template = VMTemplate.create(
 | 
				
			||||||
 | 
					                template_name, template_id, prefix
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            dcl_vm_templates.append(dcl_vm_template)
 | 
				
			||||||
 | 
					        return dcl_vm_templates
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def handle(self, *args, **options):
 | 
					    def handle(self, *args, **options):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            manager = OpenNebulaManager()
 | 
					            manager = OpenNebulaManager()
 | 
				
			||||||
            templates = manager.get_templates()
 | 
					 | 
				
			||||||
            dcl_vm_templates = []
 | 
					            dcl_vm_templates = []
 | 
				
			||||||
            for template in templates:
 | 
					            dcl_vm_templates.extend(
 | 
				
			||||||
                template_name = template.name.lstrip('public-')
 | 
					                self.get_templates(manager, VMTemplate.PUBLIC)
 | 
				
			||||||
                template_id = template.id
 | 
					            )
 | 
				
			||||||
                dcl_vm_template = VMTemplate.create(template_name, template_id)
 | 
					            dcl_vm_templates.extend(
 | 
				
			||||||
                dcl_vm_templates.append(dcl_vm_template)
 | 
					                self.get_templates(manager, VMTemplate.IPV6)
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            old_vm_templates = VMTemplate.objects.all()
 | 
					            old_vm_templates = VMTemplate.objects.all()
 | 
				
			||||||
            old_vm_templates.delete()
 | 
					            old_vm_templates.delete()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue