From 1793931521dfcd44310721c66494e44901ac090a Mon Sep 17 00:00:00 2001 From: Huang Haibin Date: Sat, 24 Mar 2018 06:29:32 +0800 Subject: Update ovsdpdk of hpa to AAI Change-Id: Ie8d89e272f3cc29e5cef7e7ac100c23bd5975249 Issue-ID: MULTICLOUD-195 Signed-off-by: Huang Haibin --- ocata/ocata/registration/views/registration.py | 94 ++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'ocata') 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 + -- cgit 1.2.3-korg