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('CINDERCLIENT_UUID_CACHE_DIR', default="~/.brickclient") # NOTE(sirp): Keep separate UUID caches for each username + endpoint # pair username = utils.env('OS_USERNAME', 'CINDER_USERNAME') url = utils.env('OS_URL', 'CINDER_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): # FIXME(bklei): these are global identity (Keystone) arguments which # should be consistent and shared by all service clients. Therefore, # they should be provided by python-keystoneclient. We will need to # refactor this code once this functionality is available in # python-keystoneclient. 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', 'CINDER_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', 'CINDER_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', 'CINDER_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', 'CINDER_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', 'CINDER_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-cert', metavar='<certificate>', default=utils.env('OS_CERT'), help='Defaults to env[OS_CERT].') parser.add_argument( '--os-key', metavar='<key>', default=utils.env('OS_KEY'), help='Defaults to env[OS_KEY].') parser.add_argument('--os-region-name', metavar='<region-name>', default=utils.env('OS_REGION_NAME', 'CINDER_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) parser.add_argument( '--os-cacert', metavar='<ca-certificate>', default=utils.env('OS_CACERT', default=None), help=_("Specify a CA bundle file to use in " "verifying a TLS (https) server certificate. " "Defaults to env[OS_CACERT]")) parser.add_argument('--insecure', default=utils.env('CINDERCLIENT_INSECURE', default=False), action='store_true', help=argparse.SUPPRESS)
def get_base_parser(self): parser = BrickClientArgumentParser( prog='brick', description=__doc__.strip(), epilog='Run "brick 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=brickclient.__version__) parser.add_argument('--debug', action='store_true', default=utils.env('CINDERCLIENT_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 volume.') parser.add_argument('--service_type', help=argparse.SUPPRESS) parser.add_argument('--service-name', metavar='<service-name>', default=utils.env('CINDER_SERVICE_NAME'), help='Service name. ' 'Default=env[CINDER_SERVICE_NAME].') parser.add_argument('--service_name', help=argparse.SUPPRESS) parser.add_argument('--endpoint-type', metavar='<endpoint-type>', default=utils.env( 'CINDER_ENDPOINT_TYPE', default=DEFAULT_CINDER_ENDPOINT_TYPE), help='Endpoint type, which is publicURL or ' 'internalURL. ' 'Default=nova env[CINDER_ENDPOINT_TYPE] or ' + DEFAULT_CINDER_ENDPOINT_TYPE + '.') parser.add_argument('--endpoint_type', help=argparse.SUPPRESS) parser.add_argument('--retries', metavar='<retries>', type=int, default=0, help='Number of retries.') self._append_global_identity_args(parser) # The auth-system-plugins might require some extra options brickclient.auth_plugin.discover_auth_systems() brickclient.auth_plugin.load_auth_system_opts(parser) return parser