Beispiel #1
0
    def create_ovdc(cls):
        """Creates an org vdc with the name specified in the config file.

        Skips creating one, if such an org vdc already exists. Also stores the
        href of the org vdc as class variable for future use.

        :raises: Exception: if the class variable _org_href or _pvdc_name
            is not populated.
        """
        cls._basic_check()
        if cls._org_href is None:
            raise Exception('Org ' + cls._config['vcd']['default_org_name'] +
                            ' doesn\'t exist.')

        if cls._pvdc_name is None:
            raise Exception('pVDC ' + cls._config['vcd']['default_pvdc_name'] +
                            ' doesn\'t exist.')

        org = Org(cls._sys_admin_client, href=cls._org_href)
        ovdc_name = cls._config['vcd']['default_ovdc_name']
        for vdc in org.list_vdcs():
            if vdc.get('name').lower() == ovdc_name.lower():
                cls._logger.debug('Reusing existing ovdc ' + ovdc_name + '.')
                cls._ovdc_href = vdc.get('href')
                return

        storage_profiles = [{
            'name': cls._config['vcd']['default_storage_profile_name'],
            'enabled': True,
            'units': 'MB',
            'limit': 0,
            'default': True
        }]

        system = System(
            cls._sys_admin_client,
            admin_resource=cls._sys_admin_client.get_admin())
        netpool_to_use = cls._get_netpool_name_to_use(system)

        cls._logger.debug('Creating ovdc ' + ovdc_name + '.')
        vdc_resource = org.create_org_vdc(
            ovdc_name,
            cls._pvdc_name,
            network_pool_name=netpool_to_use,
            network_quota=cls._config['vcd']['default_network_quota'],
            storage_profiles=storage_profiles,
            uses_fast_provisioning=True,
            is_thin_provision=True)

        cls._sys_admin_client.get_task_monitor().wait_for_success(
            task=vdc_resource.Tasks.Task[0])

        org.reload()
        # The following contraption is required to get the non admin href of
        # the ovdc. vdc_resource contains the admin version of the href since
        # we created the ovdc as a sys admin.
        for vdc in org.list_vdcs():
            if vdc.get('name').lower() == ovdc_name.lower():
                cls._ovdc_href = vdc.get('href')
Beispiel #2
0
    def _list_ovdcs(self):
        """Get list of ovdcs.

        If client is sysadmin,
            Gets all ovdcs of all organizations.
        Else
            Gets all ovdcs of the organization in context.
        """
        if self.vcd_client.is_sysadmin():
            org_resource_list = self.vcd_client.get_org_list()
        else:
            org_resource_list = list(self.vcd_client.get_org())

        ovdc_list = []
        for org_resource in org_resource_list:
            org = Org(self.vcd_client, resource=org_resource)
            vdc_list = org.list_vdcs()
            for vdc in vdc_list:
                ctr_prov_ctx = \
                    self.ovdc_cache.get_ovdc_container_provider_metadata(
                        ovdc_name=vdc['name'], org_name=org.get_name(),
                        credentials_required=False)
                vdc_dict = {
                    'org': org.get_name(),
                    'name': vdc['name'],
                    CONTAINER_PROVIDER_KEY:
                    ctr_prov_ctx[CONTAINER_PROVIDER_KEY]
                }
                ovdc_list.append(vdc_dict)
        return ovdc_list
Beispiel #3
0
    def count_vcloud(self, client):
        """
        Obtain counts via vCloud API. Multiple dependent requests are needed therefore
        we collect them all in one pass to avoid repeating previous requests e.g. to
        fetch VMs, one must first fetch vApps and vdcs.
        :param client:
        :return:
        """
        org_resource = client.get_org()
        org = Org(client, resource=org_resource)

        stats = {
            'num_availability_zone': 0,
            'num_orchestration_stack': 0,
            'num_vm': 0
        }

        for vdc_info in org.list_vdcs():
            stats['num_availability_zone'] += 1
            vdc = VDC(client, resource=org.get_vdc(vdc_info['name']))
            for vapp_info in vdc.list_resources():
                try:
                    vapp_resource = vdc.get_vapp(vapp_info.get('name'))
                except Exception:
                    continue  # not a vapp (probably vapp template or something)

                vapp = VApp(client, resource=vapp_resource)
                stats['num_orchestration_stack'] += 1
                stats['num_vm'] += len(vapp.get_all_vms())

        return stats
Beispiel #4
0
 def test_list_org_vdc(self):
     org_to_use = self.client.get_org_by_name(
         self.config['vcd']['org_to_use'])
     org = Org(self.client, href=org_to_use.get('href'))
     assert org is not None
     vdcs = org.list_vdcs()
     assert len(vdcs) > 0
Beispiel #5
0
    def _create_pks_context_for_all_accounts_in_org(self):
        """Create PKS context for accounts in a given Org.

        If user is Sysadmin
            Creates PKS contexts for all PKS accounts defined in the entire
            system.
        else
            Creates PKS contexts for all PKS accounts assigned to the org.
            However if separate service accounts for each org hasn't been
            configued by admin via pks.yaml, then PKS accounts of the PKS
            server corresponding to the vCenters powering the individual
            orgVDC of the org will be picked up for creating the PKS contexts.

        :return: list of dict, where each dictionary is a PKS context

        :rtype: list
        """
        if not self.pks_cache:
            return []

        if self.vcd_client.is_sysadmin():
            all_pks_account_info = \
                self.pks_cache.get_all_pks_account_info_in_system()
            pks_ctx_list = [
                OvdcCache.construct_pks_context(pks_account_info,
                                                credentials_required=True)
                for pks_account_info in all_pks_account_info
            ]
            return pks_ctx_list

        org_name = self.session.get('org')
        if self.pks_cache.do_orgs_have_exclusive_pks_account():
            pks_account_infos = \
                self.pks_cache.get_exclusive_pks_accounts_info_for_org(
                    org_name)
            pks_ctx_list = [
                OvdcCache.construct_pks_context(pks_account_info,
                                                credentials_required=True)
                for pks_account_info in pks_account_infos
            ]
        else:
            org_resource = self.vcd_client.get_org()
            org = Org(self.vcd_client, resource=org_resource)
            vdc_names = [vdc['name'] for vdc in org.list_vdcs()]
            # Constructing dict instead of list to avoid duplicates
            # TODO() figure out a way to add pks contexts to a set directly
            pks_ctx_dict = {}
            for vdc_name in vdc_names:
                # this is a full blown pks_account_info + pvdc_info +
                # compute_profile_name dictionary
                ctr_prov_ctx = \
                    self.ovdc_cache.get_ovdc_container_provider_metadata(
                        ovdc_name=vdc_name, org_name=org_name,
                        credentials_required=True)
                if ctr_prov_ctx[K8S_PROVIDER_KEY] == K8sProviders.PKS:
                    pks_ctx_dict[ctr_prov_ctx['vc']] = ctr_prov_ctx

            pks_ctx_list = list(pks_ctx_dict.values())

        return pks_ctx_list
Beispiel #6
0
 def test_list_org_vdc(self):
     org_to_use = self.client.get_org_by_name(
         self.config['vcd']['org_to_use'])
     org = Org(self.client, href=org_to_use.get('href'))
     assert org is not None
     vdcs = org.list_vdcs()
     assert len(vdcs) > 0
