Feature 7432 Merge branch 'Azure'
[osm/RO.git] / osm_ro / vimconn_azure.py
index db9a72a..ad96da1 100755 (executable)
@@ -1,8 +1,19 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
-import base64
-
-
+##
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+##
 
 
+import base64
 import vimconn
 import logging
 import netaddr
 import vimconn
 import logging
 import netaddr
@@ -18,8 +29,8 @@ from msrestazure.azure_exceptions import CloudError
 from msrest.exceptions import AuthenticationError
 from requests.exceptions import ConnectionError
 
 from msrest.exceptions import AuthenticationError
 from requests.exceptions import ConnectionError
 
-__author__ = 'Sergio Gonzalez'
-__date__  = '$18-apr-2019 23:59:59$'
+__author__ = 'Isabel Lloret, Sergio Gonzalez, Alfonso Tierno'
+__date__ = '$18-apr-2019 23:59:59$'
 
 
 if getenv('OSMRO_PDB_DEBUG'):
 
 
 if getenv('OSMRO_PDB_DEBUG'):
@@ -87,15 +98,16 @@ class vimconnector(vimconn.vimconnector):
         self.tenant = (tenant_id or tenant_name)
 
         # Store config to create azure subscription later
         self.tenant = (tenant_id or tenant_name)
 
         # Store config to create azure subscription later
-        self._config = {}
-        self._config["user"] = user
-        self._config["passwd"] = passwd
-        self._config["tenant"] = (tenant_id or tenant_name)
+        self._config = {
+            "user": user,
+            "passwd": passwd,
+            "tenant": tenant_id or tenant_name
+        }
 
         # SUBSCRIPTION
         if 'subscription_id' in config:
             self._config["subscription_id"] = config.get('subscription_id')
 
         # SUBSCRIPTION
         if 'subscription_id' in config:
             self._config["subscription_id"] = config.get('subscription_id')
-            #self.logger.debug('Setting subscription to: %s', self.config["subscription_id"])
+            # self.logger.debug('Setting subscription to: %s', self.config["subscription_id"])
         else:
             raise vimconn.vimconnException('Subscription not specified')
 
         else:
             raise vimconn.vimconnException('Subscription not specified')
 
@@ -153,7 +165,8 @@ class vimconnector(vimconn.vimconnector):
             resource = str(resource_id.split('/')[-1])
             return resource
         except Exception as e:
             resource = str(resource_id.split('/')[-1])
             return resource
         except Exception as e:
-            raise vimconn.vimconnException("Unable to get resource name from invalid resource_id format: '{}'".format(resource_id))
+            raise vimconn.vimconnException("Unable to get resource name from resource_id '{}' Error: '{}'".
+                                           format(resource_id, e))
 
     def _get_location_from_resource_group(self, resource_group_name):
         try:
 
     def _get_location_from_resource_group(self, resource_group_name):
         try:
@@ -304,7 +317,7 @@ class vimconnector(vimconn.vimconnector):
             ip_profile = {"subnet_address": ip_profile['subnet_address']}
 
         try:
             ip_profile = {"subnet_address": ip_profile['subnet_address']}
 
         try:
-            #subnet_name = "{}-{}".format(net_name[:24], uuid4())
+            # subnet_name = "{}-{}".format(net_name[:24], uuid4())
             subnet_params = {
                 'address_prefix': ip_profile['subnet_address']
             }
             subnet_params = {
                 'address_prefix': ip_profile['subnet_address']
             }
@@ -333,8 +346,8 @@ class vimconnector(vimconn.vimconnector):
 
         # get the name with the first not used suffix
         name_suffix = 0
 
         # get the name with the first not used suffix
         name_suffix = 0
-        #name = subnet_name + "-" + str(name_suffix)
-        name = subnet_name # first subnet created will have no prefix
+        # name = subnet_name + "-" + str(name_suffix)
+        name = subnet_name  # first subnet created will have no prefix
         while name in net_names:
             name_suffix += 1
             name = subnet_name + "-" + str(name_suffix)
         while name in net_names:
             name_suffix += 1
             name = subnet_name + "-" + str(name_suffix)
