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
def get_org_name_from_ovdc_id(vdc_id): """Get org_name from vdc_id using OVDC_TO_ORG_MAP. Update OVDC_TO_ORG_MAP for new {org_name:vdc_id} pair :param vdc_id: unique ovdc id :return: org_name :rtype: str """ if vdc_id in OVDC_TO_ORG_MAP: org_name = OVDC_TO_ORG_MAP.get(vdc_id) else: client = None try: client = get_sys_admin_client() vdc_href = f"{client._uri}/vdc/{vdc_id}" vdc_resource = client.get_resource(get_admin_href(vdc_href)) vdc_obj = VDC(client, resource=vdc_resource) link = find_link(vdc_obj.get_resource(), RelationType.UP, EntityType.ADMIN_ORG.value) org = Org(client, href=link.href) OVDC_TO_ORG_MAP[vdc_id] = org.get_name() org_name = org.get_name() finally: if client: client.logout return org_name
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
def share_catalog(cls): """Shares the test catalog with all members in the test organization. :return: Nothing :raises: Exception: if the class variable _org_href is not populated. :raises: EntityNotFoundException: if the catalog in question is missing. """ cls._basic_check() if cls._org_href is None: raise Exception('Org ' + cls._config['vcd']['default_org_name'] + ' doesn\'t exist.') org = Org(cls._sys_admin_client, href=cls._org_href) catalog_name = cls._config['vcd']['default_catalog_name'] catalog_records = org.list_catalogs() for catalog_record in catalog_records: if catalog_record.get('name').lower() == catalog_name.lower(): cls._logger.debug('Sharing catalog ' + catalog_name + ' to all members of org ' + org.get_name()) org.share_catalog_with_org_members(catalog_name=catalog_name) return raise EntityNotFoundException('Catalog ' + catalog_name + 'doesn\'t' 'exists.')
def delete_vm(client): print("================= Vdc delete request ===================") vdc_name = "pcp_vdc_02" target_vm_name = "pcp_vm" org_resource = client.get_org() org = Org(client, resource=org_resource) print("Org name: ", org.get_name()) print("Vdc name: ", vdc_name) vdc_resource = org.get_vdc(vdc_name) vdc = VDC(client, name=vdc_name, resource=vdc_resource) vapp_resource = vdc.get_vapp(vapp_name) vapp = VApp(client, name=vapp_name, resource=vapp_resource) delete_vapp_vm_resp = vapp.delete_vms(target_vm_name) task = client.get_task_monitor().wait_for_status( task=delete_vapp_vm_resp, timeout=60, poll_frequency=2, fail_on_statuses=None, expected_target_statuses=[ TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR, TaskStatus.CANCELED ], callback=None) st = task.get('status') if st == TaskStatus.SUCCESS.value: message = 'delete vdc status : {0} '.format(st) logging.info(message) else: raise errors.VCDVdcDeleteError(etree.tostring(task, pretty_print=True))
def share_catalog(cls): """Shares the test catalog with all members in the test organization. :raises: Exception: if the class variable _org_href is not populated. :raises: EntityNotFoundException: if the catalog in question is missing. """ cls._basic_check() if cls._org_href is None: raise Exception('Org ' + cls._config['vcd']['default_org_name'] + ' doesn\'t exist.') try: catalog_author_client = Environment.get_client_in_default_org( CommonRoles.CATALOG_AUTHOR) org = Org(catalog_author_client, href=cls._org_href) catalog_name = cls._config['vcd']['default_catalog_name'] catalog_records = org.list_catalogs() for catalog_record in catalog_records: if catalog_record.get('name') == catalog_name: cls._logger.debug('Sharing catalog ' + catalog_name + ' to' ' all members of org ' + org.get_name()) org.share_catalog_with_org_members( catalog_name=catalog_name) return raise EntityNotFoundException('Catalog ' + catalog_name + 'doesn\'t exist.') finally: catalog_author_client.logout()
def delete_vm(client): print("================= Vdc delete request ===================") vdc_name = "pcp_vdc_02" target_vm_name = "pcp_vm" org_resource = client.get_org() org = Org(client, resource=org_resource) print("Org name: ", org.get_name()) print("Vdc name: ", vdc_name) vdc_resource = org.get_vdc(vdc_name) vdc = VDC(client, name=vdc_name, resource=vdc_resource) vapp_resource = vdc.get_vapp(vapp_name) vapp = VApp(client, name=vapp_name, resource=vapp_resource) delete_vapp_vm_resp = vapp.delete_vms(target_vm_name) task = client.get_task_monitor().wait_for_status(task=delete_vapp_vm_resp, timeout=60, poll_frequency=2, fail_on_statuses=None, expected_target_statuses=[ TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR, TaskStatus.CANCELED ], callback=None) st = task.get('status') if st == TaskStatus.SUCCESS.value: message = 'delete vdc status : {0} '.format(st) logging.info(message) else: raise errors.VCDVdcDeleteError(etree.tostring(task, pretty_print=True))
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
def test_0020_get_org(self): """Test the method Client.get_org_by_name(). Invoke the method with the name of the organization created in setup. This test passes if the organization detail retrieved by the method is not None, and the details e.g. name of the organization, are correct. """ org_resource = TestOrg._client.get_org_by_name(TestOrg._new_org_name) self.assertIsNotNone(org_resource) org = Org(TestOrg._client, resource=org_resource) self.assertEqual(TestOrg._new_org_name, org.get_name())
def get_org_name_of_ovdc(vdc_id): """Get org_name from vdc_id using OVDC_TO_ORG_MAP. Update OVDC_TO_ORG_MAP for new {org_name:vdc_id} pair :param vdc_id: unique ovdc id :return: org_name """ if vdc_id in OVDC_TO_ORG_MAP: org_name = OVDC_TO_ORG_MAP.get(vdc_id) else: client = get_vcd_sys_admin_client() vdc_href = f"{client._uri}/vdc/{vdc_id}" vdc_resource = client.get_resource(get_admin_href(vdc_href)) vdc_obj = VDC(client, resource=vdc_resource) link = find_link(vdc_obj.resource, RelationType.UP, EntityType.ADMIN_ORG.value) org = Org(client, href=link.href) '''Add the entry to the map to be used next time the \ same ovdc is requested''' OVDC_TO_ORG_MAP[vdc_id] = org.get_name() org_name = org.get_name() return org_name
def update_vdc(client): print("================= Vdc update request ===================") vdc_name = "pcp_vdc_02" is_enabled = False org_resource = client.get_org() org = Org(client, resource=org_resource) print("Org name: ", org.get_name()) print("Vdc name: ", vdc_name) vdc_resource = org.get_vdc(vdc_name) vdc = VDC(client, name=vdc_name, resource=vdc_resource) update_vdc_resp = vdc.enable_vdc(is_enabled) print("================= Vdc updated ===================")
def uninstall_cse(ctx, config_file_name, template_name): click.secho('Uninstalling CSE from vCD from file: %s, template: %s' % (config_file_name, template_name)) config = get_config(config_file_name) client = Client( config['vcd']['host'], api_version=config['vcd']['api_version'], verify_ssl_certs=config['vcd']['verify'], log_file='cse.log', log_headers=True, log_bodies=True) client.set_credentials( BasicLoginCredentials(config['vcd']['username'], 'System', config['vcd']['password'])) click.echo('Connected to vCloud Director as system ' 'administrator (%s:%s): %s' % (config['vcd']['host'], config['vcd']['port'], bool_to_msg(True))) ctx.obj = {} ctx.obj['client'] = client if config['broker']['type'] == 'default': ctx.obj = {} ctx.obj['client'] = client orgs = client.get_org_list() for org in [o for o in orgs.Org if hasattr(orgs, 'Org')]: if org.get('name') == config['broker']['org']: org_href = org.get('href') org = Org(client, href=org_href) click.echo('Find org \'%s\': %s' % (org.get_name(), bool_to_msg(True))) vdc_resource = org.get_vdc(config['broker']['vdc']) click.echo('Find vdc \'%s\': %s' % (vdc_resource.get('name'), bool_to_msg(True))) vdc = VDC(client, resource=vdc_resource) assert vdc for template in config['broker']['templates']: if template_name == '*' or template['name'] == template_name: click.secho('Deleting template: %s (%s:%s)' % (template['name'], config['broker']['catalog'], template['catalog_item'])) org.delete_catalog_item(config['broker']['catalog'], template['catalog_item'])
print("Logging in...") client = Client(cfg.vcd_host, verify_ssl_certs=False, log_file='pyvcloud.log', log_requests=True, log_headers=True, log_bodies=True) client.set_credentials(BasicLoginCredentials(cfg.vcd_admin_user, "System", cfg.vcd_admin_password)) # Ensure the org exists. print("Fetching org...") try: # This call gets a record that we can turn into an Org class. org_record = client.get_org_by_name(cfg.org) org = Org(client, href=org_record.get('href')) print("Org already exists: {0}".format(org.get_name())) except Exception: print("Org does not exist, creating: {0}".format(cfg.org)) sys_admin_resource = client.get_admin() system = System(client, admin_resource=sys_admin_resource) admin_org_resource = system.create_org(cfg.org, "Test Org", True) org_record = client.get_org_by_name(cfg.org) org = Org(client, href=org_record.get('href')) print("Org now exists: {0}".format(org.get_name())) # Ensure user exists on the org. try: user_resource = org.get_user(cfg.user['name']) print("User already exists: {0}".format(cfg.user['name'])) except Exception: print("User does not exist, creating: {0}".format(cfg.user['name']))
def read_vdc(client): print("================= Vdc read request ===================") vdc_name = "pcp_vdc_03" org_resource = client.get_org() org = Org(client, resource=org_resource) print("Org name: ", org.get_name()) print("Vdc name: ", vdc_name) vdc_resource = org.get_vdc(vdc_name) vdc = VDC(client, name=vdc_name, resource=vdc_resource) print("name = ", vdc_resource.get('name')) # res.provider_vdc = str(vdc_resource.provider_vdc) description = str(vdc_resource.Description) print("description = ", description) allocation_model = str(vdc_resource.AllocationModel) print("allocation_model = ", allocation_model) cpu_units = str(vdc_resource.ComputeCapacity.Cpu.Units) print("cpu_units = ", cpu_units) cpu_allocated = vdc_resource.ComputeCapacity.Cpu.Allocated print("cpu_allocated = ", cpu_allocated) cpu_limit = vdc_resource.ComputeCapacity.Cpu.Limit print("cpu_limit = ", cpu_limit) mem_units = vdc_resource.ComputeCapacity.Memory.Units print("mem_units = ", mem_units) mem_allocated = vdc_resource.ComputeCapacity.Memory.Allocated print("mem_allocated = ", mem_allocated) mem_limit = vdc_resource.ComputeCapacity.Memory.Limit print("mem_limit = ", mem_limit) nic_quota = vdc_resource.NicQuota print("nic_quota = ", nic_quota) network_quota = vdc_resource.NetworkQuota print("network_quota = ", network_quota) vm_quota = vdc_resource.VmQuota print("vm_quota = ", vm_quota) storage_profiles = str( vdc_resource.VdcStorageProfiles.VdcStorageProfile.get('name')) print("storage_profiles = ", storage_profiles) # res.resource_guaranteed_memory = str(vdc_resource.resource_guaranteed_memory) # res.resource_guaranteed_cpu = str(vdc_resource.resource_guaranteed_cpu) vcpu_in_mhz = vdc_resource.VCpuInMhz2 print("vcpu_in_mhz = ", vcpu_in_mhz) # res.is_thin_provision = str(vdc_resource.is_thin_provision) # res.network_pool_name = str(vdc_resource.network_pool_name) # res.uses_fast_provisioning = str(vdc_resource.uses_fast_provisioning) # res.over_commit_allowed = str(vdc_resource.over_commit_allowed) # res.vm_discovery_enabled = str(vdc_resource.vm_discovery_enabled) is_enabled = vdc_resource.IsEnabled print("is_enabled = ", is_enabled)
def create(client): print("=============== __LOG__Create_VDC =======================\n\n") vdc_name = "ACME_PAYG" vapp_name = "test2" org_resource = client.get_org() org = Org(client, resource=org_resource) print("Org name: ", org.get_name()) print("Vdc name: ", vdc_name) try: vdc_resource = org.get_vdc(vdc_name) vdc = VDC(client, name=vdc_name, resource=vdc_resource) vapp_resource = vdc.get_vapp(vapp_name) vapp = VApp(client, name=vapp_name, resource=vapp_resource) print("vapp : ", vapp) catalog_item = org.get_catalog_item('ACME', 'tinyova') source_vapp_resource = client.get_resource( catalog_item.Entity.get('href')) print("source_vapp_resource: ", source_vapp_resource) spec = { 'source_vm_name': 'Tiny Linux template', 'vapp': source_vapp_resource } storage_profiles = [{ 'name': 'Performance', 'enabled': True, 'units': 'MB', 'limit': 0, 'default': True }] spec['target_vm_name'] = 'ubuntu_pcp_11' spec['hostname'] = 'ubuntu' spec['network'] = 'global' spec['ip_allocation_mode'] = 'dhcp' #spec['storage_profile'] = storage_profiles vms = [spec] result = vapp.add_vms(vms) print("result: ", result) #task = client.get_task_monitor().wait_for_status( # task=result, # timeout=60, # poll_frequency=2, # fail_on_statuses=None, # expected_target_statuses=[ # TaskStatus.SUCCESS, # TaskStatus.ABORTED, # TaskStatus.ERROR, # TaskStatus.CANCELED], # callback=None) #st = task.get('status') #if st == TaskStatus.SUCCESS.value: # message = 'status : {0} '.format(st) # logging.info(message) #else: # print("st : ", st) # raise Exception(task) print("=============================================\n\n") return True except Exception as e: error_message = '__ERROR_ [create_vdc] failed for vdc {0} '.format( vdc_name) logging.warn(error_message, e) return False
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
client = Client(cfg.vcd_host, verify_ssl_certs=False, log_file='pyvcloud.log', log_requests=True, log_headers=True, log_bodies=True) client.set_highest_supported_version() client.set_credentials(BasicLoginCredentials(cfg.vcd_admin_user, "System", cfg.vcd_admin_password)) # Ensure the org exists. print("Fetching org...") try: # This call gets a record that we can turn into an Org class. org_record = client.get_org_by_name(cfg.org) org = Org(client, href=org_record.get('href')) print("Org already exists: {0}".format(org.get_name())) except Exception: print("Org does not exist, creating: {0}".format(cfg.org)) sys_admin_resource = client.get_admin() system = System(client, admin_resource=sys_admin_resource) admin_org_resource = system.create_org(cfg.org, "Test Org", True) org_record = client.get_org_by_name(cfg.org) org = Org(client, href=org_record.get('href')) print("Org now exists: {0}".format(org.get_name())) # Ensure user exists on the org. try: user_resource = org.get_user(cfg.user['name']) print("User already exists: {0}".format(cfg.user['name'])) except Exception: print("User does not exist, creating: {0}".format(cfg.user['name']))
def install_cse(ctx, config_file_name, template_name, no_capture, update, amqp_install, ext_install): check_config(config_file_name) click.secho('Installing CSE on vCD from file: %s, template: %s' % (config_file_name, template_name)) config = get_config(config_file_name) client = Client(config['vcd']['host'], api_version=config['vcd']['api_version'], verify_ssl_certs=config['vcd']['verify'], log_file='cse-install.log', log_headers=True, log_bodies=True) client.set_credentials( BasicLoginCredentials(config['vcd']['username'], 'System', config['vcd']['password'])) click.echo( 'Connected to vCloud Director as system ' 'administrator (%s:%s): %s' % (config['vcd']['host'], config['vcd']['port'], bool_to_msg(True))) click.secho('Installing \'%s\' service broker' % config['broker']['type']) if config['broker']['type'] == 'default': orgs = client.get_org_list() org_href = None for org in [o for o in orgs.Org if hasattr(orgs, 'Org')]: if org.get('name') == config['broker']['org']: org_href = org.get('href') org = Org(client, href=org_href) click.echo('Find org \'%s\': %s' % (org.get_name(), bool_to_msg(True))) vdc_resource = org.get_vdc(config['broker']['vdc']) click.echo('Find vdc \'%s\': %s' % (vdc_resource.get('name'), bool_to_msg(True))) try: catalog = org.get_catalog(config['broker']['catalog']) except Exception: click.secho('Creating catalog %s ' % config['broker']['catalog'], nl=False, fg='green') catalog = org.create_catalog(config['broker']['catalog'], 'CSE catalog') org.share_catalog(config['broker']['catalog']) click.secho('done', fg='blue') catalog = org.get_catalog(config['broker']['catalog']) click.echo( 'Find catalog \'%s\': %s' % (config['broker']['catalog'], bool_to_msg(catalog is not None))) for template in config['broker']['templates']: if template_name == '*' or template['name'] == template_name: click.secho('Processing template: %s' % template['name']) k8s_template = None try: k8s_template = org.get_catalog_item( config['broker']['catalog'], template['catalog_item']) click.echo( 'Find template \'%s\', \'%s\': %s' % (config['broker']['catalog'], template['catalog_item'], bool_to_msg(k8s_template is not None))) except Exception: pass try: if k8s_template is None or update: if update: click.secho('Updating template') else: click.secho('Creating template') create_template(ctx, config, client, org, vdc_resource, catalog, no_capture, template) k8s_template = org.get_catalog_item( config['broker']['catalog'], template['catalog_item']) if update: click.echo('Updated template \'%s\', \'%s\': %s' % (config['broker']['catalog'], template['catalog_item'], bool_to_msg(k8s_template is not None))) else: click.echo('Find template \'%s\', \'%s\': %s' % (config['broker']['catalog'], template['catalog_item'], bool_to_msg(k8s_template is not None))) except Exception: LOGGER.error(traceback.format_exc()) click.echo('Can\'t create or update template \'%s\' ' '\'%s\': %s' % (template['name'], config['broker']['catalog'], template['catalog_item'])) configure_amqp_settings(ctx, client, config, amqp_install) register_extension(ctx, client, config, ext_install) click.secho('Start CSE with: \'cse run %s\'' % config_file_name)
log_requests=cfg.logging.log_requests, log_headers=cfg.logging.log_headers, log_bodies=cfg.logging.log_bodies) client.set_highest_supported_version() client.set_credentials( BasicLoginCredentials(cfg.vcd.sys_admin_username, cfg.vcd.sys_org_name, cfg.vcd.sys_admin_pass)) # Ensure the org exists. print("Fetching the organization...") try: # This call gets a record that we can turn into an Org class. org_record = client.get_org_by_name(cfg.org.name) org = Org(client, href=org_record.get('href')) print("The organization {0} has been found".format(org.get_name())) except Exception: print("The organization {0} does not exist, exiting".format( org.get_name())) sys.exit() # Ensure VDC exists. print("Fetching the VDC...") try: vdc_resource = org.get_vdc(cfg.org.vdc_name) vdc = VDC(client, resource=vdc_resource) print("The VDC {0} has been found".format(cfg.org.vdc_name)) except Exception: print("The VDC {0} does not exist, exiting".format(cfg.org['vdc_name'])) sys.exit()