Skip to content

Commit

Permalink
Merge pull request #605 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored May 15, 2018
2 parents 6ef093e + d30aaaa commit c1f13be
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 26 deletions.
5 changes: 4 additions & 1 deletion IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
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', 'uriparse',
'VirtualMachine', 'VMRC', 'xmlobject']
__version__ = '1.7.0'
__version__ = '1.7.1'
__author__ = 'Miguel Caballer'
28 changes: 20 additions & 8 deletions IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -645,14 +645,26 @@ 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_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)
self.log_info("The VM state is: " + vm.state)

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)

instance_type = self.get_instance_type_by_name(virtual_machine.hardware_profile.vm_size,
virtual_machine.location, credentials, subscription_id)
Expand Down
9 changes: 3 additions & 6 deletions IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,19 +1009,16 @@ 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

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)
Expand Down
6 changes: 5 additions & 1 deletion IM/connectors/OpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = []
Expand Down
6 changes: 5 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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).
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.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
Expand Down
7 changes: 5 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:16.04
LABEL maintainer="Miguel Caballer <[email protected]>"
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

Expand All @@ -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

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.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

Expand All @@ -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/

Expand Down
5 changes: 5 additions & 0 deletions test/unit/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_im_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c1f13be

Please sign in to comment.