diff options
author | Bin Hu <bh526r@att.com> | 2018-03-24 18:02:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-24 18:02:58 +0000 |
commit | bcb7f9ef76409473b6002f65b9427b0c05178fcf (patch) | |
tree | f5c086c180c829a8de2e6ecf60d31b9adb796937 | |
parent | fdab34b268dfdbc244a718a32054fec28b973f6a (diff) | |
parent | 1793931521dfcd44310721c66494e44901ac090a (diff) |
Merge "Update ovsdpdk of hpa to AAI"
-rw-r--r-- | ocata/ocata/registration/views/registration.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ocata/ocata/registration/views/registration.py b/ocata/ocata/registration/views/registration.py index e3121240..ddd856b5 100644 --- a/ocata/ocata/registration/views/registration.py +++ b/ocata/ocata/registration/views/registration.py @@ -240,3 +240,97 @@ class Registry(newton_registration.Registry): except Exception as e: self._logger.error(traceback.format_exc()) return + + def _update_epa_caps(self, cloud_owner, cloud_region_id, cloud_extra_info): + ''' + populate cloud EPA Capabilities information into AAI + :param cloud_owner: + :param cloud_region_id: + :param epa_caps_info: dict of meta data about cloud-region's epa caps + + :return: + ''' + cloud_epa_caps_info = {} + cloud_epa_caps_info.update(cloud_extra_info.get("epa-caps")) + cloud_hpa_info = cloud_extra_info.get("ovsDpdk") + cloud_epa_caps = { + 'cloud-epa-caps': json.dumps(epa_caps_info), + } + + if cloud_hpa_info: + attributes = [ + { + 'hpa-attribute-key': cloud_hpa_info.get("libname"), + 'hpa-attribute-value': cloud_hpa_info.get("libvalue"), + } + ] + + hpa_capability = [ + { + 'hpa-capability-id': str(uuid.uuid4()), + 'hpa-feature': 'ovsDpdk', + 'hpa-version': cloud_hpa_info.get("version"), + 'architecture': cloud_hpa_info.get("arch"), + 'hpa-feature-attributes': attributes + }, + ] + + hpa_capabilities = { + 'hpa-capability': hpa_capability + } + + cloud_hpa_caps = { + 'hpa_capabilities': hpa_capabilities + } + + if cloud_owner and cloud_region_id: + resource_url = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s" \ + % (cloud_owner, cloud_region_id) + + # get cloud-region + retcode, content, status_code = \ + restcall.req_to_aai(resource_url, "GET") + + #add resource-version to url + if retcode == 0 and content: + content = json.JSONDecoder().decode(content) + #cloud_epa_caps["resource-version"] = content["resource-version"] + content.update(cloud_epa_caps) + content.update(cloud_hpa_caps) + cloud_epa_caps = content + + #update cloud-region + retcode, content, status_code = \ + restcall.req_to_aai(resource_url, "PUT", content=cloud_epa_caps) + + self._logger.debug( + "update_epa_caps,vimid:%s_%s req_to_aai: update cloud-epa-caps, return %s, %s, %s" + % (cloud_owner,cloud_region_id, retcode, content, status_code)) + + return retcode + return 1 # unknown cloud owner,region_id + + def _discover_epa_resources(self, vimid="", viminfo=None): + try: + cloud_extra_info_str = viminfo.get('cloud_extra_info') + if cloud_extra_info_str: + cloud_extra_info = json.loads(cloud_extra_info_str) + + cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) + ret = self._update_epa_caps(cloud_owner, cloud_region_id, + cloud_extra_info) + if ret != 0: + # failed to update image + self._logger.debug("failed to populate EPA CAPs info into AAI: %s, ret:%s" + % (vimid, ret)) + + 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 + |