summaryrefslogtreecommitdiffstats
path: root/share/common/msapi/helper.py
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-09-17 01:27:34 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-17 01:27:34 +0000
commitd07b4081cd7e1771e99ea4b4012852fb296a057e (patch)
treeace7f8627b4eb51089451bdf9ee28d4fb6d3c6d2 /share/common/msapi/helper.py
parent1f1588b0fe00d4c9dc6c5bf5ad2105f00eec42d0 (diff)
parentfb6c49e4131e44e145ab60fce7dc355d69763158 (diff)
Merge "Add heatbridge handler"
Diffstat (limited to 'share/common/msapi/helper.py')
-rw-r--r--share/common/msapi/helper.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/share/common/msapi/helper.py b/share/common/msapi/helper.py
new file mode 100644
index 00000000..0c27990b
--- /dev/null
+++ b/share/common/msapi/helper.py
@@ -0,0 +1,59 @@
+# Copyright (c) 2017-2018 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+import json
+import logging
+import re
+
+from common.exceptions import VimDriverNewtonException
+from common.utils import restcall
+
+
+logger = logging.getLogger(__name__)
+
+
+class Helper(object):
+
+ @staticmethod
+ def MultiCloudIdentityHelper(multicloud_api_prefix, cloud_owner, cloud_region_id, uri, data={}, header=''):
+ auth_api_url_format = "/{f_cloudowner}/{f_cloudregionid}/identity{f_uri}"
+ auth_api_url = auth_api_url_format.format(f_cloudowner=cloud_owner,
+ f_cloudregionid=cloud_region_id,
+ f_uri=uri)
+ extra_headers = header
+ ret = restcall._call_req(multicloud_api_prefix, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(data))
+ if ret[0] > 0 or ret[1] is None:
+ logger.critical("call url %s failed with status %s" % (multicloud_api_prefix+auth_api_url, ret[0]))
+ return None
+
+ resp = json.JSONDecoder().decode(ret[1])
+ return resp
+
+ # The consumer of this api must be attaching to the same management network of multicloud,
+ # The constraints comes from the returned catalog endpoint url e.g. "http://10.0.14.1:80/api/multicloud-titaniumcloud/v0/pod25_RegionOne/identity/v3"
+ @staticmethod
+ def MultiCloudServiceHelper(cloud_owner, cloud_region_id, v2_token_resp_json, service_type, uri, data=None, method="GET",):
+ # get endpoint from token response
+ token = v2_token_resp_json["access"]["token"]["id"]
+ catalogs = v2_token_resp_json["access"]["serviceCatalog"]
+ for catalog in catalogs:
+ if catalog['type'] == service_type:
+ # now we have endpoint
+ endpoint_url = catalog['endpoints'][0]['publicURL']
+ extra_headers = {'X-Auth-Token': token}
+ ret = restcall._call_req(endpoint_url, "", "", 0, uri, method, extra_headers, json.dumps(data) if data else "")
+ if ret[0] > 0 or ret[1] is None:
+ logger.critical("call url %s failed with status %s" % (endpoint_url+uri, ret[0]))
+ return None
+
+ content = json.JSONDecoder().decode(ret[1])
+ return content
+ pass