From 6baf989547eb04202fd8469586d869502222812a Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 16 Mar 2018 09:32:00 +0100 Subject: [PATCH 1/4] Replace strip with lstrip --- datacenterlight/management/commands/fetchvmtemplates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/management/commands/fetchvmtemplates.py b/datacenterlight/management/commands/fetchvmtemplates.py index 15b76fc1..16970705 100644 --- a/datacenterlight/management/commands/fetchvmtemplates.py +++ b/datacenterlight/management/commands/fetchvmtemplates.py @@ -15,7 +15,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) From c0c79ebf2b21c09352fe1ecd9ebcc8e4365410ae Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 16 Mar 2018 09:32:13 +0100 Subject: [PATCH 2/4] Format code --- datacenterlight/management/commands/fetchvmtemplates.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datacenterlight/management/commands/fetchvmtemplates.py b/datacenterlight/management/commands/fetchvmtemplates.py index 16970705..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: @@ -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))) From f866368e859744e49f33edf7210677922b6c2259 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 16 Mar 2018 09:35:13 +0100 Subject: [PATCH 3/4] Replace other occurrences of strip('public-') with lstrip('public-') --- opennebula_api/serializers.py | 6 +++--- opennebula_api/tests.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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..da904576 100644 --- a/opennebula_api/tests.py +++ b/opennebula_api/tests.py @@ -145,5 +145,5 @@ 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 From 26424fe24ec59748aa2ed77d65d84595b928da9f Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 16 Mar 2018 09:38:35 +0100 Subject: [PATCH 4/4] Reformat code --- opennebula_api/tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opennebula_api/tests.py b/opennebula_api/tests.py index da904576..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.lstrip('public-')) + self.assertEqual( + serialized.data.get('name'), vm.name.lstrip('public-') + ) break