How to use the pyvcloud.vcd.client.RelationType function in pyvcloud

To help you get started, we’ve selected a few pyvcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmware / vcd-cli / system_tests / vm_tests.py View on Github external
vm_resource = vapp.get_vm(VmTest._test_vapp_vmtools_vm_name)
        VmTest._test_vapp_vmtools_vm_href = vm_resource.get('href')
        self.assertIsNotNone(VmTest._test_vapp_vmtools_vm_href)
        temp_name = config['vcd']['default_template_file_name']
        VmTest._test_vapp_href = create_customized_vapp_from_template(
            client=VmTest._client,
            vdc=vdc1,
            name=VmTest._vapp_name,
            catalog_name=catalog_name,
            template_name=temp_name)
        self.assertIsNotNone(VmTest._test_vapp_href)

        VmTest._sys_admin_client = Environment.get_sys_admin_client()
        resource = VmTest._sys_admin_client.get_extension()
        result = VmTest._sys_admin_client.get_linked_resource(
            resource, RelationType.DOWN,
            EntityType.DATASTORE_REFERENCES.value)
        if hasattr(result, '{' + NSMAP['vcloud'] + '}Reference'):
            for reference in result['{' + NSMAP['vcloud'] + '}Reference']:
                datastore_id = reference.get('id')
                VmTest._datastore_id = datastore_id.split(':')[3]
                break
        self.assertIsNotNone(VmTest._datastore_id)
github vmware / pyvcloud / system_tests / pvdc_tests.py View on Github external
logger = Environment.get_default_logger()
        TestPVDC._sys_admin_client = Environment.get_sys_admin_client()
        org = Environment.get_test_org(TestPVDC._sys_admin_client)
        platform = Platform(TestPVDC._sys_admin_client)

        vdc_name = TestPVDC._new_vdc_name
        pvdc_name = Environment.get_test_pvdc_name()
        provider_vdc = platform.get_ref_by_name(ResourceType.PROVIDER_VDC,
                                                pvdc_name)
        pvdc_ext_href = get_admin_extension_href(provider_vdc.get('href'))
        pvdc_ext_resource = TestPVDC._sys_admin_client.get_resource(
            pvdc_ext_href)
        vc_name = pvdc_ext_resource.VimServer.get('name')
        res_pools_in_pvdc = TestPVDC._sys_admin_client.get_linked_resource(
            resource=pvdc_ext_resource,
            rel=RelationType.DOWN,
            media_type=EntityType.VMW_PROVIDER_VDC_RESOURCE_POOL_SET.value)
        if hasattr(res_pools_in_pvdc,
                   '{' + NSMAP['vmext'] + '}VMWProviderVdcResourcePool'):
            src_respool = res_pools_in_pvdc.VMWProviderVdcResourcePool[0]
        name_filter = ('vcName', vc_name)
        query = TestPVDC._sys_admin_client.get_typed_query(
            ResourceType.RESOURCE_POOL.value,
            query_result_format=QueryResultFormat.RECORDS,
            equality_filter=name_filter)
        res_pools_in_use = {}
        for res_pool in list(query.execute()):
            res_pools_in_use[res_pool.get('moref')] = res_pool.get('name')
        source_respool_name = res_pools_in_use[
            src_respool.ResourcePoolVimObjectRef.MoRef]
        TestPVDC._source_resource_pool = source_respool_name
github vmware / pyvcloud / pyvcloud / vcd / api_extension.py View on Github external
"""
        params = E_VMEXT.Service({'name': name})
        if description is not None:
            params.append(E.Description(description))
        params.append(E_VMEXT.Namespace(namespace))
        params.append(E_VMEXT.Enabled('true'))
        params.append(E_VMEXT.RoutingKey(routing_key))
        params.append(E_VMEXT.Exchange(exchange))
        filters = E_VMEXT.ApiFilters()
        for pattern in patterns:
            filters.append(
                E_VMEXT.ApiFilter(E_VMEXT.UrlPattern(pattern.strip())))
        params.append(filters)
        ext = self.client.get_extension()
        ext_services = self.client.get_linked_resource(
            ext, RelationType.DOWN, EntityType.EXTENSION_SERVICES.value)
        return self.client.post_linked_resource(ext_services, RelationType.ADD,
                                                EntityType.ADMIN_SERVICE.value,
                                                params)
github vmware / container-service-extension / container_service_extension / pv_provisioner.py View on Github external
def process_request_provision_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['PVC']['metadata']['name']
        disk_name = '%s-%s' % (cluster_name, disk_name_orig)
        disk_size = json_request['PVC']['spec']['resources']['requests']['storage']

        d = None
        try:
            d = vdc.get_disk(disk_name)
        except Exception as e:
            if str(e).startswith('Found multiple'):
                raise Exception('disk already exists')
        if d is not None:
            raise Exception('disk already exists')

        # if disk doesn't exist:
        #     create it
github vmware / pyvcloud / pyvcloud / vcd / org.py View on Github external
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)
github vmware / container-service-extension / container_service_extension / pyvcloud_utils.py View on Github external
:return: org's name and href

    :rtype: dict
    """
    raise_error_if_not_sysadmin(sysadmin_client)

    if vdc_id in OVDC_TO_ORG_MAP:
        return OVDC_TO_ORG_MAP.get(vdc_id)

    vdc_href = f"{sysadmin_client.get_api_uri()}/vdc/{vdc_id}"
    vdc_resource = sysadmin_client.get_resource(get_admin_href(vdc_href))
    vdc_obj = VDC(sysadmin_client, resource=vdc_resource)
    link = vcd_client.find_link(
        vdc_obj.get_resource(),
        vcd_client.RelationType.UP,
        vcd_client.EntityType.ADMIN_ORG.value)
    org_href = link.href
    org = vcd_org.Org(sysadmin_client, href=org_href)
    org_name = org.get_name()

    result = {'name': org_name, 'href': org_href}
    OVDC_TO_ORG_MAP[vdc_id] = result
    return result
github vmware / pyvcloud / pyvcloud / vcd / vapp.py View on Github external
def reset_vapp_network(self, network_name):
        """Resets a vApp network.

        :param str network_name: name of vApp network to be reset.

        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task that is resetting the vApp network.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        self.get_resource()
        # find the required network
        for nw in self.resource.NetworkConfigSection.NetworkConfig:
            if nw.get("networkName") == network_name:
                return self.client.post_linked_resource(
                    nw, RelationType.REPAIR, None, None)
        raise EntityNotFoundException(
            'Can\'t find network \'%s\'' % network_name)
github vmware / pyvcloud / pyvcloud / vcd / vm.py View on Github external
Deploying the vm will allocate all resources assigned to the vm. If an
        attempt is made to deploy an already deployed vm, an exception will be
        raised.

        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task that is deploying the vm.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        deploy_vm_params = E.DeployVAppParams()
        deploy_vm_params.set('powerOn', str(power_on).lower())
        deploy_vm_params.set('forceCustomization',
                             str(force_customization).lower())
        return self._perform_power_operation(
            rel=RelationType.DEPLOY,
            operation_name='deploy',
            media_type=EntityType.DEPLOY.value,
            contents=deploy_vm_params)
github vmware / pyvcloud / pyvcloud / vcd / system.py View on Github external
def list_network_pools(self):
        """List network pools in the system organization.

        :return: a list of lxml.objectify.ObjectifiedElement containing
            NetworkPoolReference XML elements.

        :rtype: list
        """
        resource = self.client.get_extension()
        result = self.client.get_linked_resource(
            resource, RelationType.DOWN,
            EntityType.NETWORK_POOL_REFERENCES.value)
        if hasattr(result, '{' + NSMAP['vmext'] + '}NetworkPoolReference'):
            return result.NetworkPoolReference
        else:
            return []
github vmware / pyvcloud / pyvcloud / vcd / org.py View on Github external
:param str item_type: type of entity we are trying to enable for
            download. Valid values are EntityType.VAPP_TEMPLATE and
            EntityType.MEDIA.

        return: True, if the entity needs to be enabled for download else
            False.

        :rtype: bool
        """
        enable_download_required = True
        if item_type == EntityType.MEDIA.value:
            if hasattr(entity_resource, 'Files'):
                enable_download_required = False
        elif item_type == EntityType.VAPP_TEMPLATE.value:
            ovf_download_link = find_link(entity_resource,
                                          RelationType.DOWNLOAD_DEFAULT,
                                          EntityType.TEXT_XML.value, False)
            if ovf_download_link is not None:
                enable_download_required = False

        return enable_download_required