From 786e42a71518a44e7ba71feb42faad1f1dae55a4 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Tue, 15 May 2018 09:36:47 +0000 Subject: Add GET API to retrieve config and backlogs Change-Id: I3fb4063ab6346b51c36b29f82202f5e2fe1b2d8a Issue-ID: MULTICLOUD-230 Signed-off-by: Bin Yang --- windriver/titanium_cloud/vesagent/vesagent_ctrl.py | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'windriver/titanium_cloud/vesagent/vesagent_ctrl.py') diff --git a/windriver/titanium_cloud/vesagent/vesagent_ctrl.py b/windriver/titanium_cloud/vesagent/vesagent_ctrl.py index a531a61a..e7094aa4 100644 --- a/windriver/titanium_cloud/vesagent/vesagent_ctrl.py +++ b/windriver/titanium_cloud/vesagent/vesagent_ctrl.py @@ -162,8 +162,23 @@ class VesAgentCtrl(APIView): ''' self._logger.info("vimid: %s" % vimid) self._logger.debug("with META: %s" % request.META) + try: + # get vesagent_config from cloud region + viminfo = extsys.get_vim_by_id(vimid) + cloud_extra_info_str = viminfo.get('cloud_extra_info', None) + cloud_extra_info = json.loads(cloud_extra_info_str) if cloud_extra_info_str is not None else None + vesagent_config = cloud_extra_info.get("vesagent_config", None) if cloud_extra_info is not None else None - pass + vesagent_backlogs = self.getBacklogsOneVIM(vimid) + + except Exception as e: + self._logger.error("exception:%s" % str(e)) + return Response(data={'error': str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + return Response(data={"vesagent_config":vesagent_config, + "vesagent_backlogs": vesagent_backlogs}, + status=status.HTTP_200_OK) def post(self, request, vimid=""): @@ -230,6 +245,36 @@ class VesAgentCtrl(APIView): return Response(status=status.HTTP_200_OK) + def getBacklogsOneVIM(self, vimid): + ''' + remove the specified backlogs for a VIM + :param vimid: + :return: + ''' + self._logger.info("vimid: %s" % vimid) + + vesAgentConfig = None + try: + # retrive the backlogs + vesAgentConfigStr = cache.get("VesAgentBacklogs.config.%s" % (vimid)) + if vesAgentConfigStr is None: + logger.warn("VesAgentBacklogs.config.%s cannot be found in cache" % (vimid)) + return None + + logger.debug("VesAgentBacklogs.config.%s: %s" % (vimid, vesAgentConfigStr)) + + vesAgentConfig = json.loads(vesAgentConfigStr) + if vesAgentConfig is None: + logger.warn("VesAgentBacklogs.config.%s corrupts" % (vimid)) + return None + + except Exception as e: + self._logger.error("exception:%s" % str(e)) + vesAgentConfig = {"error": "exception occurs"} + + self._logger.info("return") + return vesAgentConfig + def buildBacklogsOneVIM(self, vimid, vesagent_config = None): ''' -- cgit 1.2.3-korg