-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathconversion_util.py
30 lines (30 loc) · 1.03 KB
/
conversion_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def get_obj_url_uuid(path,unique_id):
url = path + "-" +unique_id
uuid = url.split('/')[-1]
return url,uuid
def get_tenant_ref(name):
tenant="admin"
if name and name.startswith('/'):
parts = name.split('/', 2)
tenant = parts[1]
if not parts[2]:
LOG.warning('Invalid tenant ref : %s' % name)
elif name and '/' in name:
parts = name.split('/')
# Changed the index to get the tenant and name in case of
# prefixed name
tenant = parts[-2]
if tenant.lower() == 'common':
tenant = 'admin'
if '/' in name:
name = name.split('/')[1]
if ' ' in tenant:
tenant = tenant.split(' ')[-1]
return tenant,name
def get_object_ref( object_name, object_type, tenant='admin',
cloud_name='Default-Cloud', prefix=None):
if object_type == 'tenant':
ref = '/api/tenant/?name=%s' %(object_name)
elif object_type == 'cloud':
ref = '/api/%s/?tenant=admin&name=%s' % (object_type, object_name)
return ref