Esempio n. 1
0
    def __init__(self, config_path_param=None):
        if config_path_param is None:
            if os.environ.get('DKCLI_CONFIG_LOCATION') is not None:
                config_file_location = os.path.expandvars(
                    '${DKCLI_CONFIG_LOCATION}').strip()
            else:
                config_file_location = home + "/dev/DKCloudCommand/DKCloudCommand/DKCloudCommandConfig.json"
        else:
            config_file_location = config_path_param

        if not os.path.isfile(config_file_location):
            raise click.ClickException("Config file '%s' not found" %
                                       config_file_location)

        cfg = DKCloudCommandConfig()
        if not cfg.init_from_file(config_file_location):
            s = "Unable to load configuration from '%s'" % config_file_location
            raise click.ClickException(s)
        self.dki = DKCloudAPI(cfg)
        if self.dki is None:
            s = 'Unable to create and/or connect to backend object.'
            raise click.ClickException(s)
        token = self.dki.login()
        if token is None:
            s = 'login failed'
            raise click.ClickException(s)