@@ -348,7 +361,7 @@ class vimconnector(vimconn.vimconnector):
         subnet_id = net['net_id']
         location = self._get_location_from_resource_group(self.resource_group)
         try:
         subnet_id = net['net_id']
         location = self._get_location_from_resource_group(self.resource_group)
         try:
-            net_ifz = {'location':location}
+            net_ifz = {'location': location}
             net_ip_config = {'name': nic_name + '-ipconfiguration', 'subnet': {'id': subnet_id}}
             if static_ip:
                 net_ip_config['privateIPAddress'] = static_ip
             net_ip_config = {'name': nic_name + '-ipconfiguration', 'subnet': {'id': subnet_id}}
             if static_ip:
                 net_ip_config['privateIPAddress'] = static_ip
@@ -358,11 +371,8 @@ class vimconnector(vimconn.vimconnector):
             if mac_address:
                 net_ifz['mac_address'] = mac_address
 
             if mac_address:
                 net_ifz['mac_address'] = mac_address
 
-            async_nic_creation = self.conn_vnet.network_interfaces.create_or_update(
-                    self.resource_group,
-                    nic_name,
-                    net_ifz
-                )
+            async_nic_creation = self.conn_vnet.network_interfaces.create_or_update(self.resource_group, nic_name,
+                                                                                    net_ifz)
             async_nic_creation.wait()
             self.logger.debug('created nic name %s', nic_name)
 
             async_nic_creation.wait()
             self.logger.debug('created nic name %s', nic_name)
 
@@ -380,7 +390,7 @@ class vimconnector(vimconn.vimconnector):
                 )
                 self.logger.debug('created public IP: {}'.format(public_ip.result()))
 
                 )
                 self.logger.debug('created public IP: {}'.format(public_ip.result()))
 
-                # Asociate NIC to Public IP
+                # Associate NIC to Public IP
                 nic_data = self.conn_vnet.network_interfaces.get(
                     self.resource_group,
                     nic_name)
                 nic_data = self.conn_vnet.network_interfaces.get(
                     self.resource_group,
                     nic_name)
@@ -480,7 +490,7 @@ class vimconnector(vimconn.vimconnector):
                 return [offer.name for offer in result_offers]
             except CloudError as e:
                 # azure raises CloudError when not found
                 return [offer.name for offer in result_offers]
             except CloudError as e:
                 # azure raises CloudError when not found
-                self.logger.info("error listing offers for publisher {}, message: {}".format(publisher, e.message))
+                self.logger.info("error listing offers for publisher {}, Error: {}".format(publisher, e))
                 return []
 
     def _get_sku_list(self, params, publisher, offer):
                 return []
 
     def _get_sku_list(self, params, publisher, offer):
@@ -496,7 +506,7 @@ class vimconnector(vimconn.vimconnector):
                 return [sku.name for sku in result_skus]
             except CloudError as e:
                 # azure raises CloudError when not found
                 return [sku.name for sku in result_skus]
             except CloudError as e:
                 # azure raises CloudError when not found
-                self.logger.info("error listing skus for publisher {}, offer {}, message: {}".format(publisher, offer, e.message))
+                self.logger.info("error listing skus for publisher {}, offer {}, Error: {}".format(publisher, offer, e))
                 return []
 
     def _get_sku_image_list(self, publisher, offer, sku):
                 return []
 
     def _get_sku_image_list(self, publisher, offer, sku):
@@ -513,7 +523,7 @@ class vimconnector(vimconn.vimconnector):
                 })
         except CloudError as e:
             self.logger.info(
                 })
         except CloudError as e:
             self.logger.info(
-                "error listing skus for publisher {}, offer {}, message: {}".format(publisher, offer, e.message))
+                "error listing skus for publisher {}, offer {}, Error: {}".format(publisher, offer, e))
             image_list = []
         return image_list
 
             image_list = []
         return image_list
 
