summaryrefslogtreecommitdiffstats
path: root/ocata
diff options
context:
space:
mode:
authorzhang ab <zhanganbing@chinamobile.com>2018-03-16 03:41:15 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-16 03:41:15 +0000
commit27097cb92644e84fd7f72d56f1d4f2009f1e8f10 (patch)
tree43305a96858d9fec76a9d2f17a7ff47801dda4c1 /ocata
parent6c7295e3de3fe80e8a5adf31b64be186e27ce5ad (diff)
parent3846d73f3d7bbc91f3f2672fbbd78f7667890a54 (diff)
Merge "update hpa cpu pinning to support AAI schema v13"
Diffstat (limited to 'ocata')
-rw-r--r--ocata/ocata/registration/tests/test_registration.py14
-rw-r--r--ocata/ocata/registration/views/registration.py80
2 files changed, 92 insertions, 2 deletions
diff --git a/ocata/ocata/registration/tests/test_registration.py b/ocata/ocata/registration/tests/test_registration.py
index 5193d602..e7d089b9 100644
--- a/ocata/ocata/registration/tests/test_registration.py
+++ b/ocata/ocata/registration/tests/test_registration.py
@@ -34,14 +34,24 @@ MOCK_GET_FLAVOR_RESPONSE = {
"id": "1", "name": "micro", "vcpus": 1, "ram": "1MB",
"disk": "1G", "OS-FLV-EXT-DATA:ephemeral": False,
"swap": True, "os-flavor-access:is_public": True,
- "OS-FLV-DISABLED:disabled": True, "link": [{"href":1}]
+ "OS-FLV-DISABLED:disabled": True, "link": [{"href":1}],
+ "properties": "hw:cpu_policy, hw:cpu_thread_policy"
},
{
"id": "2", "name": "mini", "vcpus": 2, "ram": "2MB",
"disk": "2G", "OS-FLV-EXT-DATA:ephemeral": True,
"swap": False, "os-flavor-access:is_public": True,
- "OS-FLV-DISABLED:disabled": True
+ "OS-FLV-DISABLED:disabled": True,
+ "properties": "hw:cpu_policy, hw:cpu_thread_policy"
},
+ {
+ "id": "3", "name": "onap.cpu_pinning", "vcpus": 2, "ram": "2MB",
+ "disk": "2G", "OS-FLV-EXT-DATA:ephemeral": True,
+ "swap": False, "os-flavor-access:is_public": True,
+ "OS-FLV-DISABLED:disabled": True,
+ "properties": "hw:cpu_policy, hw:cpu_thread_policy"
+ },
+
]
}
diff --git a/ocata/ocata/registration/views/registration.py b/ocata/ocata/registration/views/registration.py
index 69c85837..5d663fe1 100644
--- a/ocata/ocata/registration/views/registration.py
+++ b/ocata/ocata/registration/views/registration.py
@@ -13,10 +13,16 @@
# limitations under the License.
import logging
+import json
+import uuid
+import traceback
from django.conf import settings
from newton_base.registration import registration as newton_registration
+from common.exceptions import VimDriverNewtonException
+from common.msapi import extsys
+from keystoneauth1.exceptions import HttpError
logger = logging.getLogger(__name__)
@@ -28,3 +34,77 @@ class Registry(newton_registration.Registry):
self.proxy_prefix = settings.MULTICLOUD_PREFIX
self.aai_base_url = settings.AAI_BASE_URL
self._logger = logger
+
+ def _discover_flavors(self, vimid="", session=None, viminfo=None):
+ try:
+ cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
+ hpa_caps = []
+ hpa_caps.append("[")
+ for flavor in self._get_list_resources(
+ "/flavors/detail", "compute", session, viminfo, vimid,
+ "flavors"):
+
+ flavor_info = {
+ 'flavor-id': flavor['id'],
+ 'flavor-name': flavor['name'],
+ 'flavor-vcpus': flavor['vcpus'],
+ 'flavor-ram': flavor['ram'],
+ 'flavor-disk': flavor['disk'],
+ 'flavor-ephemeral': flavor['OS-FLV-EXT-DATA:ephemeral'],
+ 'flavor-swap': flavor['swap'],
+ 'flavor-is-public': flavor['os-flavor-access:is_public'],
+ 'flavor-disabled': flavor['OS-FLV-DISABLED:disabled'],
+ }
+
+
+ if flavor.get('link') and len(flavor['link']) > 0:
+ flavor_info['flavor-selflink'] = flavor['link'][0]['href'] or 'http://0.0.0.0',
+ else:
+ flavor_info['flavor-selflink'] = 'http://0.0.0.0',
+
+ # add hpa capabilities
+ if (flavor['name'].find('onap.') == -1):
+ continue
+
+ properties = flavor['properties'].split(', ')
+ if len(properties):
+ flavor_info['flavor-properties'] = flavor['properties']
+ # add hpa capability cpu pinning
+ if (flavor['name'].find('onap.cpu_pinning') != -1):
+ uuid1 = uuid.uuid4()
+ hpa_caps.append("{'hpaCapabilityID': '" + str(uuid1) + "', ")
+ hpa_caps.append("'hpaFeature': 'cpuPinning', ")
+ hpa_caps.append("'hardwareArchitecture': 'generic', ")
+ hpa_caps.append("'version': 'v1', ")
+
+ hpa_caps.append("[")
+ for p in range(len(properties)):
+ if (properties[p] == "hw:cpu_policy") :
+ hpa_caps.append("{'hpa-attribute-key':'logicalCpuThreadPinningPolicy', ")
+ hpa_caps.append("'hpa-attribute-value': {'value':'prefer'}}, ")
+ if (properties[p] == "hw:cpu_thread_policy") :
+ hpa_caps.append("{'hpa-attribute-key':'logicalCpuPinningPolicy', ")
+ hpa_caps.append("'hpa-attribute-value': {'value':'dedicated'}}, ")
+ hpa_caps.append("]},")
+ else:
+ self._logger.info("can not support this properties")
+ else:
+ self._logger.info("can not support this flavor type")
+ hpa_caps.append("]")
+ str_hpa_caps = ''
+ flavor_info['hpa_capabilities'] = str_hpa_caps.join(hpa_caps)
+ self._logger.debug("flavor_info: %s" % flavor_info)
+
+ self._update_resoure(
+ cloud_owner, cloud_region_id, flavor['id'],
+ flavor_info, "flavor")
+
+ except VimDriverNewtonException as e:
+ self._logger.error("VimDriverNewtonException: status:%s, response:%s" % (e.http_status, e.content))
+ return
+ except HttpError as e:
+ self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
+ return
+ except Exception as e:
+ self._logger.error(traceback.format_exc())
+ return