Skip to content

Commit

Permalink
Merge pull request #961 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Dec 12, 2019
2 parents 1f53f3d + 7f06ffd commit bf3c8b8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 36 deletions.
24 changes: 24 additions & 0 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion IM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
13 changes: 1 addition & 12 deletions IM/connectors/OCCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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"):
Expand Down Expand Up @@ -544,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):
Expand Down Expand Up @@ -1081,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))
Expand Down Expand Up @@ -1603,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()
Expand All @@ -1615,21 +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
vm.delete_public_nets(vm.requested_radl)

return True, ""
else:
Expand Down
4 changes: 3 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,13 @@ 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.
* Fixed IP is not attached to the VM in OpenStack conn.
* 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.
2 changes: 1 addition & 1 deletion doc/swagger_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion docker-devel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM grycap/jenkins:ubuntu16.04-im
ARG BRANCH=devel
MAINTAINER Miguel Caballer <[email protected]>
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
Expand Down
4 changes: 2 additions & 2 deletions docker-py3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile to create a container with the IM service
FROM ubuntu:18.04
LABEL maintainer="Miguel Caballer <[email protected]>"
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

Expand All @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile to create a container with the IM service
FROM ubuntu:18.04
LABEL maintainer="Miguel Caballer <[email protected]>"
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

Expand All @@ -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/
Expand Down
4 changes: 3 additions & 1 deletion test/unit/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit bf3c8b8

Please sign in to comment.