From fe32b7e01d1b7ba7f6c69ffbfc1e207f791623cd Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 15 Nov 2018 15:49:33 +0100 Subject: [PATCH 1/4] Fix security error with xmlrpclib --- IM/connectors/OpenNebula.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/IM/connectors/OpenNebula.py b/IM/connectors/OpenNebula.py index 0b923a81c..39c4e5d82 100644 --- a/IM/connectors/OpenNebula.py +++ b/IM/connectors/OpenNebula.py @@ -14,15 +14,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import hashlib +import defusedxml.xmlrpc +defusedxml.xmlrpc.monkey_patch() + try: from xmlrpclib import ServerProxy except ImportError: from xmlrpc.client import ServerProxy +import hashlib import time -import defusedxml.xmlrpc -defusedxml.xmlrpc.monkey_patch() from distutils.version import LooseVersion from IM.xmlobject import XMLObject From 6e24620d961c94224fbbdeffa865bd2046264eba Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 19 Nov 2018 10:40:54 +0100 Subject: [PATCH 2/4] Implements: #716 --- IM/connectors/GCE.py | 7 +++++++ test/unit/connectors/GCE.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/IM/connectors/GCE.py b/IM/connectors/GCE.py index ead0fcea9..18c4ff3c0 100644 --- a/IM/connectors/GCE.py +++ b/IM/connectors/GCE.py @@ -255,6 +255,12 @@ def get_instance_type(self, sizes, radl): memory = radl.getFeature('memory.size').getValue('M') memory_op = radl.getFeature('memory.size').getLogOperator() + disk_free = 0 + disk_free_op = ">=" + if radl.getValue('disks.free_size'): + disk_free = radl.getFeature('disks.free_size').getValue('G') + disk_free_op = radl.getFeature('disks.free_size').getLogOperator() + res = None for size in sizes: # get the node size with the lowest price and memory (in the case @@ -266,6 +272,7 @@ def get_instance_type(self, sizes, radl): if 'guestCpus' in size.extra and size.extra['guestCpus']: str_compare = "size.extra['guestCpus'] " + cpu_op + " cpu and " str_compare += "size.ram " + memory_op + " memory" + str_compare += " and size.disk " + disk_free_op + " disk_free" if eval(str_compare): if not instance_type_name or size.name == instance_type_name: diff --git a/test/unit/connectors/GCE.py b/test/unit/connectors/GCE.py index 058ab4c27..14f75de8b 100755 --- a/test/unit/connectors/GCE.py +++ b/test/unit/connectors/GCE.py @@ -140,6 +140,7 @@ def test_20_launch(self, save_data, get_driver): disk.0.os.name = 'linux' and disk.0.image.url = 'gce://us-central1-a/centos-6' and disk.0.os.credentials.username = 'user' and + disks.free_size >= 100g and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' @@ -159,7 +160,7 @@ def test_20_launch(self, save_data, get_driver): node_size = MagicMock() node_size.ram = 512 node_size.price = 1 - node_size.disk = 1 + node_size.disk = 100 node_size.vcpus = 1 node_size.name = "small" node_size.extra = {'guestCpus': 1} From ec47dd5175c6619c287587851473ea7090569296 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 19 Nov 2018 11:52:29 +0100 Subject: [PATCH 3/4] Revert: #716 as the disk info is not correctly returned --- IM/connectors/GCE.py | 9 +-------- test/unit/connectors/GCE.py | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/IM/connectors/GCE.py b/IM/connectors/GCE.py index 18c4ff3c0..07d0db3bb 100644 --- a/IM/connectors/GCE.py +++ b/IM/connectors/GCE.py @@ -255,24 +255,17 @@ def get_instance_type(self, sizes, radl): memory = radl.getFeature('memory.size').getValue('M') memory_op = radl.getFeature('memory.size').getLogOperator() - disk_free = 0 - disk_free_op = ">=" - if radl.getValue('disks.free_size'): - disk_free = radl.getFeature('disks.free_size').getValue('G') - disk_free_op = radl.getFeature('disks.free_size').getLogOperator() - res = None for size in sizes: # get the node size with the lowest price and memory (in the case # of the price is not set) if size.price is None: size.price = 0 - if res is None or (size.price <= res.price and size.ram <= res.ram): + if res is None or (size.price <= res.price or size.ram <= res.ram): str_compare = "" if 'guestCpus' in size.extra and size.extra['guestCpus']: str_compare = "size.extra['guestCpus'] " + cpu_op + " cpu and " str_compare += "size.ram " + memory_op + " memory" - str_compare += " and size.disk " + disk_free_op + " disk_free" if eval(str_compare): if not instance_type_name or size.name == instance_type_name: diff --git a/test/unit/connectors/GCE.py b/test/unit/connectors/GCE.py index 14f75de8b..058ab4c27 100755 --- a/test/unit/connectors/GCE.py +++ b/test/unit/connectors/GCE.py @@ -140,7 +140,6 @@ def test_20_launch(self, save_data, get_driver): disk.0.os.name = 'linux' and disk.0.image.url = 'gce://us-central1-a/centos-6' and disk.0.os.credentials.username = 'user' and - disks.free_size >= 100g and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' @@ -160,7 +159,7 @@ def test_20_launch(self, save_data, get_driver): node_size = MagicMock() node_size.ram = 512 node_size.price = 1 - node_size.disk = 100 + node_size.disk = 1 node_size.vcpus = 1 node_size.name = "small" node_size.extra = {'guestCpus': 1} From 575127c97326edcfbae6a43c5a5f5949f2698e29 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 19 Nov 2018 12:11:48 +0100 Subject: [PATCH 4/4] Improve size selection --- IM/connectors/GCE.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IM/connectors/GCE.py b/IM/connectors/GCE.py index 07d0db3bb..1d6645118 100644 --- a/IM/connectors/GCE.py +++ b/IM/connectors/GCE.py @@ -260,7 +260,7 @@ def get_instance_type(self, sizes, radl): # get the node size with the lowest price and memory (in the case # of the price is not set) if size.price is None: - size.price = 0 + size.price = 9999 if res is None or (size.price <= res.price or size.ram <= res.ram): str_compare = "" if 'guestCpus' in size.extra and size.extra['guestCpus']: