summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eteutils/OpenstackLibrary.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/eteutils/OpenstackLibrary.py b/eteutils/OpenstackLibrary.py
index 99aba87..1be497c 100644
--- a/eteutils/OpenstackLibrary.py
+++ b/eteutils/OpenstackLibrary.py
@@ -12,10 +12,13 @@ class OpenstackLibrary:
self._cache = robot.utils.ConnectionCache('No connections created')
self.builtin = BuiltIn()
- def save_openstack_auth(self, alias, response):
+ def save_openstack_auth(self, alias, response,token, version):
"""Save Openstack Auth takes in an openstack auth response and saves it to allow easy retrival of token and service catalog"""
self.builtin.log('Creating connection: %s' % alias, 'DEBUG')
- self._cache.register(response, alias=alias)
+ jsonResponse = json.loads(response);
+ jsonResponse['auth_token'] = token
+ jsonResponse['keystone_api_version'] = version
+ self._cache.register(jsonResponse, alias=alias)
def get_openstack_token(self, alias):
"""Get Openstack auth token from the current alias"""
@@ -24,7 +27,10 @@ class OpenstackLibrary:
jsonResponse = json.loads(response);
else:
jsonResponse = response;
- return jsonResponse['access']['token']['id']
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ return jsonResponse['access']['token']['id']
+ else:
+ return jsonResponse['auth_token']
def get_openstack_catalog(self, alias):
"""Get Openstack service catalog from the current alias"""
@@ -33,7 +39,11 @@ class OpenstackLibrary:
jsonResponse = json.loads(response);
else:
jsonResponse = response;
- return jsonResponse['access']['serviceCatalog']
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ return jsonResponse['access']['serviceCatalog']
+ else:
+ return jsonResponse['token']['catalog']
+
def get_current_openstack_tenant(self, alias):
"""Get Openstack tenant from the current alias"""
@@ -42,7 +52,10 @@ class OpenstackLibrary:
jsonResponse = json.loads(response);
else:
jsonResponse = response;
- return jsonResponse['access']['token']['tenant']
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ return jsonResponse['access']['token']['tenant']
+ else:
+ return jsonResponse['token']['project']
def get_current_openstack_tenant_id(self, alias):
"""Get Openstack tenant id from the current alias"""
@@ -57,7 +70,11 @@ class OpenstackLibrary:
else:
jsonResponse = response;
regions = [];
- for catalogEntry in jsonResponse['access']['serviceCatalog']:
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ resp = jsonResponse['access']['serviceCatalog']
+ else:
+ resp = jsonResponse['token']['catalog']
+ for catalogEntry in resp:
listOfEndpoints = catalogEntry['endpoints'];
for endpoint in listOfEndpoints:
if 'region'in endpoint:
@@ -73,7 +90,11 @@ class OpenstackLibrary:
else:
jsonResponse = response;
endPoint = None;
- for catalogEntry in jsonResponse['access']['serviceCatalog']:
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ resp = jsonResponse['access']['serviceCatalog']
+ else:
+ resp = jsonResponse['token']['catalog']
+ for catalogEntry in resp:
if self.__determine_match(catalogEntry['type'], servicetype):
listOfEndpoints = catalogEntry['endpoints'];
# filter out non matching regions if provided
@@ -83,8 +104,13 @@ class OpenstackLibrary:
# WindRiver does not return the tenantId on the endpoint in this case.
if tenant_id is not None:
listOfEndpoints[:] = [y for y in listOfEndpoints if self.__determine_match(y['tenantId'], tenant_id)];
+ if jsonResponse['keystone_api_version'] == 'v3':
+ listOfEndpoints[:] = [z for z in listOfEndpoints if self.__determine_match(z['interface'], 'public')];
if len(listOfEndpoints) > 0:
- endPoint = listOfEndpoints[0]['publicURL'];
+ if jsonResponse['keystone_api_version'] == 'v2.0':
+ endPoint = listOfEndpoints[0]['publicURL'];
+ else:
+ endPoint = listOfEndpoints[0]['url'];
if endPoint == None:
self.builtin.should_not_be_empty("", "Service Endpoint Url should not be empty")
return endPoint;