diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-07-04 17:58:26 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-07-04 17:58:26 +0800 |
commit | 645b1edaf2f914ae74281b9941605e296e9ead93 (patch) | |
tree | 4f9a9fe626e2073ad0225164ec4ab1af1292201f | |
parent | a47080445507f1dc444144bfe9c948c9f8f16224 (diff) |
collect VM status of the backlog for ocata
Change-Id: If81ab2d0a625618386f703a32293e506e0fa8348
Issue-ID: MULTICLOUD-230
Signed-off-by: Yun Huang <yun.huang@windriver.com>
-rw-r--r-- | ocata/ocata/vesagent/event_domain/fault_vm.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ocata/ocata/vesagent/event_domain/fault_vm.py b/ocata/ocata/vesagent/event_domain/fault_vm.py index 5ece71ab..d5c40fe5 100644 --- a/ocata/ocata/vesagent/event_domain/fault_vm.py +++ b/ocata/ocata/vesagent/event_domain/fault_vm.py @@ -115,5 +115,48 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog): logger.debug("vesAgentConfig:%s, vesAgentState:%s, oneBacklog: %s" % (vesAgentConfig, vesAgentState, oneBacklog)) + try: + vimid = vesAgentConfig["vimid"] + tenant_name = oneBacklog["tenant"] + + # get token + auth_api_url_format = "/{f_vim_id}/identity/v2.0/tokens" + auth_api_url = auth_api_url_format.format(f_vim_id=vimid) + auth_api_data = { "auth":{"tenantName": tenant_name} } + base_url = settings.MULTICLOUD_PREFIX + extra_headers = '' + logger.debug("authenticate with url:%s" % auth_api_url) + ret = _call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data)) + if ret[0] > 0 or ret[1] is None: + logger.critical("call url %s failed with status %s" % (auth_api_url, ret[0])) + + token_resp = json.JSONDecoder().decode(ret[1]) + logger.debug("authenticate resp: %s" % token_resp) + token = token_resp["access"]["token"]["id"] + + # collect data by issue API + api_link = oneBacklog["api_link"] + method = oneBacklog["api_method"] + base_url = settings.MULTICLOUD_PREFIX + data = '' + extra_headers = {'X-Auth-Token': token} + #which one is correct? extra_headers = {'HTTP_X_AUTH_TOKEN': token} + logger.debug("authenticate with url:%s, header:%s" % (auth_api_url,extra_headers)) + ret = _call_req(base_url, "", "", 0, api_link, method, extra_headers, data) + if ret[0] > 0 or ret[1] is None: + logger.critical("call url %s failed with status %s" % (api_link, ret[0])) + + server_resp = json.JSONDecoder().decode(ret[1]) + logger.debug("collected data: %s" % server_resp) + + # encode data + + # publish event to VES + + except Exception as e: + logger.error("exception:%s" % str(e)) + return + + logger.info("return") return |