def completion_cache(self, cache_type, obj_class, mode): """ The completion cache store items that can be used for bash autocompletion, like UUIDs or human-friendly IDs. A resource listing will clear and repopulate the cache. A resource create will append to the cache. Delete is not handled because listings are assumed to be performed often enough to keep the cache reasonably up-to-date. """ base_dir = utils.env('GUTSCLIENT_UUID_CACHE_DIR', default="~/.gutsclient") # NOTE(sirp): Keep separate UUID caches for each username + endpoint # pair username = utils.env('OS_USERNAME', 'GUTS_USERNAME') url = utils.env('OS_URL', 'GUTS_URL') uniqifier = hashlib.md5(username.encode('utf-8') + url.encode('utf-8')).hexdigest() cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier)) try: os.makedirs(cache_dir, 0o755) except OSError: # NOTE(kiall): This is typically either permission denied while # attempting to create the directory, or the directory # already exists. Either way, don't fail. pass resource = obj_class.__name__.lower() filename = "%s-%s-cache" % (resource, cache_type.replace('_', '-')) path = os.path.join(cache_dir, filename) cache_attr = "_%s_cache" % cache_type try: setattr(self, cache_attr, open(path, mode)) except IOError: # NOTE(kiall): This is typically a permission denied while # attempting to write the cache file. pass try: yield finally: cache = getattr(self, cache_attr, None) if cache: cache.close() delattr(self, cache_attr)
def _append_global_identity_args(self, parser): parser.add_argument( '--os-auth-strategy', metavar='<auth-strategy>', default=utils.env('OS_AUTH_STRATEGY', default='keystone'), help=_('Authentication strategy (Env: OS_AUTH_STRATEGY' ', default keystone). For now, any other value will' ' disable the authentication')) parser.add_argument( '--os_auth_strategy', help=argparse.SUPPRESS) parser.add_argument('--os-username', metavar='<auth-user-name>', default=utils.env('OS_USERNAME', 'GUTS_USERNAME'), help='OpenStack user name. ' 'Default=env[OS_USERNAME].') parser.add_argument('--os_username', help=argparse.SUPPRESS) parser.add_argument('--os-password', metavar='<auth-password>', default=utils.env('OS_PASSWORD', 'GUTS_PASSWORD'), help='Password for OpenStack user. ' 'Default=env[OS_PASSWORD].') parser.add_argument('--os_password', help=argparse.SUPPRESS) parser.add_argument('--os-tenant-name', metavar='<auth-tenant-name>', default=utils.env('OS_TENANT_NAME', 'GUTS_PROJECT_ID'), help='Tenant name. ' 'Default=env[OS_TENANT_NAME].') parser.add_argument('--os_tenant_name', help=argparse.SUPPRESS) parser.add_argument('--os-tenant-id', metavar='<auth-tenant-id>', default=utils.env('OS_TENANT_ID', 'GUTS_TENANT_ID'), help='ID for the tenant. ' 'Default=env[OS_TENANT_ID].') parser.add_argument('--os_tenant_id', help=argparse.SUPPRESS) parser.add_argument('--os-auth-url', metavar='<auth-url>', default=utils.env('OS_AUTH_URL', 'GUTS_URL'), help='URL for the authentication service. ' 'Default=env[OS_AUTH_URL].') parser.add_argument('--os_auth_url', help=argparse.SUPPRESS) parser.add_argument( '--os-user-id', metavar='<auth-user-id>', default=utils.env('OS_USER_ID'), help=_('Authentication user ID (Env: OS_USER_ID)')) parser.add_argument( '--os_user_id', help=argparse.SUPPRESS) parser.add_argument( '--os-user-domain-id', metavar='<auth-user-domain-id>', default=utils.env('OS_USER_DOMAIN_ID'), help='OpenStack user domain ID. ' 'Defaults to env[OS_USER_DOMAIN_ID].') parser.add_argument( '--os_user_domain_id', help=argparse.SUPPRESS) parser.add_argument( '--os-user-domain-name', metavar='<auth-user-domain-name>', default=utils.env('OS_USER_DOMAIN_NAME'), help='OpenStack user domain name. ' 'Defaults to env[OS_USER_DOMAIN_NAME].') parser.add_argument( '--os_user_domain_name', help=argparse.SUPPRESS) parser.add_argument( '--os-project-id', metavar='<auth-project-id>', default=utils.env('OS_PROJECT_ID'), help='Another way to specify tenant ID. ' 'This option is mutually exclusive with ' ' --os-tenant-id. ' 'Defaults to env[OS_PROJECT_ID].') parser.add_argument( '--os_project_id', help=argparse.SUPPRESS) parser.add_argument( '--os-project-name', metavar='<auth-project-name>', default=utils.env('OS_PROJECT_NAME'), help='Another way to specify tenant name. ' 'This option is mutually exclusive with ' ' --os-tenant-name. ' 'Defaults to env[OS_PROJECT_NAME].') parser.add_argument( '--os_project_name', help=argparse.SUPPRESS) parser.add_argument( '--os-project-domain-id', metavar='<auth-project-domain-id>', default=utils.env('OS_PROJECT_DOMAIN_ID'), help='Defaults to env[OS_PROJECT_DOMAIN_ID].') parser.add_argument( '--os-project-domain-name', metavar='<auth-project-domain-name>', default=utils.env('OS_PROJECT_DOMAIN_NAME'), help='Defaults to env[OS_PROJECT_DOMAIN_NAME].') parser.add_argument('--os-region-name', metavar='<region-name>', default=utils.env('OS_REGION_NAME', 'GUTS_REGION_NAME'), help='Region name. ' 'Default=env[OS_REGION_NAME].') parser.add_argument('--os_region_name', help=argparse.SUPPRESS) parser.add_argument( '--os-token', metavar='<token>', default=utils.env('OS_TOKEN'), help=_('Defaults to env[OS_TOKEN]')) parser.add_argument( '--os_token', help=argparse.SUPPRESS) parser.add_argument( '--os-url', metavar='<url>', default=utils.env('OS_URL'), help=_('Defaults to env[OS_URL]')) parser.add_argument( '--os_url', help=argparse.SUPPRESS) # Register the CLI arguments that have moved to the session object. session.Session.register_cli_options(parser) parser.set_defaults(insecure=utils.env('GUTSCLIENT_INSECURE', default=False))
def get_base_parser(self): parser = GutsClientArgumentParser( prog='guts', description=__doc__.strip(), epilog='Run "guts help SUBCOMMAND" for help on a subcommand.', add_help=False, formatter_class=OpenStackHelpFormatter, ) # Global arguments parser.add_argument('-h', '--help', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--version', action='version', version=gutsclient.__version__) parser.add_argument('-d', '--debug', action='store_true', default=utils.env('GUTSCLIENT_DEBUG', default=False), help="Shows debugging output.") parser.add_argument('--os-auth-system', metavar='<auth-system>', default=utils.env('OS_AUTH_SYSTEM'), help='Defaults to env[OS_AUTH_SYSTEM].') parser.add_argument('--os_auth_system', help=argparse.SUPPRESS) parser.add_argument('--service-type', metavar='<service-type>', help='Service type. ' 'For most actions, default is migration.') parser.add_argument('--service_type', help=argparse.SUPPRESS) parser.add_argument('--service-name', metavar='<service-name>', default=utils.env('GUTS_SERVICE_NAME'), help='Service name. ' 'Default=env[GUTS_SERVICE_NAME].') parser.add_argument('--service_name', help=argparse.SUPPRESS) parser.add_argument('--migration-service-name', metavar='<migration-service-name>', default=utils.env('GUTS_MIGRATION_SERVICE_NAME'), help='Migration service name. ' 'Default=env[GUTS_MIGRATION_SERVICE_NAME].') parser.add_argument('--migration_service_name', help=argparse.SUPPRESS) parser.add_argument('--endpoint-type', metavar='<endpoint-type>', dest='os_endpoint_type', default=utils.env('GUTS_ENDPOINT_TYPE', default=DEFAULT_GUTS_ENDPOINT_TYPE), help='DEPRECATED! Use --os-endpoint-type.') parser.add_argument('--endpoint_type', dest='os_endpoint_type', help=argparse.SUPPRESS) parser.add_argument('--os-endpoint-type', metavar='<os-endpoint-type>', default=utils.env('OS_ENDPOINT_TYPE', default=utils.env('GUTS_ENDPOINT_TYPE', default=DEFAULT_GUTS_ENDPOINT_TYPE)), help='Endpoint type, which is publicURL or ' 'internalURL. ' 'Default=env[OS_ENDPOINT_TYPE] or ' 'nova env[GUTS_ENDPOINT_TYPE] or ' + DEFAULT_GUTS_ENDPOINT_TYPE + '.') parser.add_argument('--os_endpoint_type', help=argparse.SUPPRESS) parser.add_argument('--os-migration-api-version', metavar='<migration-api-ver>', default=utils.env('OS_MIGRATION_API_VERSION', default=None), help='Block Storage API version. ' 'Valid values are 1 or 2. ' 'Default=env[OS_MIGRATION_API_VERSION].') parser.add_argument('--os_migration_api_version', help=argparse.SUPPRESS) parser.add_argument('--bypass-url', metavar='<bypass-url>', dest='bypass_url', default=utils.env('GUTSCLIENT_BYPASS_URL'), help="Use this API endpoint instead of the " "Service Catalog. Defaults to " "env[GUTSCLIENT_BYPASS_URL]") parser.add_argument('--bypass_url', help=argparse.SUPPRESS) parser.add_argument('--retries', metavar='<retries>', type=int, default=0, help='Number of retries.') if osprofiler_profiler: parser.add_argument('--profile', metavar='HMAC_KEY', help='HMAC key to use for encrypting context ' 'data for performance profiling of operation. ' 'This key needs to match the one configured ' 'on the guts api server. ' 'Without key the profiling will not be ' 'triggered even if osprofiler is enabled ' 'on server side.') self._append_global_identity_args(parser) # The auth-system-plugins might require some extra options gutsclient.auth_plugin.discover_auth_systems() gutsclient.auth_plugin.load_auth_system_opts(parser) return parser