From 4ee52afe58215325d68b5defe76795a41ecc351f Mon Sep 17 00:00:00 2001 From: micafer Date: Wed, 29 Nov 2017 11:30:41 +0100 Subject: [PATCH 1/3] Improve get_node_with_id function --- IM/connectors/OpenStack.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 5afbb82bd..8b6b87f42 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -53,6 +53,19 @@ def __init__(self, cloud_info, inf): self.add_public_ip_count = 0 LibCloudCloudConnector.__init__(self, cloud_info, inf) + def get_node_with_id(self, node_id, auth_data): + """ + Get the node with the specified ID + + Arguments: + - node_id(str): ID of the node to get + - auth(Authentication): parsed authentication tokens. + Returns: a :py:class:`libcloud.compute.base.Node` with the node info + """ + driver = self.get_driver(auth_data) + node = driver.ex_get_node_details(node_id) + return node + def get_driver(self, auth_data): """ Get the driver from the auth data From b375d1eb7358d5389054b6920fb84289be1ba88e Mon Sep 17 00:00:00 2001 From: micafer Date: Wed, 29 Nov 2017 13:42:11 +0100 Subject: [PATCH 2/3] Fix #503 --- IM/connectors/Azure.py | 2 +- IM/connectors/AzureClassic.py | 2 +- IM/connectors/EC2.py | 2 +- IM/connectors/OpenStack.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 54f38019f..a79845e4b 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -142,7 +142,7 @@ def get_instance_type(self, system, credentials, subscription_id): disk_free_op = ">=" if system.getValue('disks.free_size'): disk_free = system.getFeature('disks.free_size').getValue('M') - disk_free_op = system.getFeature('memory.size').getLogOperator() + disk_free_op = system.getFeature('disks.free_size').getLogOperator() compute_client = ComputeManagementClient(credentials, subscription_id) instace_types = list(compute_client.virtual_machine_sizes.list(location)) diff --git a/IM/connectors/AzureClassic.py b/IM/connectors/AzureClassic.py index 036c82687..db958727b 100644 --- a/IM/connectors/AzureClassic.py +++ b/IM/connectors/AzureClassic.py @@ -755,7 +755,7 @@ def get_instance_type(self, system, auth_data): disk_free_op = ">=" if system.getValue('disks.free_size'): disk_free = system.getFeature('disks.free_size').getValue('M') - disk_free_op = system.getFeature('memory.size').getLogOperator() + disk_free_op = system.getFeature('disks.free_size').getLogOperator() instace_types = self.get_all_instance_types(auth_data) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index d1d633565..3f289fdc5 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -283,7 +283,7 @@ def get_instance_type(self, radl, vpc=None): disk_free_op = ">=" if radl.getValue('disks.free_size'): disk_free = radl.getFeature('disks.free_size').getValue('G') - disk_free_op = radl.getFeature('memory.size').getLogOperator() + disk_free_op = radl.getFeature('disks.free_size').getLogOperator() performance = 0 performance_op = ">=" diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 8b6b87f42..4ee13997f 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -184,9 +184,9 @@ def get_instance_type(self, sizes, radl): memory_op = radl.getFeature('memory.size').getLogOperator() disk_free = 0 disk_free_op = ">=" - if radl.getValue('disk.0.free_size'): - disk_free = radl.getFeature('disk.0.free_size').getValue('G') - disk_free_op = radl.getFeature('memory.size').getLogOperator() + if radl.getValue('disks.free_size'): + disk_free = radl.getFeature('disks.free_size').getValue('G') + disk_free_op = radl.getFeature('disks.free_size').getLogOperator() # get the node size with the lowest price, vcpus and memory sizes.sort(key=lambda x: (x.price, x.vcpus, x.ram)) From 6450f100b8f40fb295bb062b961f89a5f74ab99d Mon Sep 17 00:00:00 2001 From: micafer Date: Wed, 29 Nov 2017 13:50:28 +0100 Subject: [PATCH 3/3] Fix #503 --- test/unit/connectors/OpenStack.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 3402a68d1..4372a9892 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -240,7 +240,7 @@ def test_30_updateVMInfo(self, get_driver): node.public_ips = [] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node node_size = MagicMock() node_size.ram = 512 @@ -308,7 +308,7 @@ def test_40_stop(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node driver.ex_stop_node.return_value = True @@ -336,7 +336,7 @@ def test_50_start(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node driver.ex_start_node.return_value = True @@ -386,7 +386,7 @@ def test_55_alter(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node node_size = MagicMock() node_size.ram = 2048 @@ -435,7 +435,7 @@ def test_60_finalize(self, sleep, get_driver): node.private_ips = ['10.0.0.1'] node.driver = driver node.destroy.return_value = True - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node keypair = MagicMock() driver.get_key_pair.return_value = keypair @@ -468,7 +468,7 @@ def test_70_create_snapshot(self, get_driver): node = MagicMock() node.id = "1" node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node image = MagicMock() image.id = "newimage" driver.create_image.return_value = image