Beispiel #7
0
def create_pks_context_for_all_accounts_in_org(
        op_ctx: ctx.OperationContext):  # noqa: E501
    """Create PKS context for accounts in a given Org.

    If user is Sysadmin
        Creates PKS contexts for all PKS accounts defined in the entire
        system.
    else
        Creates PKS contexts for all PKS accounts assigned to the org.
        However if separate service accounts for each org hasn't been
        configued by admin via pks.yaml, then PKS accounts of the PKS
        server corresponding to the vCenters powering the individual
        orgVDC of the org will be picked up for creating the PKS contexts.

    :return: list of dict, where each dictionary is a PKS context

    :rtype: list
    """
    pks_cache = server_utils.get_pks_cache()
    if pks_cache is None:
        return []

    if op_ctx.client.is_sysadmin():
        all_pks_account_info = pks_cache.get_all_pks_account_info_in_system()
        pks_ctx_list = [
            ovdc_utils.construct_pks_context(pks_account_info,
                                             credentials_required=True)
            for pks_account_info in all_pks_account_info
        ]  # noqa: E501
        return pks_ctx_list

    if pks_cache.do_orgs_have_exclusive_pks_account():
        pks_account_infos = pks_cache.get_exclusive_pks_accounts_info_for_org(
            op_ctx.user.org_name)  # noqa: E501
        pks_ctx_list = [
            ovdc_utils.construct_pks_context(pks_account_info,
                                             credentials_required=True)
            for pks_account_info in pks_account_infos
        ]  # noqa: E501
        return pks_ctx_list

    org_resource = op_ctx.client.get_org()
    org = Org(op_ctx.client, resource=org_resource)
    vdc_names = [vdc['name'] for vdc in org.list_vdcs()]
    # Constructing dict instead of list to avoid duplicates
    # TODO() figure out a way to add pks contexts to a set directly
    pks_ctx_dict = {}
    for vdc_name in vdc_names:
        # this is a full blown pks_account_info + pvdc_info +
        # compute_profile_name dictionary
        k8s_metadata = ovdc_utils.get_ovdc_k8s_provider_metadata(
            op_ctx.sysadmin_client,
            ovdc_name=vdc_name,
            org_name=op_ctx.user.org_name,
            include_credentials=True)
        if k8s_metadata[K8S_PROVIDER_KEY] == K8sProvider.PKS:
            pks_ctx_dict[k8s_metadata['vc']] = k8s_metadata

    return list(pks_ctx_dict.values())
Beispiel #8
0
    def list_vdcs(self):
        org_name = self.params.get('org_name')
        response = dict()
        org_details = dict()
        response['vdcs'] = list()
        response['changed'] = False

        resource = self.client.get_org_by_name(org_name)
        org = Org(self.client, resource=resource)
        response['vdcs'] = org.list_vdcs()

        return response
Beispiel #9
0
    def _list_ovdcs(self, list_pks_plans=False):
        """Get list of ovdcs.

        If client is sysadmin,
            Gets all ovdcs of all organizations.
        Else
            Gets all ovdcs of the organization in context.
        """
        if self.vcd_client.is_sysadmin():
            org_resource_list = self.vcd_client.get_org_list()
        else:
            org_resource_list = list(self.vcd_client.get_org())

        ovdc_list = []
        vc_to_pks_plans_map = {}
        if list_pks_plans:
            if self.vcd_client.is_sysadmin():
                vc_to_pks_plans_map = self._construct_vc_to_pks_map()
            else:
                raise UnauthorizedActionError(
                    'Operation Denied. Plans available only for '
                    'System Administrator.')
        for org_resource in org_resource_list:
            org = Org(self.vcd_client, resource=org_resource)
            vdc_list = org.list_vdcs()
            for vdc in vdc_list:
                ctr_prov_ctx = \
                    self.ovdc_cache.get_ovdc_container_provider_metadata(
                        ovdc_name=vdc['name'], org_name=org.get_name(),
                        credentials_required=False)
                if list_pks_plans:
                    pks_plans, pks_server = self.\
                        _get_pks_plans_and_server_for_vdc(vdc,
                                                          org_resource,
                                                          vc_to_pks_plans_map)
                    vdc_dict = {
                        'org': org.get_name(),
                        'name': vdc['name'],
                        'pks_api_server': pks_server,
                        'available pks plans': pks_plans
                    }
                else:
                    vdc_dict = {
                        'name': vdc['name'],
                        'org': org.get_name(),
                        K8S_PROVIDER_KEY: ctr_prov_ctx[K8S_PROVIDER_KEY]
                    }
                ovdc_list.append(vdc_dict)
        return ovdc_list
Beispiel #10
0
    def _list_ovdcs(self, list_pks_plans):
        """Get list of ovdcs.

        If client is sysadmin,
            Gets all ovdcs of all organizations.
        Else
            Gets all ovdcs of the organization in context.
        """
        client, _ = connect_vcd_user_via_token(self.tenant_auth_token)
        if client.is_sysadmin():
            org_resource_list = client.get_org_list()
        else:
            org_resource_list = list(client.get_org())

        ovdc_list = []
        vc_to_pks_plans_map = {}
        if is_pks_enabled() and list_pks_plans:
            if client.is_sysadmin():
                vc_to_pks_plans_map = self._construct_vc_to_pks_map()
            else:
                raise UnauthorizedActionError(
                    'Operation Denied. Plans available only for '
                    'System Administrator.')
        for org_resource in org_resource_list:
            org = Org(client, resource=org_resource)
            vdc_list = org.list_vdcs()
            for vdc_sparse in vdc_list:
                ctr_prov_ctx = \
                    OvdcManager().get_ovdc_container_provider_metadata(
                        ovdc_name=vdc_sparse['name'], org_name=org.get_name(),
                        credentials_required=False)
                vdc_dict = {
                    'name': vdc_sparse['name'],
                    'org': org.get_name(),
                    K8S_PROVIDER_KEY: ctr_prov_ctx[K8S_PROVIDER_KEY]
                }
                if is_pks_enabled() and list_pks_plans:
                    pks_plans, pks_server = self.\
                        _get_pks_plans_and_server_for_vdc(client,
                                                          vdc_sparse,
                                                          org_resource,
                                                          vc_to_pks_plans_map)
                    vdc_dict['pks_api_server'] = pks_server
                    vdc_dict['available pks plans'] = pks_plans
                ovdc_list.append(vdc_dict)
        return ovdc_list
Beispiel #11
0
 def test_list_vdc(self):
     org_resource = self.client.get_org()
     org = Org(self.client, resource=org_resource)
     vdcs = org.list_vdcs()
     assert vdcs is not None
Beispiel #12
0
    def create_ovdc(cls):
        """Creates an org vdc with the name specified in the config file.

        Skips creating one, if such an org vdc already exists. Also stores the
        href of the org vdc as class variable for future use.

        :raises: Exception: if the class variable _org_href or _pvdc_name
            is not populated.
        """
        cls._basic_check()
        if cls._org_href is None:
            raise Exception('Org ' + cls._config['vcd']['default_org_name'] +
                            ' doesn\'t exist.')

        if cls._pvdc_name is None:
            raise Exception('pVDC ' + cls._config['vcd']['default_pvdc_name'] +
                            ' doesn\'t exist.')

        org = Org(cls._sys_admin_client, href=cls._org_href)
        ovdc_name = cls._config['vcd']['default_ovdc_name']
        for vdc in org.list_vdcs():
            if vdc.get('name').lower() == ovdc_name.lower():
                cls._logger.debug('Reusing existing ovdc ' + ovdc_name + '.')
                cls._ovdc_href = vdc.get('href')
                return

        storage_profiles = [{
            'name':
            cls._config['vcd']['default_storage_profile_name'],
            'enabled':
            True,
            'units':
            'MB',
            'limit':
            0,
            'default':
            True
        }]

        system = System(
            cls._sys_admin_client,
            admin_resource=cls._sys_admin_client.get_admin())
        netpool_to_use = cls._get_netpool_name_to_use(system)

        cls._logger.debug('Creating ovdc ' + ovdc_name + '.')
        vdc_resource = org.create_org_vdc(
            ovdc_name,
            cls._pvdc_name,
            network_pool_name=netpool_to_use,
            network_quota=cls._config['vcd']['default_network_quota'],
            storage_profiles=storage_profiles,
            uses_fast_provisioning=True,
            is_thin_provision=True)

        cls._sys_admin_client.get_task_monitor().wait_for_success(
            task=vdc_resource.Tasks.Task[0])

        org.reload()
        # The following contraption is required to get the non admin href of
        # the ovdc. vdc_resource contains the admin version of the href since
        # we created the ovdc as a sys admin.
        for vdc in org.list_vdcs():
            if vdc.get('name').lower() == ovdc_name.lower():
                cls._ovdc_href = vdc.get('href')
Beispiel #13
0
class Vdc(VcdAnsibleModule):
    def __init__(self, **kwargs):
        super(Vdc, self).__init__(**kwargs)
        self.org = Org(self.client, resource=self.get_vdc_org_resource())

    def manage_states(self):
        state = self.params.get('state')
        if state == 'present':
            return self.create()

        if state == 'absent':
            return self.delete()

        if state == 'update':
            return self.update()

    def manage_operations(self):
        operation = self.params.get('operation')
        if operation == 'list_vdcs':
            return self.list_vdcs()

    def get_vdc_org_resource(self):
        if self.params.get('vdc_org_name'):
            return self.client.get_org_by_name(self.params.get('vdc_org_name'))

        return self.client.get_org()

    def create(self):
        vdc_name = self.params.get('vdc_name')
        is_enabled = self.params.get('is_enabled')
        provider_vdc_name = self.params.get('provider_vdc_name')
        description = self.params.get('description')
        allocation_model = self.params.get('allocation_model')
        storage_profiles = self.params.get('storage_profiles')
        cpu_units = self.params.get('cpu_units')
        cpu_allocated = self.params.get('cpu_allocated')
        cpu_limit = self.params.get('cpu_limit')
        mem_units = self.params.get('mem_units')
        mem_allocated = self.params.get('mem_allocated')
        mem_limit = self.params.get('mem_limit')
        nic_quota = self.params.get('nic_quota')
        network_quota = self.params.get('network_quota')
        vm_quota = self.params.get('vm_quota')
        resource_guaranteed_memory = self.params.get(
            'resource_guaranteed_memory')
        resource_guaranteed_cpu = self.params.get('resource_guaranteed_cpu')
        vcpu_in_mhz = self.params.get('vcpu_in_mhz')
        is_thin_provision = self.params.get('is_thin_provision')
        network_pool_name = self.params.get('network_pool_name')
        uses_fast_provisioning = self.params.get('uses_fast_provisioning')
        over_commit_allowed = self.params.get('over_commit_allowed')
        vm_discovery_enabled = self.params.get('vm_discovery_enabled')
        response = dict()
        response['changed'] = False

        if not self.org.get_vdc(vdc_name):
            create_vdc_task = self.org.create_org_vdc(
                vdc_name=vdc_name,
                provider_vdc_name=provider_vdc_name,
                description=description,
                allocation_model=allocation_model,
                storage_profiles=storage_profiles,
                cpu_units=cpu_units,
                cpu_allocated=cpu_allocated,
                cpu_limit=cpu_limit,
                mem_units=mem_units,
                mem_allocated=mem_allocated,
                mem_limit=mem_limit,
                nic_quota=nic_quota,
                network_quota=network_quota,
                vm_quota=vm_quota,
                resource_guaranteed_memory=resource_guaranteed_memory,
                resource_guaranteed_cpu=resource_guaranteed_cpu,
                vcpu_in_mhz=vcpu_in_mhz,
                is_thin_provision=is_thin_provision,
                network_pool_name=network_pool_name,
                uses_fast_provisioning=uses_fast_provisioning,
                over_commit_allowed=over_commit_allowed,
                vm_discovery_enabled=vm_discovery_enabled,
                is_enabled=is_enabled)

            self.execute_task(create_vdc_task.Tasks.Task[0])
            response['msg'] = 'VDC {} has been created.'.format(vdc_name)
            response['changed'] = True
        else:
            response['warnings'] = 'VDC {} is already present.'.format(
                vdc_name)

        return response

    def update(self):
        vdc_name = self.params.get('vdc_name')
        is_enabled = self.params.get('is_enabled')
        response = dict()
        response['changed'] = False

        try:

            vdc_resource = self.org.get_vdc(vdc_name, is_admin_operation=True)
            vdc = VDC(self.client, name=vdc_name, resource=vdc_resource)
            vdc.enable_vdc(enable=is_enabled)
            response['msg'] = 'VDC {} has been updated.'.format(vdc_name)
            response['changed'] = True

        except OperationNotSupportedException:
            m = "VDC {} may already in {} state"
            response['warnings'] = m.format(
                vdc_name, "enabled") if is_enabled else m.format(
                    vdc_name, "disabled")

        return response

    def delete(self):
        vdc_name = self.params.get('vdc_name')
        response = dict()
        response['changed'] = False

        try:

            vdc_resource = self.org.get_vdc(vdc_name, is_admin_operation=True)
            vdc = VDC(self.client, name=vdc_name, resource=vdc_resource)
            vdc.enable_vdc(enable=False)

        except EntityNotFoundException:
            response['warnings'] = 'VDC {} is not present.'.format(vdc_name)
            return

        except OperationNotSupportedException:
            pass

        delete_vdc_task = vdc.delete_vdc()
        self.execute_task(delete_vdc_task)
        response['msg'] = 'VDC {} has been deleted.'.format(vdc_name)
        response['changed'] = True

        return response

    def list_vdcs(self):
        response = dict()
        response['changed'] = False
        response['msg'] = list()

        for vdc in self.org.list_vdcs():
            response['msg'].append(vdc.get('name'))

        return response
