本文整理汇总了Python中tenant.Tenant类的典型用法代码示例。如果您正苦于以下问题:Python Tenant类的具体用法?Python Tenant怎么用?Python Tenant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tenant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: varray_list
def varray_list(self, vdcname=None, tenant=None):
'''
Returns all the varrays in a vdc
Parameters:
Returns:
JSON payload of varray list
'''
vdcuri = None
vdcrestapi = None
if(tenant != None):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
tenanturi = tenant_obj.tenant_query(tenant)
if(vdcname != None):
vdcrestapi = VirtualArray.URI_VIRTUALARRAY_BY_VDC_ID_AND_TENANT_ID.format(vdcname, tenanturi)
else:
vdcrestapi = VirtualArray.URI_VIRTUALARRAY_BY_TENANT_ID.format(tenanturi)
else:
if(vdcname != None):
vdcrestapi = VirtualArray.URI_VIRTUALARRAY_BY_VDC_ID.format(vdcname)
else:
vdcrestapi = VirtualArray.URI_VIRTUALARRAY
(s, h) = common.service_json_request(
self.__ipAddr, self.__port, "GET",
vdcrestapi, None)
o = common.json_decode(s)
returnlst = []
for item in o['varray']:
returnlst.append(item['id'])
return returnlst
示例2: project_query
def project_query(self, name):
'''
Retrieves UUID of project based on its name
Parameters:
name: name of project
Returns: UUID of project
Throws:
SOSError - when project name is not found
'''
if (common.is_uri(name)):
return name
(tenant_name, project_name) = common.get_parent_child_from_xpath(name)
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
try:
tenant_uri = tenant_obj.tenant_query(tenant_name)
projects = self.project_list(tenant_uri)
if(projects and len(projects) > 0):
for project in projects:
if (project):
project_detail = self.project_show_by_uri(project['id'])
if(project_detail and project_detail['name'] == project_name):
return project_detail['id']
raise SOSError(SOSError.NOT_FOUND_ERR, 'Project: ' + project_name + ' not found')
except SOSError as e:
raise e
示例3: keypool_show
def keypool_show(self, keypool, tenant, uid, secret):
'''
show keypool
parameters:
keypool: label of the keypool
tenant: tenant name
uid: user id
secret: secret key
Returns:
JSON payload response
'''
#uri = self.keypool_query(label)
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
try:
if(apitype == 's3'):
return s3_bucket_show(namespace, keypool, uid, secretkey)
elif(apitype == 'swift'):
return swift_container_show(namespace, keypool, uid, secretkey)
elif(apitype == 'atmos'):
return atmos_subtenant_show(namespace, keypool, uid, secretkey)
else:
raise SOSError(SOSError.VALUE_ERR,
"Wrong API type " + apitype + " specified")
except SOSError as e:
raise e
示例4: cluster_create
def cluster_create(self, label, tenant, datacenter, vcenter):
tenant_obj = Tenant(self.__ipAddr, self.__port)
vdatacenterobj = VcenterDatacenter(self.__ipAddr, self.__port)
if(tenant is None):
tenant_uri = tenant_obj.tenant_getid()
else:
tenant_uri = tenant_obj.tenant_query(tenant)
parms = {'name': label}
# datacenter
if(datacenter):
# on failure, query raise exception
parms['vcenter_data_center'] = \
vdatacenterobj.vcenterdatacenter_query(
datacenter, vcenter, tenant)
body = json.dumps(parms)
(s, h) = common.service_json_request(
self.__ipAddr, self.__port,
"POST",
Cluster.URI_TENANTS_CLUSTERS.format(tenant_uri),
body)
o = common.json_decode(s)
示例5: cluster_create
def cluster_create(self, label, tenant, project, datacenter, vcenter):
tenant_obj = Tenant(self.__ipAddr, self.__port)
vdatacenterobj = VcenterDatacenter(self.__ipAddr, self.__port)
projectobj = Project(self.__ipAddr, self.__port)
if(tenant == None):
tenant_uri = tenant_obj.tenant_getid()
else:
tenant_uri = tenant_obj.tenant_query(tenant)
parms = { 'name' : label
}
#project
if(project):
if(tenant):
projectname = tenant + "/" + project
else:
projectname = "" + "/" + project
#on failure, query raise exception
parms['project'] = projectobj.project_query(projectname)
#datacenter
if(datacenter):
#on failure, query raise exception
parms['vcenter_data_center'] = vdatacenterobj.vcenterdatacenter_query(datacenter, vcenter)
body = json.dumps(parms)
(s, h) = common.service_json_request(self.__ipAddr, self.__port,
"POST",
Cluster.URI_TENANTS_CLUSTERS.format(tenant_uri),
body)
o = common.json_decode(s)
示例6: keypool_update
def keypool_update(
self, keypool, tenant, versioning, apitype, uid, secret):
'''
update keypool versioning
parameters:
keypool: label of the keypool
project: project name
tenant: tenant name
uid: user id
secret: secret key
Returns:
JSON payload response
'''
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
try:
if(apitype == 's3'):
return s3_bucket_update(
namespace, keypool, versioning, uid, secretkey)
else:
raise SOSError(SOSError.VALUE_ERR,
"Wrong API type " + apitype + " specified")
except SOSError as e:
raise e
示例7: varray_disallow_tenant
def varray_disallow_tenant(self, varray, tenant):
'''
Makes a REST API call to retrieve details of a varray
based on its UUID
'''
uri = self.varray_query(varray)
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
tenanturi = tenant_obj.tenant_query(tenant)
parms = {
'remove': [{
'privilege': ['USE'],
'tenant': tenanturi,
}]
}
body = json.dumps(parms)
(s, h) = common.service_json_request(
self.__ipAddr, self.__port, "PUT",
self.URI_VIRTUALARRAY_ACLS.format(uri),
body)
return s
示例8: key_write
def key_write(self, key, filepath , keypool, tenant, apitype, uid, secret, type):
'''
write a key
parameters:
key: key
keypool: keypool
tenant: tenant name
value: value
apitype: api to be used
uid: user id
secret: secret
Returns:
JSON payload response
'''
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
if(apitype == 's3'):
s3_key_write(namespace, keypool, key, filepath, uid, secret )
elif(apitype == 'swift'):
swift_object_write(namespace, keypool, key, filepath, uid, secret )
elif(apitype == 'atmos'):
atmos_object_write(namespace, keypool, key, filepath, uid, secret, type )
else:
raise SOSError(SOSError.VALUE_ERR,
"Wrong API type " + apitype + " specified")
示例9: keypool_delete
def keypool_delete(self, keypool, tenant, uid, secret):
'''Makes a REST API call to delete a keypool by its name,
project and tenant
'''
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
try:
if(apitype == 's3'):
return s3_bucket_delete(namespace, keypool, uid, secretkey)
elif(apitype == 'swift'):
return swift_container_delete(namespace,
keypool,
uid,
secretkey)
elif(apitype == 'atmos'):
return atmos_subtenant_delete(namespace,
keypool,
uid,
secretkey)
else:
raise SOSError(SOSError.VALUE_ERR,
"Wrong API type " + apitype + " specified")
except SOSError as e:
raise e
示例10: key_delete
def key_delete(self, key, keypool, tenant, apitype, version, uid, secret):
'''
Makes a REST API call to delete a key by its name
Parameters:
key: label of the key
keypool: label of the keypool
project: project name
tenant: tenant name
apitype: api to be used
uid: user id
secret: secret
Returns:
JSON payload of key list
'''
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
if(apitype == 's3'):
s3_key_delete(namespace, keypool, key, version, uid, secret )
elif(apitype == 'swift'):
swift_object_delete(namespace, keypool, key, version, uid, secret )
elif(apitype == 'atmos'):
atmos_object_delete(namespace, keypool, key, uid, secret )
else:
raise SOSError(SOSError.VALUE_ERR,
"Wrong API type " + apitype + " specified")
示例11: key_list_versions
def key_list_versions(self, keypool, key, tenant, apitype, uid, secret):
'''
Returns versions of the key`
Parameters:
key: label of the key
keypool: label of the keypool
project: project name
tenant: tenant name
apitype: api to be used
uid: user id
secret: secret
Returns:
JSON payload of key list
'''
if (not common.is_uri(tenant)):
from tenant import Tenant
tenant_obj = Tenant(self.__ipAddr, self.__port)
namespace = tenant_obj.namespace_get(tenant)
if(apitype == 's3'):
s3_key_list_versions(namespace, keypool, key, uid, secret )
elif ( (apitype =='swift') or (apitype=='atmos')) :
raise SOSError(SOSError.NOT_FOUND_ERR,
"Versioning not available with API type " + apitype)
else:
raise SOSError(SOSError.VALUE_ERR,
"Wroing API type " + apitype + " specified")
示例12: add_or_remove_vcenter_acls
def add_or_remove_vcenter_acls(self, vcenter_name, tenants, operation):
vcenter_uri = self.vcenter_query(vcenter_name, VCenter.VCENTERS_FROM_ALL_TENANTS)
tenants_array = []
tenants_array = tenants.split(',')
from tenant import Tenant
obj = Tenant(self.__ipAddr, self.__port)
acl_entries = []
for tenant in tenants_array:
acl_entry = dict()
acl_entry['privilege'] = ['USE']
acl_entry['tenant'] = str(obj.tenant_query(tenant))
acl_entries.append(acl_entry)
request = {operation: acl_entries}
body = json.dumps(request)
(s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT",
VCenter.URI_VCENTER_ACL.format(vcenter_uri), body)
o = common.json_decode(s)
return o
示例13: get_tenant_id
def get_tenant_id(self, tenantName):
"""
Fetch the tenant id
"""
tenantObj = Tenant(self.__ipAddr, self.__port)
tenantId = tenantObj.get_tenant_by_name(tenantName)
return tenantId
示例14: get_tenant_uri_from_name
def get_tenant_uri_from_name(self, tenantname):
if (tenantname is None or
tenantname == "" or
tenantname.lower() == VCenter.VCENTERS_FROM_ALL_TENANTS.lower() or
tenantname.lower() == VCenter.VCENTERS_WITH_NO_TENANTS.lower()):
tenanturi = tenantname
else:
from tenant import Tenant
obj = Tenant(self.__ipAddr, self.__port)
tenanturi = obj.tenant_query(tenantname)
return tenanturi
示例15: create
def create(
self,
tenant,
policyname,
policytype,
schedulefrequency,
schedulerepeat,
scheduletime,
scheddom,
scheddow,
expiretype,
expirevalue,
):
tenant_obj = Tenant(self.__ipAddr, self.__port)
tenant_uri = tenant_obj.tenant_query(tenant)
schedule = dict()
schedule = {
"schedule_frequency": schedulefrequency,
"schedule_repeat": schedulerepeat,
"schedule_time": scheduletime,
}
if schedulefrequency == "weeks":
schedule["schedule_day_of_week"] = scheddow
elif schedulefrequency == "months":
schedule["schedule_day_of_month"] = scheddom
parms = {"policy_type": policytype, "policy_name": policyname}
body = None
parms["schedule"] = schedule
snapshot_expire = dict()
if expiretype or expirevalue:
snapshot_expire = {"expire_type": expiretype, "expire_value": expirevalue}
parms["snapshot_expire"] = snapshot_expire
body = json.dumps(parms)
(s, h) = common.service_json_request(
self.__ipAddr,
self.__port,
"POST",
Schedulepolicy.URI_SNAPSHOT_SCHEDULE_POLICY_CREATE.format(tenant_uri),
body,
)
return