diff --git a/datacenterlight/management/commands/fetchvmtemplates.py b/datacenterlight/management/commands/fetchvmtemplates.py index 15b76fc1..6a45ebad 100644 --- a/datacenterlight/management/commands/fetchvmtemplates.py +++ b/datacenterlight/management/commands/fetchvmtemplates.py @@ -7,7 +7,8 @@ logger = logging.getLogger(__name__) 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): try: @@ -15,7 +16,7 @@ class Command(BaseCommand): templates = manager.get_templates() dcl_vm_templates = [] for template in templates: - template_name = template.name.strip('public-') + template_name = template.name.lstrip('public-') template_id = template.id dcl_vm_template = VMTemplate.create(template_name, template_id) dcl_vm_templates.append(dcl_vm_template) @@ -26,4 +27,5 @@ class Command(BaseCommand): for dcl_vm_template in dcl_vm_templates: dcl_vm_template.save() 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))) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index cc52a15e..79f37ecd 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -36,7 +36,7 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): return int(obj.template.memory) / 1024 def get_name(self, obj): - return obj.name.strip('public-') + return obj.name.lstrip('public-') class VirtualMachineSerializer(serializers.Serializer): @@ -133,7 +133,7 @@ class VirtualMachineSerializer(serializers.Serializer): def get_configuration(self, obj): template_id = obj.template.template_id template = OpenNebulaManager().get_template(template_id) - return template.name.strip('public-') + return template.name.lstrip('public-') def get_ipv4(self, obj): """ @@ -162,7 +162,7 @@ class VirtualMachineSerializer(serializers.Serializer): return '-' def get_name(self, obj): - return obj.name.strip('public-') + return obj.name.lstrip('public-') class VMTemplateSerializer(serializers.Serializer): diff --git a/opennebula_api/tests.py b/opennebula_api/tests.py index 234e0c16..b8c5280f 100644 --- a/opennebula_api/tests.py +++ b/opennebula_api/tests.py @@ -145,5 +145,7 @@ class VirtualMachineSerializerTestCase(TestCase): for vm in self.manager.get_vms(): serialized = VirtualMachineSerializer(vm) - self.assertEqual(serialized.data.get('name'), vm.name.strip('public-')) + self.assertEqual( + serialized.data.get('name'), vm.name.lstrip('public-') + ) break