Beispiel #14
0
 def test_list_vdc(self):
     org_resource = self.client.get_org()
     org = Org(self.client, resource=org_resource)
     vdcs = org.list_vdcs()
     assert vdcs is not None
Beispiel #15
0
print(orgtable)

# Iterate over Organizations - 2nd GO to retrieve data about VDCs ---------------------------------
for o in orgs:
    cprint(
        '\nOrganization ' + o.attrib['name'] +
        ' ###################################################################'
        '############################################', 'green')
    # print(o.get('name'))

    # Create an Instance of Org by specifying org's href
    org = Org(client, href=(o.attrib['href']))

    cprint("\nList of all VDCs in the Organization {}".format(o.get('name')),
           'yellow')
    vdclist = org.list_vdcs()
    vdctable = PrettyTable(["Organization", "VDC name", "VDC href"])
    for i in range(len(vdclist)):
        vdctable.add_row(
            [o.get('name'), vdclist[i]['name'], vdclist[i]['href']])
    print(vdctable)

    # Iterate over VDCs to retrieve data about Edges, Org Networks, vAPPs and VMs
    for vdc in vdclist:
        # print("\nFetching VDC {}".format(vdc['name']))
        vdc_resource = org.get_vdc(vdc['name'])
        vdc_instance = VDC(client, resource=vdc_resource)

        cprint("\nList of all Tenant Edges in the VDC {}".format(vdc['name']),
               'yellow')
        edgelist = vdc_instance.list_edge_gateways()
Beispiel #16
0
user = sys.argv[3]
password = sys.argv[4]

# Disable warnings from self-signed certificates.
requests.packages.urllib3.disable_warnings()

# Login. SSL certificate verification is turned off to allow self-signed
# certificates.  You should only do this in trusted environments.
print("Logging in: host={0}, org={1}, user={2}".format(host, org, user))
client = Client(host, verify_ssl_certs=False)
client.set_highest_supported_version()
client.set_credentials(BasicLoginCredentials(user, org, password))

