From d65a361783f0768b03f2eb960e55024a61b0d15d Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 12 Dec 2019 12:31:51 +0100 Subject: [PATCH 1/3] Change version num to 1.9.0 --- IM/__init__.py | 2 +- changelog | 4 +++- doc/swagger_api.yaml | 2 +- docker-devel/Dockerfile | 2 +- docker-py3/Dockerfile | 4 ++-- docker/Dockerfile | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/IM/__init__.py b/IM/__init__.py index a750e8396..815cef794 100644 --- a/IM/__init__.py +++ b/IM/__init__.py @@ -19,5 +19,5 @@ 'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry', 'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter', 'VirtualMachine', 'VMRC', 'xmlobject'] -__version__ = '1.8.7' +__version__ = '1.9.0' __author__ = 'Miguel Caballer' diff --git a/changelog b/changelog index 0fffb7a62..80941ac08 100644 --- a/changelog +++ b/changelog @@ -552,7 +552,7 @@ IM 1.8.6: * Fix error creating GCE FW. * Enable to specify the snapshot name in disk url in EC2 conn. -IM 1.8.7: +IM 1.9.0: * Get device info from disks on OpenStack conn. * Fix error setting keypair name as public_key in the EC2 conn. * Enable to set volume_type in OpenStack conn. @@ -560,3 +560,5 @@ IM 1.8.7: * Fix error do not release floating IPs if they are not created by the IM in OpenStack conn. * Fix error new line chars removed in TOSCA values. * Remove added VMs in case that all of them fails in the addition process. + * Fix error OpenStack_2_NodeDriver object has no attribute 'get_floating_ip'. + * Add deleting state. diff --git a/doc/swagger_api.yaml b/doc/swagger_api.yaml index 47603cc21..86366c42a 100644 --- a/doc/swagger_api.yaml +++ b/doc/swagger_api.yaml @@ -2,7 +2,7 @@ swagger: '2.0' info: description: Infrastructure Manager (IM) REST API. - version: 1.8.7 + version: 1.9.0 title: Infrastructure Manager (IM) REST API contact: email: products@grycap.upv.es diff --git a/docker-devel/Dockerfile b/docker-devel/Dockerfile index 808041cd6..eddfad40e 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.8.7" +LABEL version="1.9.0" 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 0b13884d2..bcbfb0000 100644 --- a/docker-py3/Dockerfile +++ b/docker-py3/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.8.7" +LABEL version="1.9.0" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y gcc git python3 pip3 install pip --upgrade -I && \ /usr/local/bin/pip3 install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage && \ /usr/local/bin/pip3 install pyOpenSSL pycrypto cheroot xmltodict pymongo ansible==2.7.13 && \ - /usr/local/bin/pip3 install IM==1.8.7 && \ + /usr/local/bin/pip3 install IM==1.9.0 && \ /usr/local/bin/pip3 uninstall pip -y && \ apt-get purge -y gcc git libssl-dev libffi-dev libsqlite3-dev python3-dev python3-pip && \ apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/ diff --git a/docker/Dockerfile b/docker/Dockerfile index 6c018a854..e71275566 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.8.7" +LABEL version="1.9.0" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y gcc git python pip install pip --upgrade -I && \ /usr/local/bin/pip install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage && \ /usr/local/bin/pip install MySQL-python pyOpenSSL pycrypto xmltodict pymongo && \ - /usr/local/bin/pip install IM==1.8.7 && \ + /usr/local/bin/pip install IM==1.9.0 && \ /usr/local/bin/pip uninstall pip -y && \ apt-get purge -y gcc git python-dev python-pip libmysqld-dev libssl-dev libffi-dev libsqlite3-dev && \ apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/ From 90e2462442edd1afaec527019e75d95d4aa648f9 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 12 Dec 2019 14:26:29 +0100 Subject: [PATCH 2/3] Remove disconnected IPs: #957 --- IM/connectors/OpenStack.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index a2b8d685c..b98b678b0 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -456,6 +456,14 @@ def setIPsFromInstance(self, vm, node): - node(:py:class:`libcloud.compute.base.Node`): object to connect to EC2 instance. """ + # First remove old + system = vm.info.systems[0] + cont = 0 + while system.getValue('net_interface.%d.connection' % cont): + if system.getValue('net_interface.%d.ip' % cont): + system.delValue('net_interface.%d.ip' % cont) + cont += 1 + if 'addresses' in node.extra: public_ips = [] ip_net_map = {} @@ -481,7 +489,6 @@ def setIPsFromInstance(self, vm, node): map_nets = self.map_radl_ost_networks(vm, ip_net_map) - system = vm.info.systems[0] i = 0 ips_assigned = [] while system.getValue("net_interface." + str(i) + ".connection"): @@ -1622,6 +1629,19 @@ def alter_public_ips(self, vm, radl, auth_data): nets_id = [net.id for net in vm.requested_radl.networks if net.isPublic()] system = vm.requested_radl.systems[0] + i = 0 + while system.getValue('net_interface.%d.connection' % i): + f = system.getFeature("net_interface.%d.connection" % i) + if f.value in nets_id: + system.delValue('net_interface.%d.connection' % i) + if system.getValue('net_interface.%d.ip' % i): + system.delValue('net_interface.%d.ip' % i) + i += 1 + + # Also remove them from the info RADL + nets_id = [net.id for net in vm.info.networks if net.isPublic()] + system = vm.info.systems[0] + i = 0 while system.getValue('net_interface.%d.connection' % i): f = system.getFeature("net_interface.%d.connection" % i) From 7f06ffde525faf60c1e3eb53e7e1f94faa3679db Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 12 Dec 2019 16:30:20 +0100 Subject: [PATCH 3/3] Remove disconnected IPs: #957 --- IM/VirtualMachine.py | 24 +++++++++++++++++++++++ IM/connectors/OCCI.py | 13 +------------ IM/connectors/OpenStack.py | 32 +++++-------------------------- test/unit/connectors/OpenStack.py | 4 +++- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index afd5b9623..3886329ec 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -1079,3 +1079,27 @@ def get_ssh_command(self): ssh.host)) return command + + @staticmethod + def delete_public_nets(radl): + """ + Helper function to correctly delete references to public nets in an RADL + """ + nets_id = [net.id for net in radl.networks if net.isPublic()] + system = radl.systems[0] + + i = 0 + while system.getValue('net_interface.%d.connection' % i): + next_net = system.getValue('net_interface.%d.connection' % (i + 1)) + next_dns = system.getValue('net_interface.%d.connection' % (i + 1)) + f = system.getFeature("net_interface.%d.connection" % i) + if f.value in nets_id: + if next_net: + system.setValue('net_interface.%d.connection' % i, next_net) + system.setValue('net_interface.%d.dns_name' % i, next_dns) + else: + system.delValue('net_interface.%d.connection' % i) + system.delValue('net_interface.%d.dns_name' % i) + if system.getValue('net_interface.%d.ip' % i): + system.delValue('net_interface.%d.ip' % i) + i += 1 diff --git a/IM/connectors/OCCI.py b/IM/connectors/OCCI.py index 89f391bfe..270f53bcf 100644 --- a/IM/connectors/OCCI.py +++ b/IM/connectors/OCCI.py @@ -1193,18 +1193,7 @@ def manage_nics(self, vm, radl, auth_data, auth_header): if success: # Remove all public net connections in the Requested RADL - nets_id = [net.id for net in vm.requested_radl.networks if net.isPublic()] - system = vm.requested_radl.systems[0] - - i = 0 - while system.getValue('net_interface.%d.connection' % i): - f = system.getFeature("net_interface.%d.connection" % i) - if f.value in nets_id: - system.delValue('net_interface.%d.connection' % i) - if system.getValue('net_interface.%d.ip' % i): - system.delValue('net_interface.%d.ip' % i) - i += 1 - + vm.delete_public_nets(vm.requested_radl) return True, "" else: return False, msg diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index b98b678b0..89855dab6 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -551,8 +551,7 @@ def update_system_info_from_instance(self, system, instance_type): if instance_type: LibCloudCloudConnector.update_system_info_from_instance(system, instance_type) if instance_type.vcpus: - system.addFeature( - Feature("cpu.count", "=", instance_type.vcpus), conflict="me", missing="other") + system.addFeature(Feature("cpu.count", "=", instance_type.vcpus), conflict="me", missing="other") @staticmethod def get_ost_net(driver, name=None, netid=None): @@ -1088,7 +1087,7 @@ def manage_elastic_ips(self, vm, node, public_ips): while vm.getRequestedSystem().getValue("net_interface." + str(n) + ".connection"): net_conn = vm.getRequestedSystem().getValue('net_interface.' + str(n) + '.connection') net = vm.info.get_network_by_id(net_conn) - if net.isPublic(): + if net and net.isPublic(): fixed_ip = vm.getRequestedSystem().getValue("net_interface." + str(n) + ".ip") pool_name = net.getValue("provider_id") requested_ips.append((fixed_ip, pool_name)) @@ -1610,6 +1609,7 @@ def alter_public_ips(self, vm, radl, auth_data): current_public_ip = vm.getPublicIP() new_has_public_ip = radl.hasPublicNet(vm.info.systems[0].name) if new_has_public_ip and not current_public_ip: + self.log_info("Adding Public IP.") for net in radl.networks: if net.isPublic(): new_public_net = net.clone() @@ -1622,34 +1622,12 @@ def alter_public_ips(self, vm, radl, auth_data): if not new_has_public_ip and current_public_ip: floating_ip = node.driver.ex_get_floating_ip(current_public_ip) + self.log_info("Removing Public IP: %s." % floating_ip) if node.driver.ex_detach_floating_ip_from_node(node, floating_ip): floating_ip.delete() # Remove all public net connections in the Requested RADL - nets_id = [net.id for net in vm.requested_radl.networks if net.isPublic()] - system = vm.requested_radl.systems[0] - - i = 0 - while system.getValue('net_interface.%d.connection' % i): - f = system.getFeature("net_interface.%d.connection" % i) - if f.value in nets_id: - system.delValue('net_interface.%d.connection' % i) - if system.getValue('net_interface.%d.ip' % i): - system.delValue('net_interface.%d.ip' % i) - i += 1 - - # Also remove them from the info RADL - nets_id = [net.id for net in vm.info.networks if net.isPublic()] - system = vm.info.systems[0] - - i = 0 - while system.getValue('net_interface.%d.connection' % i): - f = system.getFeature("net_interface.%d.connection" % i) - if f.value in nets_id: - system.delValue('net_interface.%d.connection' % i) - if system.getValue('net_interface.%d.ip' % i): - system.delValue('net_interface.%d.ip' % i) - i += 1 + vm.delete_public_nets(vm.requested_radl) return True, "" else: diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 1954b6bc8..51fb63258 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -535,7 +535,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): node.id = "1" node.state = "running" node.extra = {'flavorId': 'small', 'vm_state': 'resized'} - node.public_ips = ['158.42.1.1'] + node.public_ips = [] node.private_ips = ['10.0.0.1'] node.driver = driver driver.ex_get_node_details.return_value = node @@ -547,6 +547,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): node_size.vcpus = 2 node_size.name = "small" driver.list_sizes.return_value = [node_size] + driver.ex_get_size.return_value = node_size driver.ex_resize.return_value = True driver.ex_confirm_resize.return_value = True @@ -618,6 +619,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): fip.delete.return_value = True driver.ex_get_floating_ip.return_value = fip driver.ex_detach_floating_ip_from_node.return_value = True + node.public_ips = ['158.42.1.1'] success, _ = ost_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.")