From 6ce33624109b3151cfc4b3770590d158ee7e46e6 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 14 May 2018 15:50:35 +0200 Subject: [PATCH 1/7] Fix #604 --- IM/connectors/Azure.py | 20 ++++++++++++-------- test/unit/connectors/Azure.py | 5 +++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 6c05e3b46..9877c55a1 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -66,12 +66,12 @@ class AzureCloudConnector(CloudConnector): } POWER_STATE_MAP = { - 'Deallocated': VirtualMachine.OFF, - 'Deallocating': VirtualMachine.OFF, - 'Running': VirtualMachine.RUNNING, - 'Starting': VirtualMachine.PENDING, - 'Started': VirtualMachine.PENDING, - 'Stopped': VirtualMachine.STOPPED + 'PowerState/deallocated': VirtualMachine.OFF, + 'PowerState/deallocating': VirtualMachine.OFF, + 'PowerState/running': VirtualMachine.RUNNING, + 'PowerState/starting': VirtualMachine.PENDING, + 'PowerState/started': VirtualMachine.PENDING, + 'PowerState/stopped': VirtualMachine.STOPPED } def __init__(self, cloud_info, inf): @@ -645,14 +645,18 @@ def updateVMInfo(self, vm, auth_data): credentials, subscription_id = self.get_credentials(auth_data) compute_client = ComputeManagementClient(credentials, subscription_id) # Get one the virtual machine by name - virtual_machine = compute_client.virtual_machines.get(group_name, vm_name) + virtual_machine = compute_client.virtual_machines.get(group_name, vm_name, expand='instanceView') except Exception as ex: self.log_exception("Error getting the VM info: " + vm.id) return (False, "Error getting the VM info: " + vm.id + ". " + str(ex)) self.log_info("VM info: " + vm.id + " obtained.") vm.state = self.PROVISION_STATE_MAP.get(virtual_machine.provisioning_state, VirtualMachine.UNKNOWN) - self.log_info("The VM state is: " + vm.state) + + if vm.state == VirtualMachine.RUNNING: + vm.state = self.POWER_STATE_MAP.get(virtual_machine.instance_view.statuses[1].code, VirtualMachine.UNKNOWN) + + self.log_debug("The VM state is: " + vm.state) instance_type = self.get_instance_type_by_name(virtual_machine.hardware_profile.vm_size, virtual_machine.location, credentials, subscription_id) diff --git a/test/unit/connectors/Azure.py b/test/unit/connectors/Azure.py index 531bc83fe..260136084 100755 --- a/test/unit/connectors/Azure.py +++ b/test/unit/connectors/Azure.py @@ -252,6 +252,11 @@ def test_30_updateVMInfo(self, credentials, dns_client, compute_client, network_ avm.provisioning_state = "Succeeded" avm.hardware_profile.vm_size = "instance_type1" avm.location = "northeurope" + status1 = MagicMock() + status1.code = "ProvisioningState/succeeded" + status2 = MagicMock() + status2.code = "PowerState/running" + avm.instance_view.statuses = [status1, status2] ni = MagicMock() ni.id = "/subscriptions/subscription-id/resourceGroups/rg0/providers/Microsoft.Network/networkInterfaces/ni-0" avm.network_profile.network_interfaces = [ni] From d1e1da1e68c9d0f6696bb993d63799a81aee7ea1 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 14 May 2018 16:42:13 +0200 Subject: [PATCH 2/7] Fix #597 --- IM/VirtualMachine.py | 5 ++++- IM/connectors/OpenStack.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index ca6b6684c..f81625f05 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -668,7 +668,10 @@ def setIps(self, public_ips, private_ips, remove_old=False): # this VM num_net = self.getNumNetworkIfaces() - vm_system.setValue('net_interface.%s.ip' % num_net, str(private_ip)) + if IPAddress(private_ip).version == 6: + vm_system.setValue('net_interface.%s.ipv6' % num_net, str(private_ip)) + else: + vm_system.setValue('net_interface.%s.ip' % num_net, str(private_ip)) vm_system.setValue('net_interface.%s.connection' % num_net, private_net.id) def get_ssh(self, retry=False): diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 9ffc268e5..1480fb21f 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -366,7 +366,10 @@ def setIPsFromInstance(self, vm, node): net_name = system.getValue("net_interface." + str(i) + ".connection") if net_name in map_nets: ip = map_nets[net_name] - system.setValue("net_interface." + str(i) + ".ip", ip) + if IPAddress(ip).version == 6: + system.setValue("net_interface." + str(i) + ".ipv6", ip) + else: + system.setValue("net_interface." + str(i) + ".ip", ip) ips_assigned.append(ip) i += 1 @@ -377,7 +380,10 @@ def setIPsFromInstance(self, vm, node): if net_name != '#UNMAPPED#': if ip not in ips_assigned: num_net = system.getNumNetworkIfaces() - system.setValue('net_interface.' + str(num_net) + '.ip', ip) + if IPAddress(ip).version == 6: + system.setValue('net_interface.' + str(num_net) + '.ipv6', ip) + else: + system.setValue('net_interface.' + str(num_net) + '.ip', ip) system.setValue('net_interface.' + str(num_net) + '.connection', net_name) else: pub_ips = [] From e8cbecc754bf73a20653f990c8ba0c09825cf43f Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 14 May 2018 16:45:40 +0200 Subject: [PATCH 3/7] Fix #604 --- IM/connectors/Azure.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 9877c55a1..32a0afb5f 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -647,13 +647,21 @@ def updateVMInfo(self, vm, auth_data): # Get one the virtual machine by name virtual_machine = compute_client.virtual_machines.get(group_name, vm_name, expand='instanceView') except Exception as ex: + self.log_warn("The VM does not exists.") + # check if the RG still exists + if self.get_rg(group_name, credentials, subscription_id): + self.log_info("But the RG %s does exits. Retun OFF." % group_name) + vm.state = VirtualMachine.OFF + return (True, vm) + self.log_exception("Error getting the VM info: " + vm.id) return (False, "Error getting the VM info: " + vm.id + ". " + str(ex)) self.log_info("VM info: " + vm.id + " obtained.") vm.state = self.PROVISION_STATE_MAP.get(virtual_machine.provisioning_state, VirtualMachine.UNKNOWN) - if vm.state == VirtualMachine.RUNNING: + if (vm.state == VirtualMachine.RUNNING and virtual_machine.instance_view and + len(virtual_machine.instance_view.statuses) > 1): vm.state = self.POWER_STATE_MAP.get(virtual_machine.instance_view.statuses[1].code, VirtualMachine.UNKNOWN) self.log_debug("The VM state is: " + vm.state) From 451c5a0a59624859215ced149efe0234f6c250ed Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 14 May 2018 16:55:03 +0200 Subject: [PATCH 4/7] style change --- test/unit/test_im_logic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_im_logic.py b/test/unit/test_im_logic.py index 386fda59e..6ef02633b 100755 --- a/test/unit/test_im_logic.py +++ b/test/unit/test_im_logic.py @@ -263,7 +263,7 @@ def test_inf_creation_errors(self): with self.assertRaises(Exception) as ex: IM.CreateInfrastructure(radl, auth0) - self.assertEqual(str(ex.exception), "No username nor token for the InfrastructureManager.") + self.assertEqual(str(ex.exception), "No username nor token for the InfrastructureManager.") # this case raises an exception auth0 = Authentication([{'type': 'InfrastructureManager', 'username': 'test', From 99b1bc1a896e9279d71c67d93ffda73b544ac86e Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 14 May 2018 16:55:32 +0200 Subject: [PATCH 5/7] Fix #597 on ONE --- IM/connectors/OpenNebula.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/IM/connectors/OpenNebula.py b/IM/connectors/OpenNebula.py index acdabbbd6..94d203c48 100644 --- a/IM/connectors/OpenNebula.py +++ b/IM/connectors/OpenNebula.py @@ -286,7 +286,11 @@ def setIPsFromTemplate(self, vm, template): net = vm.info.get_network_by_id(net_name) provider_id = net.getValue("provider_id") if provider_id == nic.NETWORK: - system.setValue("net_interface." + str(i) + ".ip", str(nic.IP)) + ip = str(nic.IP) + if IPAddress(ip).version == 6: + system.setValue("net_interface." + str(i) + ".ipv6", ip) + else: + system.setValue("net_interface." + str(i) + ".ip", ip) break i += 1 From 357e4c9b38a98db9d4b755c3ff2477a2d77cc6cf Mon Sep 17 00:00:00 2001 From: micafer Date: Tue, 15 May 2018 08:06:37 +0200 Subject: [PATCH 6/7] Set version 1.7.1 --- IM/__init__.py | 2 +- changelog | 6 +++++- docker-devel/Dockerfile | 2 +- docker-py3/Dockerfile | 7 +++++-- docker/Dockerfile | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/IM/__init__.py b/IM/__init__.py index fae67446d..7ddfe83e0 100644 --- a/IM/__init__.py +++ b/IM/__init__.py @@ -19,5 +19,5 @@ 'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry', 'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter', 'uriparse', 'VirtualMachine', 'VMRC', 'xmlobject'] -__version__ = '1.7.0' +__version__ = '1.7.1' __author__ = 'Miguel Caballer' diff --git a/changelog b/changelog index 2b87349d9..3a0c18cfa 100644 --- a/changelog +++ b/changelog @@ -404,4 +404,8 @@ IM 1.7.0: * Add export and import functions in REST API * Change in the DB schema in the case of MySQL DB. This command must be made in the current DB: - ALTER TABLE `inf_list` ADD COLUMN `rowid` INT AUTO_INCREMENT UNIQUE FIRST; \ No newline at end of file + ALTER TABLE `inf_list` ADD COLUMN `rowid` INT AUTO_INCREMENT UNIQUE FIRST; + +IM 1.7.1: + * Fix problems with nodes with IPv6 in OpenStack conn. + * Fix Azure conn does not get the correct state (in case of suspended VMs). diff --git a/docker-devel/Dockerfile b/docker-devel/Dockerfile index 623e1d3b5..06c21e72c 100644 --- a/docker-devel/Dockerfile +++ b/docker-devel/Dockerfile @@ -2,7 +2,7 @@ FROM grycap/jenkins:ubuntu16.04-im ARG BRANCH=devel MAINTAINER Miguel Caballer -LABEL version="1.7.0" +LABEL version="1.7.1" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 diff --git a/docker-py3/Dockerfile b/docker-py3/Dockerfile index 758576331..7599a6f0c 100644 --- a/docker-py3/Dockerfile +++ b/docker-py3/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile to create a container with the IM service FROM ubuntu:16.04 LABEL maintainer="Miguel Caballer " -LABEL version="1.6.4" +LABEL version="1.7.1" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 @@ -16,11 +16,14 @@ RUN pip3 install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-c # Install IM RUN apt-get update && apt-get install --no-install-recommends -y gcc libssl-dev libffi-dev libsqlite3-dev && \ - pip3 install IM==1.6.4 && \ + pip3 install IM==1.6.1 && \ apt-get remove -y gcc libssl-dev libffi-dev libsqlite3-dev python-dev python-pip && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* +# Force requests to be version 2.11.1 to avoid SSL ca errors with proxy files +RUN pip3 install requests==2.11.1 + # Copy a ansible.cfg with correct minimum values COPY ansible.cfg /etc/ansible/ansible.cfg diff --git a/docker/Dockerfile b/docker/Dockerfile index 16515c4aa..e8c68dd8b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile to create a container with the IM service FROM ubuntu:18.04 LABEL maintainer="Miguel Caballer " -LABEL version="1.7.0" +LABEL version="1.7.1" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 @@ -18,7 +18,7 @@ RUN pip install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-co RUN apt-get update && apt-get install --no-install-recommends -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev libmysqlclient20 && \ pip install pycrypto && \ pip install MySQL-python && \ - pip install IM==1.7.0 && \ + pip install IM==1.7.1 && \ apt-get purge -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev python-dev python-pip && \ apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/ From d30aaaa31b8a637ff0f2c63ae6d896d805f6dde2 Mon Sep 17 00:00:00 2001 From: micafer Date: Tue, 15 May 2018 08:06:54 +0200 Subject: [PATCH 7/7] Minor changes --- IM/connectors/EC2.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index 5059c68e3..2f3e3d09e 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -1009,10 +1009,8 @@ def setIPsFromInstance(self, vm, instance): # It will be used if it is different to the public IP of the # instance if str(address.public_ip) != instance.ip_address: - vm_system.setValue( - 'net_interface.' + str(num_nets) + '.ip', str(instance.ip_address)) - vm_system.setValue( - 'net_interface.' + str(num_nets) + '.connection', public_net.id) + vm_system.setValue('net_interface.' + str(num_nets) + '.ip', str(instance.ip_address)) + vm_system.setValue('net_interface.' + str(num_nets) + '.connection', public_net.id) num_pub_nets += 1 num_nets += 1 @@ -1020,8 +1018,7 @@ def setIPsFromInstance(self, vm, instance): n = 0 requested_ips = [] while vm.getRequestedSystem().getValue("net_interface." + str(n) + ".connection"): - net_conn = vm.getRequestedSystem().getValue( - 'net_interface.' + str(n) + '.connection') + net_conn = vm.getRequestedSystem().getValue('net_interface.' + str(n) + '.connection') if vm.info.get_network_by_id(net_conn).isPublic(): fixed_ip = vm.getRequestedSystem().getValue("net_interface." + str(n) + ".ip") requested_ips.append(fixed_ip)