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'])
api_version='31.0', verify_ssl_certs=False, log_file='pyvcloud.log', log_requests=True, log_headers=True, log_bodies=True) # Update with valid administrator's credentials client.set_credentials( BasicLoginCredentials(os.environ['VCD_USER'], 'SYSTEM', os.environ['VCD_PASSWORD'])) # print(client.is_sysadmin()) # Retrieve the list of all organizations ---------------------------------------------------------- orgs = client.get_org_list() # Iterate over Organizations - 1st GO to print table of Organizations orgtable = PrettyTable(["Organization name", "href"]) for o in orgs: # print(o.attrib['name']) # print(o.get('name')) # print(o.get('href')) orgtable.add_row([o.get('name'), o.get('href')]) cprint('Print all Organizations', 'yellow') print(orgtable) # Iterate over Organizations - 2nd GO to retrieve data about VDCs --------------------------------- for o in orgs: cprint( '\nOrganization ' + o.attrib['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)