Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_04_create_role(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
role_name = self.config['vcd']['role_name']
org.create_role(role_name, 'test description', ('Disk: View Properties',))
role_record = org.get_role_record(role_name)
assert self.config['vcd']['role_name'] == role_record.get('name')
def test_09_add_rights_to_Role(self):
org_in_use = self.config['vcd']['org_in_use']
org = Org(self.client, href=self.client.get_org_by_name(org_in_use).get('href'))
role_name = self.config['vcd']['role_name']
right_name = self.config['vcd']['right_name']
role_record = org.get_role_record(role_name)
role = Role(self.client, href=role_record.get('href'))
updated_role_resource = role.add_rights([right_name], org)
success = False
if hasattr(updated_role_resource, 'RightReferences') and \
hasattr(updated_role_resource.RightReferences, 'RightReference'):
for right in updated_role_resource.RightReferences.RightReference:
if right.get('name') == right_name:
success = True
break
assert success
def test_07_link_role_to_template(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
role_name = self.config['vcd']['role_name']
role_record = org.get_role_record(role_name)
role = Role(self.client, href=role_record.get('href'))
role.link()
def test_050_change_idisk_owner(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, resource=vdc_resource)
user_resource = org.get_user(
self.config['vcd']['idisk_new_owner_name'])
vdc.change_disk_owner(name=self.config['vcd']['idisk_name'],
user_href=user_resource.get('href'))
disk_resource = vdc.get_disk(self.config['vcd']['idisk_name'])
new_user = disk_resource.Owner.User.get('name')
assert self.config['vcd']['idisk_new_owner_name'] == new_user
represents the new vApp.
:rtype: lxml.objectify.ObjectifiedElement
"""
self.get_resource()
# Get hold of the template
media_type = EntityType.ORG.value
if self.is_admin:
media_type = EntityType.ADMIN_ORG.value
org_link = find_link(self.resource, RelationType.UP,
media_type,
fail_if_absent=False)
if org_link is not None:
org = Org(self.client, href=org_link.href)
else:
org_resource = self.client.get_org()
org = Org(self.client, resource=org_resource)
catalog_item = org.get_catalog_item(catalog, template)
template_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
# If network is not specified by user then default to
# vApp network name specified in the template
is_template_vapp_network = False
template_networks = template_resource.xpath(
'//ovf:NetworkSection/ovf:Network',
namespaces={'ovf': NSMAP['ovf']})
# assert len(template_networks) > 0
if len(template_networks) > 0:
def create(ctx, name, pvdc_name, network_pool_name, allocation_model, sp_name,
sp_limit, description, cpu_allocated, cpu_limit):
try:
restore_session(ctx)
client = ctx.obj['client']
in_use_org_href = ctx.obj['profiles'].get('org_href')
org = Org(client, in_use_org_href)
storage_profiles = [{
'name': sp_name,
'enabled': True,
'units': 'MB',
'limit': sp_limit,
'default': True
}]
vdc_resource = org.create_org_vdc(
name,
pvdc_name,
network_pool_name=network_pool_name,
description=description,
allocation_model=allocation_model,
cpu_allocated=cpu_allocated,
cpu_limit=cpu_limit,
storage_profiles=storage_profiles,
def get_source_resource(self):
source_catalog_name = self.params.get('source_catalog_name')
source_template_name = self.params.get('source_template_name')
source_vdc = self.params.get('source_vdc')
source_vapp = self.params.get('source_vapp')
org_resource = Org(self.client, resource=self.client.get_org())
source_vapp_resource = None
if source_vapp:
source_vdc_resource = VDC(
self.client, resource=org_resource.get_vdc(source_vdc))
source_vapp_resource_href = source_vdc_resource.get_resource_href(
name=source_vapp, entity_type=EntityType.VAPP)
source_vapp_resource = self.client.get_resource(
source_vapp_resource_href)
if source_catalog_name:
catalog_item = org_resource.get_catalog_item(
source_catalog_name, source_template_name)
source_vapp_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
:param pyvcloud.vcd.client.Client client:
:param str org_name: which org to use. If None, uses currently logged-in
org from @client.
:return: pyvcloud Org object
:rtype: pyvcloud.vcd.org.Org
:raises EntityNotFoundException: if the org could not be found.
"""
if not org_name:
org_sparse_resource = client.get_org()
org = vcd_org.Org(client, href=org_sparse_resource.get('href'))
else:
org = vcd_org.Org(client, resource=client.get_org_by_name(org_name))
return org
if list_pks_plans and not op_ctx.client.is_sysadmin():
raise e.UnauthorizedRequestError(
'Operation denied. Enterprise PKS plans visible only '
'to System Administrators.')
# Ideally this should be extracted out to ovdc_utils, but the mandatory
# usage of sysadmin client along with a potentially non-sysadmin client
# means that the function signature require both tenant client and
# sysadmin client, which is very awkward
if op_ctx.client.is_sysadmin():
org_resource_list = op_ctx.client.get_org_list()
else:
org_resource_list = list(op_ctx.client.get_org())
ovdcs = []
for org_resource in org_resource_list:
org = vcd_org.Org(op_ctx.client, resource=org_resource)
for vdc_sparse in org.list_vdcs():
ovdc_name = vdc_sparse['name']
org_name = org.get_name()
k8s_metadata = ovdc_utils.get_ovdc_k8s_provider_metadata(
op_ctx.sysadmin_client,
ovdc_name=ovdc_name,
org_name=org_name)
k8s_provider = k8s_metadata[K8S_PROVIDER_KEY]
ovdc_dict = {
'name': ovdc_name,
'org': org_name,
'k8s provider': k8s_provider
}
if list_pks_plans:
def delete_catalog_or_item(ctx, catalog_name, item_name):
try:
restore_session(ctx)
client = ctx.obj['client']
in_use_org_href = ctx.obj['profiles'].get('org_href')
org = Org(client, in_use_org_href)
if item_name is None:
org.delete_catalog(catalog_name)
stdout('Catalog deleted.', ctx)
else:
org.delete_catalog_item(catalog_name, item_name)
stdout('Item deleted.', ctx)
except Exception as e:
stderr(e, ctx)