Merge pull request #587 from pcoder/bug/4262/fix_template_name
Bug/4262/fix template name
This commit is contained in:
		
				commit
				
					
						fdf93428f6
					
				
			
		
					 3 changed files with 11 additions and 7 deletions
				
			
		|  | @ -7,7 +7,8 @@ logger = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Command(BaseCommand): | class Command(BaseCommand): | ||||||
|     help = 'Fetches the VM templates from OpenNebula and populates the dcl VMTemplate model' |     help = '''Fetches the VM templates from OpenNebula and populates the dcl | ||||||
|  |             VMTemplate model''' | ||||||
| 
 | 
 | ||||||
|     def handle(self, *args, **options): |     def handle(self, *args, **options): | ||||||
|         try: |         try: | ||||||
|  | @ -15,7 +16,7 @@ class Command(BaseCommand): | ||||||
|             templates = manager.get_templates() |             templates = manager.get_templates() | ||||||
|             dcl_vm_templates = [] |             dcl_vm_templates = [] | ||||||
|             for template in templates: |             for template in templates: | ||||||
|                 template_name = template.name.strip('public-') |                 template_name = template.name.lstrip('public-') | ||||||
|                 template_id = template.id |                 template_id = template.id | ||||||
|                 dcl_vm_template = VMTemplate.create(template_name, template_id) |                 dcl_vm_template = VMTemplate.create(template_name, template_id) | ||||||
|                 dcl_vm_templates.append(dcl_vm_template) |                 dcl_vm_templates.append(dcl_vm_template) | ||||||
|  | @ -26,4 +27,5 @@ class Command(BaseCommand): | ||||||
|             for dcl_vm_template in dcl_vm_templates: |             for dcl_vm_template in dcl_vm_templates: | ||||||
|                 dcl_vm_template.save() |                 dcl_vm_template.save() | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             logger.error('Error connecting to OpenNebula. Error Details: {err}'.format(err=str(e))) |             logger.error('Error connecting to OpenNebula. Error Details: ' | ||||||
|  |                          '{err}'.format(err=str(e))) | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): | ||||||
|         return int(obj.template.memory) / 1024 |         return int(obj.template.memory) / 1024 | ||||||
| 
 | 
 | ||||||
|     def get_name(self, obj): |     def get_name(self, obj): | ||||||
|         return obj.name.strip('public-') |         return obj.name.lstrip('public-') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class VirtualMachineSerializer(serializers.Serializer): | class VirtualMachineSerializer(serializers.Serializer): | ||||||
|  | @ -133,7 +133,7 @@ class VirtualMachineSerializer(serializers.Serializer): | ||||||
|     def get_configuration(self, obj): |     def get_configuration(self, obj): | ||||||
|         template_id = obj.template.template_id |         template_id = obj.template.template_id | ||||||
|         template = OpenNebulaManager().get_template(template_id) |         template = OpenNebulaManager().get_template(template_id) | ||||||
|         return template.name.strip('public-') |         return template.name.lstrip('public-') | ||||||
| 
 | 
 | ||||||
|     def get_ipv4(self, obj): |     def get_ipv4(self, obj): | ||||||
|         """ |         """ | ||||||
|  | @ -162,7 +162,7 @@ class VirtualMachineSerializer(serializers.Serializer): | ||||||
|             return '-' |             return '-' | ||||||
| 
 | 
 | ||||||
|     def get_name(self, obj): |     def get_name(self, obj): | ||||||
|         return obj.name.strip('public-') |         return obj.name.lstrip('public-') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class VMTemplateSerializer(serializers.Serializer): | class VMTemplateSerializer(serializers.Serializer): | ||||||
|  |  | ||||||
|  | @ -145,5 +145,7 @@ class VirtualMachineSerializerTestCase(TestCase): | ||||||
| 
 | 
 | ||||||
|         for vm in self.manager.get_vms(): |         for vm in self.manager.get_vms(): | ||||||
|             serialized = VirtualMachineSerializer(vm) |             serialized = VirtualMachineSerializer(vm) | ||||||
|             self.assertEqual(serialized.data.get('name'), vm.name.strip('public-')) |             self.assertEqual( | ||||||
|  |                 serialized.data.get('name'), vm.name.lstrip('public-') | ||||||
|  |             ) | ||||||
|             break |             break | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue