Exemple #1
0
 def create(self,
            tnco_client: TNCOClient,
            ctx: click.Context,
            file_content: Dict = None,
            set_values: Dict = None,
            certificate: str = None):
     api = tnco_client.resource_drivers
     if file_content is not None:
         if set_values is not None and len(set_values) > 0:
             raise click.BadArgumentUsage(
                 message=
                 'Do not use "--set" option when using "-f, --file" option',
                 ctx=ctx)
         resource_driver = file_content
     else:
         resource_driver = set_values
     if certificate is not None:
         try:
             resource_driver['certificate'] = read_certificate_file(
                 certificate)
         except IOError as e:
             ctl = self._get_controller()
             ctl.io.print_error(f'Error: reading certificate: {str(e)}')
             exit(1)
     elif 'certificate' in resource_driver:
         resource_driver['certificate'] = fix_newlines_in_cert(
             resource_driver['certificate'])
     result = api.create(resource_driver)
     return result.get('id')
Exemple #2
0
def add(environment, config, pwd, inf_type, url, certificate, output_format):
    """Add a VIM driver"""
    vim_mgmt_driver = get_vim_driver_mgmt_driver(environment, config, pwd)
    new_vim_driver = {'infrastructureType': inf_type, 'baseUri': url}

    if certificate is not None:
        try:
            new_vim_driver['certificate'] = read_certificate_file(certificate)
        except IOError as e:
            click.echo('Error: reading certificate: {0}'.format(str(e)),
                       err=True)
            exit(1)

    with clirunners.lm_driver_safety():
        vim_driver = vim_mgmt_driver.add_vim_driver(new_vim_driver)
    click.echo(format_vim_driver(output_format, vim_driver))
Exemple #3
0
def add(environment, config, pwd, lifecycle_type, url, certificate, output_format):
    """Add a lifecycle driver"""
    lifecycle_mgmt_driver = get_lifecycle_driver_mgmt_driver(environment, config, pwd)
    new_lifecycle_driver = {
        'type': lifecycle_type,
        'baseUri': url
    }

    if certificate is not None:
        try:
            new_lifecycle_driver['certificate'] = read_certificate_file(certificate)
        except IOError as e:
            click.echo('Error: reading certificate: {0}'.format(str(e)), err=True)
            exit(1)

    with lm_driver_safety_net():
        lifecycle_driver = lifecycle_mgmt_driver.add_lifecycle_driver(new_lifecycle_driver)
    click.echo(format_lifecycle_driver(output_format, lifecycle_driver))
Exemple #4
0
def add(environment, config, pwd, driver_type, url, certificate,
        output_format):
    """Add a resource driver"""
    resource_mgmt_driver = get_resource_driver_mgmt_driver(
        environment, config, pwd)
    new_resource_driver = {'type': driver_type, 'baseUri': url}

    if certificate is not None:
        try:
            new_resource_driver['certificate'] = read_certificate_file(
                certificate)
        except IOError as e:
            click.echo('Error: reading certificate: {0}'.format(str(e)),
                       err=True)
            exit(1)

    with clirunners.lm_driver_safety():
        resource_driver = resource_mgmt_driver.add_resource_driver(
            new_resource_driver)
    click.echo(format_resource_driver(output_format, resource_driver))