def run(self):
        access_token = self.auth_spec.get_access_token()
        if access_token is None:
            access_token = self.get_access_token()

        config_manager = ApplianceConfigManager(APPLIANCE_CONFIGS_BASE_DIR)
        profile = self.auth_spec.get_appliance_profile()
        if config_manager.is_config_present(profile):
            prompt = 'Found an existing appliance'
            if profile != DEFAULT_PROFILE:
                prompt += ' for profile %s' % profile
            prompt += '. Is it OK to overwrite it?'
            if not click.confirm(prompt):
                click.echo('Exiting...')
                sys.exit(-1)

        appliance_ip = self.auth_spec.get_appliance_ip()
        appliance_port = self.auth_spec.get_appliance_port()
        cert_fingerprint = self.auth_spec.get_cert_fingerprint()
        serial_id = self.auth_spec.get_serial_id()

        cert_manager = ApplianceCertManager((appliance_ip, appliance_port))

        appliance_config_spec = ApplianceConfigSpec(profile=profile,
                                                    endpoint=(appliance_ip, appliance_port),
                                                    access_token=access_token,
                                                    serial_id=serial_id)

        auth_manager = ApplianceAuthManager(appliance_config_spec, cert_fingerprint, config_manager, cert_manager)

        click.echo('Registering and initializing the authentication between the CLI and the appliance')
        auth_manager.initialize_auth()
Beispiel #2
0
def pa_list(ctx, from_json):
    result = []
    config_manager = ApplianceConfigManager(APPLIANCE_CONFIGS_BASE_DIR)
    for profile_name, config in config_manager.list_configs().items():
        result.append({
            ENDPOINT: config.get_appliance_url(),
            APPLIANCE_PROFILE: profile_name
        })
    cli_util.render(result, None, ctx)
def pa_unregister(ctx, from_json, appliance_profile):
    config_manager = ApplianceConfigManager(APPLIANCE_CONFIGS_BASE_DIR)
    config = config_manager.get_config(appliance_profile)
    if not click.confirm("Is it OK to unregister appliance with endpoint {}".format(config.get_appliance_url())):
        click.echo("Exiting...")
        sys.exit(-1)
    else:
        config_manager.delete_config(appliance_profile)
    click.echo("Unregistered the appliance")
Beispiel #4
0
    def __init__(self, ctx, appliance_profile):
        config_manager = ApplianceConfigManager(APPLIANCE_CONFIGS_BASE_DIR)
        appliance_config = config_manager.get_config(appliance_profile)
        self.auth_value = "{}:{}".format(APPLIANCE_AUTH_USER, appliance_config.get_access_token())
        self.serial_id = appliance_config.get_appliance_serial_id()

        config = cli_util.build_config(ctx.obj)
        host_name = appliance_config.get_appliance_url()
        self_signed_cert = "{}/{}".format(config_manager.get_config_dir(appliance_profile), APPLIANCE_CERT_FILE_NAME)
        self.nfs_dataset_client = NfsDatasetClient(
            config=config, service_endpoint=host_name, self_signed_cert=self_signed_cert)
Beispiel #5
0
 def _get_config_manager(self):
     return ApplianceConfigManager(self.test_dir)