def get_all_ovdcs(client: vcd_client.Client): if client.is_sysadmin(): # use adminOrgVdc in typed query query = client.get_typed_query( vcd_client.ResourceType.ADMIN_ORG_VDC.value, query_result_format=vcd_client.QueryResultFormat.ID_RECORDS) else: # use orgVdc in typed query query = client.get_typed_query( vcd_client.ResourceType.ORG_VDC.value, query_result_format=vcd_client.QueryResultFormat.ID_RECORDS) return list(query.execute())
def get_org_id_from_vdc_name(client: vcd_client.Client, vdc_name: str): """Return org id given vdc name. :param vcd_client.Client client: vcd client :param str vdc_name: vdc name :return: org id, with no prefix, e.g., '12345' :rtype: str """ if client.is_sysadmin(): resource_type = vcd_client.ResourceType.ADMIN_ORG_VDC.value else: resource_type = vcd_client.ResourceType.ORG_VDC.value query = client.get_typed_query( query_type_name=resource_type, query_result_format=vcd_client.QueryResultFormat.ID_RECORDS, equality_filter=('name', vdc_name)) records = list(query.execute()) if len(records) == 0: return None # Process org id if client.is_sysadmin(): org_urn_id = records[0].attrib['org'] else: org_name = records[0].attrib['orgName'] org_resource = client.get_org_by_name(org_name) org_urn_id = org_resource.attrib['id'] return extract_id(org_urn_id)
def get_ovdcs_by_page(client: vcd_client.Client, page=CSE_PAGINATION_FIRST_PAGE_NUMBER, page_size=CSE_PAGINATION_DEFAULT_PAGE_SIZE): """Get the list of ovdcs in the page.""" query = None if client.is_sysadmin(): # use adminOrgVdc in typed query query = client.get_typed_query( vcd_client.ResourceType.ADMIN_ORG_VDC.value, page=page, page_size=page_size, query_result_format=vcd_client.QueryResultFormat.ID_RECORDS) else: # use orgVdc in typed query query = client.get_typed_query( vcd_client.ResourceType.ORG_VDC.value, page=page, page_size=page_size, query_result_format=vcd_client.QueryResultFormat.ID_RECORDS) vdc_results = query.execute() return vdc_results
# We check to ensure they are in the resolved state; otherwise, we cannot # use them for vApps. The following code loops until catalog items are # in the right state. print("Checking for unresolved templates") find_unresolved = True while find_unresolved: find_unresolved = False # Iterate over all the desired templates from the config file. for catalog_item in cfg.catalog_items: # Run a report query on this catalog item to find its state. catalog_item_resource = org.get_catalog_item( catalog_item['catalog_name'], catalog_item['item_name']) resource_type = 'adminCatalogItem' query = client.get_typed_query( resource_type, query_result_format=QueryResultFormat.ID_RECORDS, qfilter="catalogName=={0};name=={1}".format( catalog_item['catalog_name'], catalog_item['item_name'])) item_records = list(query.execute()) # Ensure we find the catalog item. if len(item_records) == 0: raise Exception("Catalog item not found: {0}".format( catalog_item['item_name'])) else: for item_record in item_records: item_dict = to_dict(item_record, resource_type=resource_type) # If the template exists but is not in the right # state we need to wait. if item_dict['status'] != "RESOLVED": print("Template unresolved: {0} {1} {2}".format( item_dict['catalogName'],