summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/vesagent/event_domain
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-05-15 09:14:41 +0000
committerBin Yang <bin.yang@windriver.com>2018-05-15 09:14:41 +0000
commitbb00bacfc825cd22fed699cf5399257028ebfd5c (patch)
treecf259ddeb0452461ed1d2ce252986907efd39a37 /windriver/titanium_cloud/vesagent/event_domain
parentebb344c71cbf749262d2556a3465a8b49a6eb8af (diff)
collect VM status according to the backlog
Change-Id: I21c96831e6fc9bd6fcf76d3717054db2257815c6 Issue-ID: MULTICLOUD-230 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'windriver/titanium_cloud/vesagent/event_domain')
-rw-r--r--windriver/titanium_cloud/vesagent/event_domain/fault_vm.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py b/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py
index 5ece71ab..d5c40fe5 100644
--- a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py
+++ b/windriver/titanium_cloud/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