print("Fetching Org...")
org = Org(client, resource=client.get_org())
print("Fetching VDCs...")
for vdc_info in org.list_vdcs():
    name = vdc_info['name']
    href = vdc_info['href']
    print("VDC name: {0}\n    href: {1}".format(
        vdc_info['name'], vdc_info['href']))
    vdc = VDC(client, resource=org.get_vdc(vdc_info['name']))
    print("{0}{1}".format("Name".ljust(40), "Type"))
    print("{0}{1}".format("----".ljust(40), "----"))
    for resource in vdc.list_resources():
        print('%s%s' % (resource['name'].ljust(40), resource['type']))

# Log out.
print("Logging out")
client.logout()
def get_ovdc_list(client,
                  list_pks_plans=False,
                  tenant_auth_token=None,
                  is_jwt_token=False):
    """Get details for all client-visible org VDCs.

    :param pyvcloud.vcd.client.Client client:
    :param bool list_pks_plans:
    :param str tenant_auth_token:
    :param bool is_jwt_token:

    :return: List of dict with str keys: ['name', 'org', 'k8s provider'].
        If @list_pks_plans is True, then dict will also have
        str keys: ['pks api server', 'available pks plans']

    :rtype: List[Dict]

    :raises UnauthorizedRequestError: if trying to @list_pks_plans
        as non-sysadmin.
    :raises ValueError: if @list_pks_plans is True and @tenant_auth_token
        is None.
    """
    if list_pks_plans and not client.is_sysadmin():
        raise UnauthorizedRequestError('Operation Denied. Plans available '
                                       'only for System Administrator.')
    if list_pks_plans and not tenant_auth_token:
        raise ValueError("Missing required parameters for listing pks plans.")

    if client.is_sysadmin():
        org_resource_list = client.get_org_list()
    else:
        org_resource_list = list(client.get_org())

    ovdc_list = []
    for org_resource in org_resource_list:
        org = Org(client, resource=org_resource)
        vdc_list = org.list_vdcs()
        for vdc_sparse in vdc_list:
            ovdc_name = vdc_sparse['name']
            org_name = org.get_name()

            k8s_metadata = get_ovdc_k8s_provider_metadata(ovdc_name=ovdc_name,
                                                          org_name=org_name)
            k8s_provider = k8s_metadata[K8S_PROVIDER_KEY]
            ovdc_info = {
                'name': ovdc_name,
                'org': org_name,
                'k8s provider': k8s_provider
            }

            if list_pks_plans:
                # client is sys admin if we're here
                pks_plans = ''
                pks_server = ''
                if k8s_provider == K8sProvider.PKS:
                    # vc name for vdc can only be found using typed query
                    q = \
                        client.get_typed_query(
                            ResourceType.ADMIN_ORG_VDC.value,
                            query_result_format=QueryResultFormat.RECORDS,
                            qfilter=f"name=={ovdc_name};orgName=={org_name}")
                    ovdc_records = list(q.execute())
                    if len(ovdc_records) == 0:
                        raise EntityNotFoundException(f"Org VDC {ovdc_name} not found in org {org_name}") # noqa: E501
                    ovdc_record = None
                    # there should only ever be one element in the generator
                    for record in ovdc_records:
                        ovdc_record = to_dict(record, resource_type=ResourceType.ADMIN_ORG_VDC.value) # noqa: E501
                        break
                    vc_name = ovdc_record['vcName']

                    vc_to_pks_plans_map = _get_vc_to_pks_plans_map(
                        tenant_auth_token, is_jwt_token)
                    pks_plan_and_server_info = \
                        vc_to_pks_plans_map.get(vc_name, [])
                    if len(pks_plan_and_server_info) > 0:
                        pks_plans = pks_plan_and_server_info[0]
                        pks_server = pks_plan_and_server_info[1]

                ovdc_info['pks api server'] = pks_server
                ovdc_info['available pks plans'] = pks_plans

            ovdc_list.append(ovdc_info)

    return ovdc_list
Beispiel #18
0
 def test_list_vdc(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, org_resource=logged_in_org)
     vdcs = org.list_vdcs()
     assert len(vdcs) > 0