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('VSMCLIENT_UUID_CACHE_DIR', default="~/.vsmclient") # NOTE(sirp): Keep separate UUID caches for each username + endpoint # pair username = utils.env('OS_USERNAME', 'VSM_USERNAME') url = utils.env('OS_URL', 'VSM_URL') uniqifier = hashlib.md5(username + url).hexdigest() cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier)) try: os.makedirs(cache_dir, 0755) except OSError: # NOTE(kiall): This is typicaly 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 typicaly 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 get_base_parser(self): parser = VsmClientArgumentParser( prog='vsm', description=__doc__.strip(), epilog='See "vsm help COMMAND" ' 'for help on a specific command.', 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=vsmclient.__version__) parser.add_argument('--debug', action='store_true', default=utils.env('VSMCLIENT_DEBUG', default=False), help="Print debugging output") parser.add_argument('--os-username', metavar='<auth-user-name>', default=utils.env('OS_USERNAME', 'VSM_USERNAME'), help='Defaults to env[OS_USERNAME].') parser.add_argument('--os_username', help=argparse.SUPPRESS) parser.add_argument('--os-password', metavar='<auth-password>', default=utils.env('OS_PASSWORD', 'VSM_PASSWORD'), help='Defaults to 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', 'VSM_PROJECT_ID'), help='Defaults to 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', 'VSM_TENANT_ID'), help='Defaults to 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', 'VSM_URL'), help='Defaults to env[OS_AUTH_URL].') parser.add_argument('--os_auth_url', help=argparse.SUPPRESS) parser.add_argument('--os-region-name', metavar='<region-name>', default=utils.env('OS_REGION_NAME', 'VSM_REGION_NAME'), help='Defaults to env[OS_REGION_NAME].') parser.add_argument('--os_region_name', help=argparse.SUPPRESS) parser.add_argument('--service-type', metavar='<service-type>', help='Defaults to compute for most actions') parser.add_argument('--service_type', help=argparse.SUPPRESS) parser.add_argument('--service-name', metavar='<service-name>', default=utils.env('VSM_SERVICE_NAME'), help='Defaults to env[VSM_SERVICE_NAME]') parser.add_argument('--service_name', help=argparse.SUPPRESS) parser.add_argument('--vsm-service-name', metavar='<vsm-service-name>', default=utils.env('VSM_VOLUME_SERVICE_NAME'), help='Defaults to env[VSM_VOLUME_SERVICE_NAME]') parser.add_argument('--vsm_service_name', help=argparse.SUPPRESS) parser.add_argument('--endpoint-type', metavar='<endpoint-type>', default=utils.env('VSM_ENDPOINT_TYPE', default=DEFAULT_VSM_ENDPOINT_TYPE), help='Defaults to env[VSM_ENDPOINT_TYPE] or ' + DEFAULT_VSM_ENDPOINT_TYPE + '.') parser.add_argument('--endpoint_type', help=argparse.SUPPRESS) parser.add_argument('--os-vsm-api-version', metavar='<compute-api-ver>', default=utils.env('OS_VOLUME_API_VERSION', default=DEFAULT_OS_VOLUME_API_VERSION), help='Accepts 1 or 2,defaults ' 'to env[OS_VOLUME_API_VERSION].') parser.add_argument('--os_vsm_api_version', 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('VSMCLIENT_INSECURE', default=False), action='store_true', help=argparse.SUPPRESS) parser.add_argument('--retries', metavar='<retries>', type=int, default=0, help='Number of retries.') # FIXME(dtroyer): The args below are here for diablo compatibility, # remove them in folsum cycle # alias for --os-username, left in for backwards compatibility parser.add_argument('--username', help=argparse.SUPPRESS) # alias for --os-region_name, left in for backwards compatibility parser.add_argument('--region_name', help=argparse.SUPPRESS) # alias for --os-password, left in for backwards compatibility parser.add_argument('--apikey', '--password', dest='apikey', default=utils.env('VSM_API_KEY'), help=argparse.SUPPRESS) # alias for --os-tenant-name, left in for backward compatibility parser.add_argument('--projectid', '--tenant_name', dest='projectid', default=utils.env('VSM_PROJECT_ID'), help=argparse.SUPPRESS) # alias for --os-auth-url, left in for backward compatibility parser.add_argument('--url', '--auth_url', dest='url', default=utils.env('VSM_URL'), help=argparse.SUPPRESS) return parser
def get_base_parser(self): parser = VsmClientArgumentParser( prog='vsm', description=__doc__.strip(), epilog='See "vsm help COMMAND" ' 'for help on a specific command.', 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=vsmclient.__version__, help="show program's version number and exit.") parser.add_argument('--debug', action='store_true', default=utils.env('VSMCLIENT_DEBUG', default=False), help="Print debugging output.") parser.add_argument('--os-username', metavar='<auth-user-name>', default=utils.env('OS_USERNAME', 'VSM_USERNAME'), help='Defaults to env[OS_USERNAME].') parser.add_argument('--os_username', help=argparse.SUPPRESS) parser.add_argument('--os-password', metavar='<auth-password>', default=utils.env('OS_PASSWORD', 'VSM_PASSWORD'), help='Defaults to 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', 'VSM_PROJECT_ID'), help='Defaults to 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', 'VSM_TENANT_ID'), help=argparse.SUPPRESS) # help='Defaults to 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', 'VSM_URL'), help='Defaults to env[OS_AUTH_URL].') parser.add_argument('--os_auth_url', help=argparse.SUPPRESS) parser.add_argument('--os-region-name', metavar='<region-name>', default=utils.env('OS_REGION_NAME', 'VSM_REGION_NAME'), help='Defaults to env[OS_REGION_NAME].') parser.add_argument('--os_region_name', help=argparse.SUPPRESS) parser.add_argument('--service-type', metavar='<service-type>', help=argparse.SUPPRESS) # help='Defaults to compute for most actions') parser.add_argument('--service_type', help=argparse.SUPPRESS) parser.add_argument('--service-name', metavar='<service-name>', default=utils.env('VSM_SERVICE_NAME'), help=argparse.SUPPRESS) # help='Defaults to env[VSM_SERVICE_NAME]') parser.add_argument('--service_name', help=argparse.SUPPRESS) parser.add_argument('--vsm-service-name', metavar='<vsm-service-name>', default=utils.env('VSM_VOLUME_SERVICE_NAME'), help=argparse.SUPPRESS) # help='Defaults to env[VSM_VOLUME_SERVICE_NAME]') parser.add_argument('--vsm_service_name', help=argparse.SUPPRESS) parser.add_argument('--endpoint-type', metavar='<endpoint-type>', default=utils.env('VSM_ENDPOINT_TYPE', default=DEFAULT_VSM_ENDPOINT_TYPE), help=argparse.SUPPRESS) # help='Defaults to env[VSM_ENDPOINT_TYPE] or ' # + DEFAULT_VSM_ENDPOINT_TYPE + '.') parser.add_argument('--endpoint_type', help=argparse.SUPPRESS) parser.add_argument('--os-vsm-api-version', metavar='<compute-api-ver>', default=utils.env('OS_VOLUME_API_VERSION', default=DEFAULT_OS_VOLUME_API_VERSION), help=argparse.SUPPRESS) # help='Accepts 1 or 2,defaults ' # 'to env[OS_VOLUME_API_VERSION].') parser.add_argument('--os_vsm_api_version', help=argparse.SUPPRESS) parser.add_argument('--os-cacert', metavar='<ca-certificate>', default=utils.env('OS_CACERT', default=None), help=argparse.SUPPRESS) # 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('VSMCLIENT_INSECURE', default=False), action='store_true', help=argparse.SUPPRESS) parser.add_argument('--retries', metavar='<retries>', type=int, default=0, help=argparse.SUPPRESS) # help='Number of retries.') # FIXME(dtroyer): The args below are here for diablo compatibility, # remove them in folsum cycle # alias for --os-username, left in for backwards compatibility parser.add_argument('--username', help=argparse.SUPPRESS) # alias for --os-region_name, left in for backwards compatibility parser.add_argument('--region_name', help=argparse.SUPPRESS) # alias for --os-password, left in for backwards compatibility parser.add_argument('--apikey', '--password', dest='apikey', default=utils.env('VSM_API_KEY'), help=argparse.SUPPRESS) # alias for --os-tenant-name, left in for backward compatibility parser.add_argument('--projectid', '--tenant_name', dest='projectid', default=utils.env('VSM_PROJECT_ID'), help=argparse.SUPPRESS) # alias for --os-auth-url, left in for backward compatibility parser.add_argument('--url', '--auth_url', dest='url', default=utils.env('VSM_URL'), help=argparse.SUPPRESS) return parser