@@ -528,12 +538,8 @@ class vimconnector(vimconn.vimconnector):
                 })
         except CloudError as e:
             # azure gives CloudError when not found
                 })
         except CloudError as e:
             # azure gives CloudError when not found
-            self.logger.info(
-                "error listing images for publisher {}, offer {}, sku {}, vesion {} message: {}".format(publisher,
-                                                                                                        offer,
-                                                                                                        sku,
-                                                                                                        version,
-                                                                                                        e.message))
+            self.logger.info("error listing images for publisher {}, offer {}, sku {}, version {} Error: {}".
+                             format(publisher, offer, sku, version, e))
             image_list = []
         return image_list
 
             image_list = []
         return image_list
 
@@ -548,7 +554,7 @@ class vimconnector(vimconn.vimconnector):
             status: 'ACTIVE', not implemented in Azure #
         Returns the network list of dictionaries
         """
             status: 'ACTIVE', not implemented in Azure #
         Returns the network list of dictionaries
         """
-        #self.logger.debug('getting network list for vim, filter %s', filter_dict)
+        # self.logger.debug('getting network list for vim, filter %s', filter_dict)
         try:
             self._reload_connection()
 
         try:
             self._reload_connection()
 
@@ -567,28 +573,22 @@ class vimconnector(vimconn.vimconnector):
 
                 subnet_list.append({
                     'id': str(subnet.id),
 
                 subnet_list.append({
                     'id': str(subnet.id),
-                    'name': self._get_resource_name_from_resource_id(subnet.id),
+                    'name': name,
                     'status': self.provision_state2osm[subnet.provisioning_state],
                     'cidr_block': str(subnet.address_prefix),
                     'type': 'bridge',
                     'shared': False
                     'status': self.provision_state2osm[subnet.provisioning_state],
                     'cidr_block': str(subnet.address_prefix),
                     'type': 'bridge',
                     'shared': False
-                    }
-                )
+                })
 
             return subnet_list
         except Exception as e:
             self._format_vimconn_exception(e)
 
 
             return subnet_list
         except Exception as e:
             self._format_vimconn_exception(e)
 
-    def new_vminstance(self, vm_name, description, start, image_id, flavor_id, net_list, cloud_config=None,
-                       disk_list=None, availability_zone_index=None, availability_zone_list=None):
-
-        return self._new_vminstance(vm_name, image_id, flavor_id, net_list)
-
     def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None,
     def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None,
-                        disk_list=None, availability_zone_index=None, availability_zone_list=None):
+                       disk_list=None, availability_zone_index=None, availability_zone_list=None):
 
 
-        self.logger.debug("new vm instance name: %s, image_id: %s, flavor_id: %s, net_list: %s, cloud_config: %s"
-                          "disk_list: %s, availability_zone_index: %s, availability_zone_list: %s",
+        self.logger.debug("new vm instance name: %s, image_id: %s, flavor_id: %s, net_list: %s, cloud_config: %s"
+                          "disk_list: %s, availability_zone_index: %s, availability_zone_list: %s",
                           name, image_id, flavor_id, net_list, cloud_config, disk_list,
                           availability_zone_index, availability_zone_list)
 
                           name, image_id, flavor_id, net_list, cloud_config, disk_list,
                           availability_zone_index, availability_zone_list)
 
@@ -634,7 +634,7 @@ class vimconnector(vimconn.vimconnector):
                 if cloud_config.get("users"):
                     user_name = cloud_config.get("users")[0].get("name", "osm")
                 else:
                 if cloud_config.get("users"):
                     user_name = cloud_config.get("users")[0].get("name", "osm")
                 else:
-                    user_name = "osm" # DEFAULT USER IS OSM
+                    user_name = "osm"  # DEFAULT USER IS OSM
 
                 os_profile = {
                     'computer_name': vm_name,
 
                 os_profile = {
                     'computer_name': vm_name,
@@ -652,9 +652,9 @@ class vimconnector(vimconn.vimconnector):
                 }
             else:
                 os_profile = {
                 }
             else:
                 os_profile = {
-                    'computer_name': vm_name
-                    ,'admin_username': 'osm'
-                    ,'admin_password': 'Osm4u!',
+                    'computer_name': vm_name,
+                    'admin_username': 'osm',
+                    'admin_password': 'Osm4u!',
                 }
 
             vm_parameters = {
                 }
 
             vm_parameters = {
@@ -681,7 +681,7 @@ class vimconnector(vimconn.vimconnector):
                             'disk_size_gb': disk.get("size")
                         })
                     else:
                             'disk_size_gb': disk.get("size")
                         })
                     else:
-                        #self.logger.debug("currently not able to create data disks from image for azure, ignoring")
+                        # self.logger.debug("currently not able to create data disks from image for azure, ignoring")
                         data_disks.append({
                             'lun': lun_name,  # You choose the value, depending of what is available for you
                             'name': vm_name + "_data_disk-" + str(lun_name),
                         data_disks.append({
                             'lun': lun_name,  # You choose the value, depending of what is available for you
                             'name': vm_name + "_data_disk-" + str(lun_name),
@@ -712,24 +712,24 @@ class vimconnector(vimconn.vimconnector):
                 vm_name,
                 vm_parameters
             )
                 vm_name,
                 vm_parameters
             )
-            #creation_result.wait()
+            # creation_result.wait()
             result = creation_result.result()
             self.logger.debug("created vm name: %s", vm_name)
 
             if start:
             result = creation_result.result()
             self.logger.debug("created vm name: %s", vm_name)
 
             if start:
-                start_result = self.conn_compute.virtual_machines.start(
+                self.conn_compute.virtual_machines.start(
                     self.resource_group,
                     vm_name)
                     self.resource_group,
                     vm_name)
-            #start_result.wait()
+            # start_result.wait()
 
             return result.id, None
             
 
             return result.id, None
             
-            #run_command_parameters = {
-            #    'command_id': 'RunShellScript', # For linux, don't change it
-            #    'script': [
-            #    'date > /tmp/test.txt'
-            #    ]
-            #}
+            # run_command_parameters = {
+            #     'command_id': 'RunShellScript', # For linux, don't change it
+            #     'script': [
+            #     'date > /tmp/test.txt'
+            #     ]
+            # }
         except Exception as e:
             self.logger.debug('Exception creating new vminstance: %s', e, exc_info=True)
             self._format_vimconn_exception(e)
         except Exception as e:
             self.logger.debug('Exception creating new vminstance: %s', e, exc_info=True)
             self._format_vimconn_exception(e)
@@ -753,7 +753,6 @@ class vimconnector(vimconn.vimconnector):
             name = vm_name + "-" + str(name_suffix)
         return name
 
             name = vm_name + "-" + str(name_suffix)
         return name
 
-
     # It is necesary extract from image_id data to create the VM with this format
     #        'image_reference': {
     #           'publisher': vm_reference['publisher'],
     # It is necesary extract from image_id data to create the VM with this format
     #        'image_reference': {
     #           'publisher': vm_reference['publisher'],
@@ -776,10 +775,10 @@ class vimconnector(vimconn.vimconnector):
             version = str(image_id.split('/')[16])
 
             return {
             version = str(image_id.split('/')[16])
 
             return {
-                     'publisher': publisher,
-                     'offer': offer,
-                     'sku': sku,
-                     'version': version
+                'publisher': publisher,
+                'offer': offer,
+                'sku': sku,
+                'version': version
             }
         except Exception as e:
             raise vimconn.vimconnException(
             }
         except Exception as e:
             raise vimconn.vimconnException(
@@ -791,7 +790,6 @@ class vimconnector(vimconn.vimconnector):
         Checks vm name, in case the vm has not allowed characters they are removed, not error raised
         """
 
         Checks vm name, in case the vm has not allowed characters they are removed, not error raised
         """
 
-        #chars_not_allowed_list = ['~','!','@','#','$','%','^','&','*','(',')','=','+','_','[',']','{','}','|',';',':','<','>','/','?','.']
         chars_not_allowed_list = "~!@#$%^&*()=+_[]{}|;:<>/?."
 
         # First: the VM name max length is 64 characters
         chars_not_allowed_list = "~!@#$%^&*()=+_[]{}|;:<>/?."
 
         # First: the VM name max length is 64 characters
@@ -801,7 +799,7 @@ class vimconnector(vimconn.vimconnector):
         for elem in chars_not_allowed_list:
             # Check if string is in the main string
             if elem in vm_name_aux:
         for elem in chars_not_allowed_list:
             # Check if string is in the main string
             if elem in vm_name_aux:
-                #self.logger.debug('Dentro del IF')
+                # self.logger.debug('Dentro del IF')
                 # Replace the string
                 vm_name_aux = vm_name_aux.replace(elem, '-')
 
                 # Replace the string
                 vm_name_aux = vm_name_aux.replace(elem, '-')
 
@@ -813,24 +811,24 @@ class vimconnector(vimconn.vimconnector):
         filter_dict = flavor_dict or {}
         try:
             self._reload_connection()
         filter_dict = flavor_dict or {}
         try:
             self._reload_connection()
-            vm_sizes_list = [vm_size.serialize() for vm_size in self.conn_compute.virtual_machine_sizes.list(self.region)]
+            vm_sizes_list = [vm_size.serialize() for vm_size in
+                             self.conn_compute.virtual_machine_sizes.list(self.region)]
 
             cpus = filter_dict.get('vcpus') or 0
             memMB = filter_dict.get('ram') or 0
 
             # Filter
             if self._config.get("flavors_pattern"):
 
             cpus = filter_dict.get('vcpus') or 0
             memMB = filter_dict.get('ram') or 0
 
             # Filter
             if self._config.get("flavors_pattern"):
-                filtered_sizes = [size for size in vm_sizes_list if size['numberOfCores'] >= cpus
-                                  and size['memoryInMB'] >= memMB
-                                  and re.search(self._config.get("flavors_pattern"), size["name"])]
+                filtered_sizes = [size for size in vm_sizes_list if size['numberOfCores'] >= cpus and
+                                  size['memoryInMB'] >= memMB and
+                                  re.search(self._config.get("flavors_pattern"), size["name"])]
             else:
             else:
-                filtered_sizes = [size for size in vm_sizes_list if size['numberOfCores'] >= cpus
-                                  and size['memoryInMB'] >= memMB]
-
-
+                filtered_sizes = [size for size in vm_sizes_list if size['numberOfCores'] >= cpus and
+                                  size['memoryInMB'] >= memMB]
 
             # Sort
 
             # Sort
-            listedFilteredSizes = sorted(filtered_sizes, key=lambda k: (k['numberOfCores'], k['memoryInMB'], k['resourceDiskSizeInMB']))
+            listedFilteredSizes = sorted(filtered_sizes, key=lambda k: (k['numberOfCores'], k['memoryInMB'],
+                                                                        k['resourceDiskSizeInMB']))
 
             if listedFilteredSizes:
                 return listedFilteredSizes[0]['name']
 
             if listedFilteredSizes:
                 return listedFilteredSizes[0]['name']
@@ -841,17 +839,18 @@ class vimconnector(vimconn.vimconnector):
 
     def _get_flavor_id_from_flavor_name(self, flavor_name):
 
 
     def _get_flavor_id_from_flavor_name(self, flavor_name):
 
-        #self.logger.debug("getting flavor id from flavor name {}".format(flavor_name))
+        # self.logger.debug("getting flavor id from flavor name {}".format(flavor_name))
         try:
             self._reload_connection()
         try:
             self._reload_connection()
-            vm_sizes_list = [vm_size.serialize() for vm_size in self.conn_compute.virtual_machine_sizes.list(self.region)]
+            vm_sizes_list = [vm_size.serialize() for vm_size in
+                             self.conn_compute.virtual_machine_sizes.list(self.region)]
 
             output_flavor = None
             for size in vm_sizes_list:
                 if size['name'] == flavor_name:
                     output_flavor = size
 
 
             output_flavor = None
             for size in vm_sizes_list:
                 if size['name'] == flavor_name:
                     output_flavor = size
 
-            # Si no se encuentra ninguno, este metodo devuelve None
+            # None is returned if not found anything
             return output_flavor
 
         except Exception as e:
             return output_flavor
 
         except Exception as e:
@@ -866,8 +865,8 @@ class vimconnector(vimconn.vimconnector):
 
     def get_network(self, net_id):
 
 
     def get_network(self, net_id):
 
-        #self.logger.debug('get network id: {}'.format(net_id))
-        res_name = self._get_resource_name_from_resource_id(net_id)
+        # self.logger.debug('get network id: {}'.format(net_id))
+        res_name = self._get_resource_name_from_resource_id(net_id)
         self._reload_connection()
 
         filter_dict = {'name': net_id}
         self._reload_connection()
 
         filter_dict = {'name': net_id}
@@ -916,8 +915,8 @@ class vimconnector(vimconn.vimconnector):
             vm = self.conn_compute.virtual_machines.get(self.resource_group, res_name)
 
             # Shuts down the virtual machine and releases the compute resources
             vm = self.conn_compute.virtual_machines.get(self.resource_group, res_name)
 
             # Shuts down the virtual machine and releases the compute resources
-            #vm_stop = self.conn_compute.virtual_machines.power_off(self.resource_group, resName)
-            #vm_stop.wait()
+            # vm_stop = self.conn_compute.virtual_machines.power_off(self.resource_group, resName)
+            # vm_stop.wait()
 
             vm_delete = self.conn_compute.virtual_machines.delete(self.resource_group, res_name)
             vm_delete.wait()
 
             vm_delete = self.conn_compute.virtual_machines.delete(self.resource_group, res_name)
             vm_delete.wait()
@@ -963,7 +962,7 @@ class vimconnector(vimconn.vimconnector):
                 # Delete list of public ips
                 if public_ip_name:
                     self.logger.debug('delete PUBLIC IP - ' + public_ip_name)
                 # Delete list of public ips
                 if public_ip_name:
                     self.logger.debug('delete PUBLIC IP - ' + public_ip_name)
-                    public_ip = self.conn_vnet.public_ip_addresses.delete(self.resource_group, public_ip_name)
+                    self.conn_vnet.public_ip_addresses.delete(self.resource_group, public_ip_name)
 
         except CloudError as e:
             if e.error.error and "notfound" in e.error.error.lower():
 
         except CloudError as e:
             if e.error.error and "notfound" in e.error.error.lower():
@@ -973,7 +972,7 @@ class vimconnector(vimconn.vimconnector):
         except Exception as e:
             self._format_vimconn_exception(e)
 
         except Exception as e:
             self._format_vimconn_exception(e)
 
-    def action_vminstance(self, vm_id, action_dict, created_items = {}):
+    def action_vminstance(self, vm_id, action_dict, created_items={}):
         """Send and action over a VM instance from VIM
         Returns the vm_id if the action was successfully sent to the VIM
         """
         """Send and action over a VM instance from VIM
         Returns the vm_id if the action was successfully sent to the VIM
         """
@@ -1016,7 +1015,7 @@ class vimconnector(vimconn.vimconnector):
         self._reload_connection()
         try:
             resName = self._get_resource_name_from_resource_id(vm_id)
         self._reload_connection()
         try:
             resName = self._get_resource_name_from_resource_id(vm_id)
-            vm=self.conn_compute.virtual_machines.get(self.resource_group, resName)
+            vm = self.conn_compute.virtual_machines.get(self.resource_group, resName)
         except CloudError as e:
             if e.error.error and "notfound" in e.error.error.lower():
                 raise vimconn.vimconnNotFoundException("No vminstance found '{}'".format(vm_id))
         except CloudError as e:
             if e.error.error and "notfound" in e.error.error.lower():
                 raise vimconn.vimconnNotFoundException("No vminstance found '{}'".format(vm_id))
@@ -1051,8 +1050,8 @@ class vimconnector(vimconn.vimconnector):
             For the azure connector only the azure tenant will be returned if it is compatible
             with filter_dict
         """
             For the azure connector only the azure tenant will be returned if it is compatible
             with filter_dict
         """
-        tenants_azure=[{'name': self.tenant, 'id': self.tenant}]
-        tenant_list=[]
+        tenants_azure = [{'name': self.tenant, 'id': self.tenant}]
+        tenant_list = []
 
         self.logger.debug("get tenant list: %s", filter_dict)
         for tenant_azure in tenants_azure:
 
         self.logger.debug("get tenant list: %s", filter_dict)
         for tenant_azure in tenants_azure:
@@ -1217,7 +1216,8 @@ class vimconnector(vimconn.vimconnector):
                 ips = []
                 if nic_data.ip_configurations[0].public_ip_address:
                     self.logger.debug("Obtain public ip address")
                 ips = []
                 if nic_data.ip_configurations[0].public_ip_address:
                     self.logger.debug("Obtain public ip address")
-                    public_ip_name = self._get_resource_name_from_resource_id(nic_data.ip_configurations[0].public_ip_address.id)
+                    public_ip_name = self._get_resource_name_from_resource_id(
+                        nic_data.ip_configurations[0].public_ip_address.id)
                     public_ip = self.conn_vnet.public_ip_addresses.get(self.resource_group, public_ip_name)
                     self.logger.debug("Public ip address is: %s", public_ip.ip_address)
                     ips.append(public_ip.ip_address)
                     public_ip = self.conn_vnet.public_ip_addresses.get(self.resource_group, public_ip_name)
                     self.logger.debug("Public ip address is: %s", public_ip.ip_address)
                     ips.append(public_ip.ip_address)
@@ -1257,11 +1257,11 @@ if __name__ == "__main__":
         test_params[param] = value
 
     config = {
         test_params[param] = value
 
     config = {
-            'region_name': getenv("AZURE_REGION_NAME", 'westeurope'),
-            'resource_group': getenv("AZURE_RESOURCE_GROUP"),
-            'subscription_id': getenv("AZURE_SUBSCRIPTION_ID"),
-            'pub_key': getenv("AZURE_PUB_KEY", None),
-            'vnet_name': getenv("AZURE_VNET_NAME", 'myNetwork'),
+        'region_name': getenv("AZURE_REGION_NAME", 'westeurope'),
+        'resource_group': getenv("AZURE_RESOURCE_GROUP"),
+        'subscription_id': getenv("AZURE_SUBSCRIPTION_ID"),
+        'pub_key': getenv("AZURE_PUB_KEY", None),
+        'vnet_name': getenv("AZURE_VNET_NAME", 'myNetwork'),
     }
 
     virtualMachine = {
     }
 
     virtualMachine = {
@@ -1284,7 +1284,7 @@ if __name__ == "__main__":
 
     vnet_config = {
         'subnet_address': '10.1.2.0/24',
 
     vnet_config = {
         'subnet_address': '10.1.2.0/24',
-        #'subnet_name': 'subnet-oam'
+        # 'subnet_name': 'subnet-oam'
     }
     ###########################
 
     }
     ###########################