Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete_ipsec_vpn(self):
"""Delete IP sec Vpn."""
end_points = self.end_point.split('-')
local_ip = end_points[0]
peer_ip = end_points[1]
ipsec_vpn = self.resource
vpn_sites = ipsec_vpn.sites
for site in vpn_sites.site:
if site.localIp == local_ip and site.peerIp == peer_ip:
vpn_sites.remove(site)
break
self.client.put_resource(self.href,
ipsec_vpn,
EntityType.DEFAULT_CONTENT_TYPE.value)
above belongs to.
:param str task_href: href of the task.
:param str error_message: represents error information from a failed
task.
:param str stack_trace: stack trace of the error message from a
failed task.
:return: an object containing EntityType.TASK XML data representing the
updated task.
:rtype: lxml.objectify.ObjectifiedElement
"""
t = E.Task(
status=status,
serviceNamespace=namespace,
type=EntityType.TASK.value,
operation=operation,
operationName=operation_name,
name='task')
t.append(E.Owner(href=owner_href, name=owner_name, type=owner_type))
if error_message is not None:
t.append(
E.Error(
stackTrace=stack_trace,
majorErrorCode='500',
message=error_message,
minorErrorCode='INTERNAL_SERVER_ERROR'))
t.append(
E.User(href=user_href, name=user_name, type=EntityType.USER.value))
if progress is not None:
t.append(E.Progress(progress))
t.append(E.Details(details))
def get_metadata(self):
"""Fetch metadata of the vApp.
:return: an object containing EntityType.METADATA XML data which
represents the metadata associated with the vApp.
:rtype: lxml.objectify.ObjectifiedElement
"""
self.get_resource()
return self.client.get_linked_resource(
self.resource, RelationType.DOWN, EntityType.METADATA.value)
def list_connected_vapps(self, filter=None):
"""List connected vApps.
:param str filter: filter to fetch the selected vApp, e.g., name==vApp*
:return: list of connected vApps
:rtype: list
"""
vapp_name_list = []
if (self.client.is_sysadmin()):
vdc = self.client.get_linked_resource(self.get_resource(),
RelationType.UP,
EntityType.VDC_ADMIN.value)
else:
vdc = self.client.get_linked_resource(
self.get_resource(), RelationType.UP, EntityType.VDC.value)
for entity in vdc.ResourceEntities.ResourceEntity:
if entity.get('type') == EntityType.VAPP.value:
vapp = self.client.get_resource(entity.get('href'))
if hasattr(vapp, 'NetworkConfigSection'):
network_name = vapp.NetworkConfigSection.NetworkConfig.get(
'networkName')
if network_name == self.name:
vapp_name_list.append({
'Name': vapp.get('name'),
'Status': VAppPowerStatus(vapp.get('status')).name
})
return vapp_name_list
' Sizing Policy is not present')
# Remove VdcComputePolicy from request as we know that we are dealing
# with API version >= 33.0
if hasattr(vm_resource, 'VdcComputePolicy'):
vm_resource.remove(vm_resource.VdcComputePolicy)
vm_resource.ComputePolicy.remove(
vm_resource.ComputePolicy.VmPlacementPolicy)
if hasattr(vm_resource.ComputePolicy, 'VmPlacementPolicyFinal'):
vm_resource.ComputePolicy.remove(
vm_resource.ComputePolicy.VmPlacementPolicyFinal)
reconfigure_vm_link = find_link(self.resource,
RelationType.RECONFIGURE_VM,
EntityType.VM.value)
return self.client.post_resource(reconfigure_vm_link.href,
vm_resource,
EntityType.VM.value)
E.Error(
stackTrace=stack_trace,
majorErrorCode='500',
message=error_message,
minorErrorCode='INTERNAL_SERVER_ERROR'))
t.append(
E.User(href=user_href, name=user_name, type=EntityType.USER.value))
if progress is not None:
t.append(E.Progress(progress))
t.append(E.Details(details))
if task_href is None:
org_resource = self.client.get_resource(org_href)
link = find_link(org_resource, RelationType.DOWN,
EntityType.TASKS_LIST.value)
return self.client.post_resource(link.href, t,
EntityType.TASK.value)
else:
return self.client.put_resource(task_href, t,
EntityType.TASK.value)
def get_all_metadata_from_catalog_item(self, catalog_name,
item_name):
"""Fetch all metadata entries for the given catalog item.
:param str catalog_name: name of the catalog that contains the item.
:param str item_name: name of the catalog item whose metadata needs
to be retrieved.
:return: object containing Metadata Entries
:rtype: lxml.objectify.ObjectifiedElement
"""
catalog_item = self.get_catalog_item(catalog_name, item_name)
return self.client.get_linked_resource(
catalog_item, rel=RelationType.DOWN,
media_type=EntityType.METADATA.value)
def process_request_delete_pv(self, cluster_name, cluster_id, vapp, moid, json_request):
vdc_resource = self.client_sysadmin.get_linked_resource(vapp.resource, RelationType.UP, EntityType.VDC.value)
vdc = VDC(self.client_sysadmin, resource=vdc_resource)
disk_name_orig = json_request['spec']['claimRef']['name']
disk_uid = json_request['spec']['claimRef']['uid']
disk_name = '%s-%s' % (cluster_name, disk_name_orig)
disk_resource = vdc.get_disk(disk_name)
vm_name = disk_resource.attached_vms.VmReference.get('name')
vm_href = disk_resource.attached_vms.VmReference.get('href')
vm_resource = self.client_sysadmin.get_resource(vm_href)
vapp_resource = self.client_sysadmin.get_linked_resource(vm_resource, RelationType.UP, EntityType.VAPP.value)
vapp_name = vapp_resource.get('name')
LOGGER.info('PV %s, deleting ind. disk: %s, vapp: %s, vm: %s, pvc-uid: %s' % (disk_name_orig, disk_name, vapp_name, vm_name, disk_uid))
disk_id = disk_resource.get('id')
def get_vdc_references(self):
"""List all provider vdc references.
:return: an object containing VMWProviderVdcReference XML element that
refers to provider vdcs.
:rtype: lxml.objectify.StringElement
"""
if self.resource is None:
self.resource = self.client.get_resource(self.href)
return self.client.get_linked_resource(
self.resource, RelationType.DOWN, EntityType.VDC_REFERENCES.value)
'application/vnd.vmware.admin.vmwStorageProfiles+xml'
vApp_Network = 'application/vnd.vmware.vcloud.vAppNetwork+xml'
class QueryResultFormat(Enum):
RECORDS = ('application/vnd.vmware.vcloud.query.records+xml', 'records')
ID_RECORDS = ('application/vnd.vmware.vcloud.query.idrecords+xml',
'idrecords')
REFERENCES = ('application/vnd.vmware.vcloud.query.references+xml',
'references')
class _WellKnownEndpoint(Enum):
LOGGED_IN_ORG = (RelationType.DOWN, EntityType.ORG.value)
ORG_VDC = (RelationType.DOWN, EntityType.VDC.value)
ORG_NETWORK = (RelationType.DOWN, EntityType.ORG_NETWORK.value)
ORG_CATALOG = (RelationType.DOWN, EntityType.CATALOG.value)
QUERY_LIST = (RelationType.DOWN, EntityType.QUERY_LIST.value)
ADMIN = (RelationType.DOWN, EntityType.ADMIN.value)
API_EXTENSIBILITY = (RelationType.DOWN_EXTENSIBILITY,
EntityType.API_EXTENSIBILITY.value)
EXTENSION = (RelationType.DOWN, EntityType.EXTENSION.value)
ORG_LIST = (RelationType.DOWN, EntityType.ORG_LIST.value)
SNAPSHOT_CREATE = (RelationType.SNAPSHOT_CREATE,
EntityType.SNAPSHOT_CREATE.value)
OPENAPI = (RelationType.OPENAPI, EntityType.JSON)
class FenceMode(Enum):
ISOLATED = 'isolated'
DIRECT = 'direct'
BRIDGED = 'bridged'