From c878ac41bd98ef064b8e8fd1d39dbd879095a722 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Thu, 27 May 2021 12:00:30 +0200 Subject: [PATCH] Fix bug 1544 to read properly size capabilities in Azure Change-Id: Iff772db93b2d862848361ad40276dc8185379d63 Signed-off-by: garciadeblas --- RO-VIM-azure/osm_rovim_azure/vimconn_azure.py | 92 +++++++++---- requirements-test.txt | 2 +- requirements.txt | 121 ++++++++---------- 3 files changed, 120 insertions(+), 95 deletions(-) diff --git a/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py b/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py index 71c7f592..c78b0f92 100755 --- a/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py +++ b/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py @@ -49,6 +49,14 @@ if getenv("OSMRO_PDB_DEBUG"): pdb.set_trace() +def find_in_list(the_list, condition_lambda): + for item in the_list: + if condition_lambda(item): + return item + else: + return None + + class vimconnector(vimconn.VimConnector): # Translate azure provisioning state to OSM provision state @@ -253,6 +261,13 @@ class vimconnector(vimconn.VimConnector): if "flavors_pattern" in config: self._config["flavors_pattern"] = config["flavors_pattern"] + def _find_in_capabilities(self, capabilities, name): + cap = find_in_list(capabilities, lambda c: c["name"] == name) + if cap: + return cap.get("value") + else: + return None + def _reload_connection(self): """ Called before any operation, checks python azure clients @@ -1223,9 +1238,9 @@ class vimconnector(vimconn.VimConnector): try: self._reload_connection() vm_sizes_list = [ - vm_size.serialize() + vm_size.as_dict() for vm_size in self.conn_compute.resource_skus.list( - "location={}".format(self.region) + "location eq '{}'".format(self.region) ) ] @@ -1234,31 +1249,56 @@ class vimconnector(vimconn.VimConnector): numberInterfaces = len(filter_dict.get("interfaces", [])) or 0 # Filter - if self._config.get("flavors_pattern"): - filtered_sizes = [ - size - for size in vm_sizes_list - if size["capabilities"]["vCPUs"] >= cpus - and size["capabilities"]["MemoryGB"] >= memMB / 1024 - and size["capabilities"]["MaxNetworkInterfaces"] >= numberInterfaces - and re.search(self._config.get("flavors_pattern"), size["name"]) - ] - else: - filtered_sizes = [ - size - for size in vm_sizes_list - if size["capabilities"]["vCPUs"] >= cpus - and size["capabilities"]["MemoryGB"] >= memMB / 1024 - and size["capabilities"]["MaxNetworkInterfaces"] >= numberInterfaces - ] + filtered_sizes = [] + for size in vm_sizes_list: + if size["resource_type"] == "virtualMachines": + size_cpus = int( + self._find_in_capabilities(size["capabilities"], "vCPUs") + ) + size_memory = float( + self._find_in_capabilities(size["capabilities"], "MemoryGB") + ) + size_interfaces = self._find_in_capabilities( + size["capabilities"], "MaxNetworkInterfaces" + ) + if size_interfaces: + size_interfaces = int(size_interfaces) + else: + self.logger.debug( + "Flavor with no defined MaxNetworkInterfaces: {}".format( + size["name"] + ) + ) + continue + if ( + size_cpus >= cpus + and size_memory >= memMB / 1024 + and size_interfaces >= numberInterfaces + ): + if self._config.get("flavors_pattern"): + if re.search( + self._config.get("flavors_pattern"), size["name"] + ): + new_size = { + e["name"]: e["value"] for e in size["capabilities"] + } + new_size["name"] = size["name"] + filtered_sizes.append(new_size) + else: + new_size = { + e["name"]: e["value"] for e in size["capabilities"] + } + new_size["name"] = size["name"] + filtered_sizes.append(new_size) # Sort listedFilteredSizes = sorted( filtered_sizes, key=lambda k: ( - k["numberOfCores"], - k["memoryInMB"], - k["resourceDiskSizeInMB"], + int(k["vCPUs"]), + float(k["MemoryGB"]), + int(k["MaxNetworkInterfaces"]), + int(k["MaxResourceVolumeMB"]), ), ) @@ -1276,9 +1316,9 @@ class vimconnector(vimconn.VimConnector): try: self._reload_connection() vm_sizes_list = [ - vm_size.serialize() + vm_size.as_dict() for vm_size in self.conn_compute.resource_skus.list( - "location={}".format(self.region) + "location eq '{}'".format(self.region) ) ] @@ -2004,7 +2044,7 @@ if __name__ == "__main__": logger.debug("Network_list: {}".format(network_list)) logger.debug("List flavors") - flavors = azure.get_flavor_id_from_data({"vcpu": "2"}) + flavors = azure.get_flavor_id_from_data({"vcpus": 2}) logger.debug("flavors: {}".format(flavors)) """ @@ -2034,10 +2074,12 @@ if __name__ == "__main__": logger.debug("Vmachine: {}".format(vmachine)) """ + """ logger.debug("List images") image = azure.get_image_list({"name": "Canonical:UbuntuServer:16.04"}) # image = azure.get_image_list({"name": "Canonical:UbuntuServer:18.04-LTS"}) logger.debug("image: {}".format(image)) + """ """ # Create network and test machine diff --git a/requirements-test.txt b/requirements-test.txt index f2711aa5..7b16cb5e 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -24,5 +24,5 @@ mock==4.0.3 # via -r requirements-test.in nose2==0.10.0 # via -r requirements-test.in -six==1.15.0 +six==1.16.0 # via nose2 diff --git a/requirements.txt b/requirements.txt index 9f297d60..43d97f20 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,11 +16,11 @@ ####################################################################################### adal==1.2.7 # via msrestazure -aenum==3.0.0 +aenum==3.1.0 # via pyone alabaster==0.7.12 # via sphinx -alembic==1.5.8 +alembic==1.6.5 # via # neutron # oslo.db @@ -32,7 +32,7 @@ appdirs==1.4.4 # via openstacksdk argparse==1.4.0 # via unittest2 -attrs==20.3.0 +attrs==21.2.0 # via # cmd2 # jsonschema @@ -48,7 +48,7 @@ azure-core==1.14.0 # azure-mgmt-core azure-identity==1.6.0 # via -r RO-VIM-azure/requirements.in -azure-mgmt-compute==20.0.0 +azure-mgmt-compute==21.0.0 # via -r RO-VIM-azure/requirements.in azure-mgmt-core==1.2.2 # via @@ -59,17 +59,17 @@ azure-mgmt-network==19.0.0 # via -r RO-VIM-azure/requirements.in azure-mgmt-resource==18.0.0 # via -r RO-VIM-azure/requirements.in -babel==2.9.0 +babel==2.9.1 # via sphinx bcrypt==3.2.0 # via paramiko beautifulsoup4==4.9.3 # via webtest -bitarray==2.0.1 +bitarray==2.1.0 # via pyangbind boto==2.49.0 # via -r RO-VIM-aws/requirements.in -cachetools==4.2.1 +cachetools==4.2.2 # via oslo.messaging certifi==2020.12.5 # via @@ -87,7 +87,7 @@ cheroot==8.5.2 # via cherrypy cherrypy==18.1.2 # via -r NG-RO/requirements.in -cliff==3.7.0 +cliff==3.8.0 # via # osc-lib # python-designateclient @@ -107,7 +107,7 @@ cryptography==3.4.7 # paramiko # pyjwt # pyopenssl -cvprac==1.0.5 +cvprac==1.0.6 # via -r RO-SDN-arista_cloudvision/requirements.in debtcollector==2.2.0 # via @@ -125,7 +125,7 @@ debtcollector==2.2.0 # python-designateclient # python-keystoneclient # python-neutronclient -decorator==5.0.7 +decorator==5.0.9 # via # dogpile.cache # neutron @@ -135,15 +135,15 @@ dicttoxml==1.7.4 # via pyone dnspython==1.16.0 # via eventlet -docutils==0.16 +docutils==0.17.1 # via sphinx -dogpile.cache==1.1.2 +dogpile.cache==1.1.3 # via # openstacksdk # oslo.cache enum34==1.1.10 # via pyangbind -eventlet==0.30.2 +eventlet==0.31.0 # via # neutron # os-ken @@ -173,7 +173,7 @@ futurist==2.3.0 # neutron # oslo.messaging # tooz -greenlet==1.0.0 +greenlet==1.1.0 # via # eventlet # oslo.privsep @@ -189,19 +189,8 @@ idna==2.10 # via requests imagesize==1.2.0 # via sphinx -importlib-metadata==4.0.1 - # via - # -r NG-RO/requirements.in - # cmd2 - # jsonschema - # kombu - # openstacksdk - # oslo.config - # osprofiler - # sqlalchemy - # stevedore -importlib-resources==5.1.2 - # via netaddr +importlib-metadata==4.3.1 + # via -r NG-RO/requirements.in iso8601==0.1.14 # via # keystoneauth1 @@ -217,7 +206,7 @@ jaraco.functools==3.3.0 # via # cheroot # tempora -jinja2==2.11.3 +jinja2==3.0.1 # via # neutron # oslo.middleware @@ -252,7 +241,7 @@ keystoneauth1==4.3.1 # python-novaclient keystonemiddleware==9.2.0 # via neutron -kombu==5.0.2 +kombu==5.1.0 # via oslo.messaging linecache2==1.0.0 # via traceback2 @@ -270,11 +259,11 @@ mako==1.1.4 # via # alembic # pecan -markupsafe==1.1.1 +markupsafe==2.0.1 # via # jinja2 # mako -more-itertools==8.7.0 +more-itertools==8.8.0 # via # cheroot # cherrypy @@ -343,7 +332,7 @@ oauthlib==3.1.0 # via requests-oauthlib oca==4.10.0 # via -r RO-VIM-opennebula/requirements.in -openstacksdk==0.56.0 +openstacksdk==0.57.0 # via # neutron # os-client-config @@ -361,14 +350,14 @@ os-service-types==1.7.0 # openstacksdk os-traits==2.5.0 # via neutron-lib -os-vif==2.4.0 +os-vif==2.5.0 # via neutron -osc-lib==2.3.1 +osc-lib==2.4.0 # via # python-designateclient # python-neutronclient # python-openstackclient -oslo.cache==2.7.0 +oslo.cache==2.8.0 # via # keystonemiddleware # neutron @@ -380,7 +369,7 @@ oslo.concurrency==4.4.0 # oslo.service # oslo.versionedobjects # osprofiler -oslo.config==8.5.0 +oslo.config==8.7.0 # via # keystonemiddleware # neutron @@ -400,7 +389,7 @@ oslo.config==8.5.0 # oslo.versionedobjects # pycadf # python-keystoneclient -oslo.context==3.2.0 +oslo.context==3.3.0 # via # keystonemiddleware # neutron @@ -409,7 +398,7 @@ oslo.context==3.2.0 # oslo.middleware # oslo.policy # oslo.versionedobjects -oslo.db==8.5.0 +oslo.db==9.0.0 # via # neutron # neutron-lib @@ -439,7 +428,7 @@ oslo.i18n==5.0.1 # python-neutronclient # python-novaclient # python-openstackclient -oslo.log==4.4.0 +oslo.log==4.5.0 # via # keystonemiddleware # neutron @@ -451,7 +440,7 @@ oslo.log==4.4.0 # oslo.service # oslo.versionedobjects # python-neutronclient -oslo.messaging==12.7.1 +oslo.messaging==12.8.0 # via # neutron # neutron-lib @@ -460,7 +449,7 @@ oslo.middleware==4.2.0 # via # neutron # oslo.messaging -oslo.policy==3.7.0 +oslo.policy==3.8.0 # via # neutron # neutron-lib @@ -495,9 +484,9 @@ oslo.service==2.5.0 # neutron # neutron-lib # oslo.messaging -oslo.upgradecheck==1.3.0 +oslo.upgradecheck==1.4.0 # via neutron -oslo.utils==4.8.0 +oslo.utils==4.9.0 # via # keystonemiddleware # neutron @@ -539,7 +528,7 @@ ovs==2.13.3 # neutron # os-ken # ovsdbapp -ovsdbapp==1.9.0 +ovsdbapp==1.10.0 # via # networking-l2gw # neutron @@ -637,19 +626,19 @@ pycadf==3.1.1 # via keystonemiddleware pycparser==2.20 # via cffi -pygments==2.8.1 +pygments==2.9.0 # via # pyvcloud # sphinx pyinotify==0.9.6 # via oslo.log -pyjwt[crypto]==2.0.1 +pyjwt[crypto]==2.1.0 # via # adal # msal pynacl==1.4.0 # via paramiko -pyone==6.0.0 +pyone==6.0.2 # via -r RO-VIM-opennebula/requirements.in pyopenssl==20.0.1 # via @@ -664,9 +653,6 @@ pyparsing==2.4.7 pyperclip==1.8.2 # via cmd2 pyroute2==0.5.18 - # via - # neutron - # os-vif pyrsistent==0.17.3 # via jsonschema python-cinderclient==7.4.0 @@ -678,7 +664,7 @@ python-dateutil==2.8.1 # adal # alembic # oslo.log -python-designateclient==4.2.0 +python-designateclient==4.3.0 # via neutron python-editor==1.0.4 # via alembic @@ -692,12 +678,12 @@ python-keystoneclient==4.2.0 # python-openstackclient python-mimeparse==1.6.0 # via testtools -python-neutronclient==7.3.0 +python-neutronclient==7.4.0 # via # -r RO-VIM-openstack/requirements.in # networking-l2gw # neutron -python-novaclient==17.4.0 +python-novaclient==17.5.0 # via # -r RO-VIM-openstack/requirements.in # neutron @@ -781,7 +767,7 @@ requests==2.25.1 # sphinx requestsexceptions==1.4.0 # via openstacksdk -rfc3986==1.4.0 +rfc3986==1.5.0 # via oslo.config routes==2.5.1 # via @@ -825,7 +811,6 @@ six==1.16.0 # pyone # pyopenssl # python-dateutil - # python-designateclient # python-keystoneclient # pyvmomi # routes @@ -838,27 +823,27 @@ six==1.16.0 # webtest snowballstemmer==2.1.0 # via sphinx -sortedcontainers==2.3.0 +sortedcontainers==2.4.0 # via ovs soupsieve==2.2.1 # via beautifulsoup4 -sphinx==3.5.4 +sphinx==4.0.2 # via -r RO-VIM-fos/requirements.in sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-htmlhelp==2.0.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-serializinghtml==1.1.5 # via sphinx sqlalchemy-migrate==0.13.0 # via oslo.db -sqlalchemy==1.4.11 +sqlalchemy==1.4.17 # via # alembic # neutron @@ -895,7 +880,7 @@ tempita==0.5.2 # via sqlalchemy-migrate tempora==4.0.2 # via portend -tenacity==7.0.0 +tenacity==6.3.1 # via # neutron # tooz @@ -909,22 +894,22 @@ testtools==2.4.0 # testscenarios tinyrpc==1.0.4 # via os-ken -tooz==2.8.0 +tooz==2.9.0 # via neutron traceback2==1.4.0 # via # testtools # unittest2 -typing-extensions==3.7.4.3 - # via importlib-metadata unittest2==1.1.0 # via testtools -urllib3==1.26.4 +urllib3==1.26.5 # via requests uuid==1.30 # via -r RO-SDN-arista_cloudvision/requirements.in vine==5.0.0 - # via amqp + # via + # amqp + # kombu voluptuous==0.12.1 # via tooz waitress==2.0.0 @@ -966,9 +951,7 @@ zc.lockfile==2.0 zenoh==0.3.0 # via -r RO-VIM-fos/requirements.in zipp==3.4.1 - # via - # importlib-metadata - # importlib-resources + # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: # setuptools -- 2.17.1