Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 2e8b7f4

Browse files
committed
Added keystone constructor with tenantid
Get the list of snapshots in cinder
1 parent 5b6c741 commit 2e8b7f4

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

cinder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ def get_all_volumes(self, tenant_id):
4444
data = None
4545
return data
4646

47+
def get_all_snapshots(self, tenant_id):
48+
headers = {"X-Auth-Token": "%s" % self.token_, "Content-Type": "application/json"}
49+
r = requests.get("%s/%s/snapshots" % (self.url_, tenant_id), headers=headers, verify=False)
50+
if r.status_code == 200:
51+
data = r.json()
52+
if 'error' in data:
53+
raise Exception(data['error']['message'])
54+
else:
55+
data = None
56+
return data
57+
4758
def get_all_global_volumes(self, tenant_id):
4859
headers = {"X-Auth-Token": "%s" % self.token_, "Content-Type": "application/json"}
4960
r = requests.get("%s/%s/volumes/detail?all_tenants=1" % (self.url_, tenant_id), headers=headers, verify=False)

keystone.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ class Keystone:
3333
credentials_ = None
3434
tenantId_ = None
3535

36-
def __init__(self, url, username, password, tenant):
36+
def __init__(self, url, username, password, tenant, tenantid = None):
3737
self.url_ = url
3838
self.username_ = username
3939
self.password_ = password
40-
self.tenant_ = tenant
41-
credentials = json.dumps({"auth":{"passwordCredentials": {"username": "%s" % self.username_ , "password": "%s" % self.password_}, "tenantName": "%s" % self.tenant_}})
40+
if tenantid is None:
41+
self.tenant_ = tenant
42+
credentials = json.dumps({"auth":{"passwordCredentials": {"username": "%s" % self.username_ , "password": "%s" % self.password_}, "tenantName": "%s" % self.tenant_}})
43+
else:
44+
self.tenantId_ = tenantid
45+
credentials = json.dumps({"auth":{"passwordCredentials": {"username": "%s" % self.username_ , "password": "%s" % self.password_}, "tenantId": "%s" % self.tenantId_}})
4246
headers = {"Content-Type": "application/json"}
4347
r = requests.post("%s/tokens" % self.url_, headers=headers, data=credentials, verify=False)
4448
if r.status_code==200:
4549
self.credentials_ = r.json()
4650
self.token_ = self.credentials_['access']['token']['id']
4751
self.tenantId_ = self.credentials_['access']['token']['tenant']['id']
48-
52+
self.tenant_ = self.credentials_['access']['token']['tenant']['name']
53+
4954
def getToken(self):
5055
if self.token_==None:
5156
return None

0 commit comments

Comments
 (0)