예제 #1
0
def get_password(max_password_prompts=3):
    """Read password from TTY."""
    verify = strutils.bool_from_string(env("OS_VERIFY_PASSWORD"))
    pw = None
    if hasattr(sys.stdin, "isatty") and sys.stdin.isatty():
        # Check for Ctrl-D
        try:
            for __ in moves.range(max_password_prompts):
                pw1 = getpass.getpass("OS Password: "******"Please verify: ")
                else:
                    pw2 = pw1
                if pw1 == pw2 and pw1:
                    pw = pw1
                    break
        except EOFError:
            pass
    return pw
예제 #2
0
    def get_base_parser(self):
        parser = SaharaClientArgumentParser(
            prog='sahara',
            description=__doc__.strip(),
            epilog='See "sahara 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=version.version_info.version_string())

        parser.add_argument('--debug',
                            default=False,
                            action='store_true',
                            help="Print debugging output.")

        parser.add_argument('--os-cache',
                            default=strutils.bool_from_string(
                                cliutils.env('OS_CACHE', default=False)),
                            action='store_true',
                            help="Use the auth token cache. Defaults to False "
                            "if env[OS_CACHE] is not set.")

        # TODO(mattf) - add get_timings support to Client
        #        parser.add_argument('--timings',
        #            default=False,
        #            action='store_true',
        #            help="Print call timing info")

        # TODO(mattf) - use timeout
        #        parser.add_argument('--timeout',
        #            default=600,
        #            metavar='<seconds>',
        #            type=positive_non_zero_float,
        #            help="Set HTTP call timeout (in seconds)")

        parser.add_argument('--os-username',
                            metavar='<auth-user-name>',
                            default=cliutils.env('OS_USERNAME',
                                                 'SAHARA_USERNAME'),
                            help='Defaults to env[OS_USERNAME].')
        parser.add_argument('--os_username', help=argparse.SUPPRESS)

        parser.add_argument('--os-password',
                            metavar='<auth-password>',
                            default=cliutils.env('OS_PASSWORD',
                                                 'SAHARA_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=cliutils.env('OS_TENANT_NAME',
                                                 'SAHARA_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=cliutils.env('OS_TENANT_ID'),
                            help='Defaults to env[OS_TENANT_ID].')

        parser.add_argument('--os-auth-url',
                            metavar='<auth-url>',
                            default=cliutils.env('OS_AUTH_URL', 'SAHARA_URL'),
                            help='Defaults to env[OS_AUTH_URL].')
        parser.add_argument('--os_auth_url', help=argparse.SUPPRESS)

        # NA
        #        parser.add_argument('--os-region-name',
        #            metavar='<region-name>',
        #            default=utils.env('OS_REGION_NAME', 'SAHARA_REGION_NAME'),
        #            help='Defaults to env[OS_REGION_NAME].')
        #        parser.add_argument('--os_region_name',
        #            help=argparse.SUPPRESS)

        parser.add_argument('--os-auth-system',
                            metavar='<auth-system>',
                            default=cliutils.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='Defaults to data_processing for all '
                            'actions.')
        parser.add_argument('--service_type', help=argparse.SUPPRESS)

        # NA
        #        parser.add_argument('--service-name',
        #            metavar='<service-name>',
        #            default=utils.env('SAHARA_SERVICE_NAME'),
        #            help='Defaults to env[SAHARA_SERVICE_NAME]')
        #        parser.add_argument('--service_name',
        #            help=argparse.SUPPRESS)

        # NA
        #        parser.add_argument('--volume-service-name',
        #            metavar='<volume-service-name>',
        #            default=utils.env('NOVA_VOLUME_SERVICE_NAME'),
        #            help='Defaults to env[NOVA_VOLUME_SERVICE_NAME]')
        #        parser.add_argument('--volume_service_name',
        #            help=argparse.SUPPRESS)

        parser.add_argument('--endpoint-type',
                            metavar='<endpoint-type>',
                            default=cliutils.env(
                                'SAHARA_ENDPOINT_TYPE',
                                default=DEFAULT_ENDPOINT_TYPE),
                            help='Defaults to env[SAHARA_ENDPOINT_TYPE] or ' +
                            DEFAULT_ENDPOINT_TYPE + '.')
        # NOTE(dtroyer): We can't add --endpoint_type here due to argparse
        #                thinking usage-list --end is ambiguous; but it
        #                works fine with only --endpoint-type present
        #                Go figure.  I'm leaving this here for doc purposes.
        #parser.add_argument('--endpoint_type',
        #    help=argparse.SUPPRESS)

        parser.add_argument('--sahara-api-version',
                            metavar='<sahara-api-ver>',
                            default=cliutils.env('SAHARA_API_VERSION',
                                                 default=DEFAULT_API_VERSION),
                            help='Accepts "api", '
                            'defaults to env[SAHARA_API_VERSION].')
        parser.add_argument('--sahara_api_version', help=argparse.SUPPRESS)

        parser.add_argument('--os-cacert',
                            metavar='<ca-certificate>',
                            default=cliutils.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].')

        # NA
        #        parser.add_argument('--insecure',
        #            default=utils.env('NOVACLIENT_INSECURE', default=False),
        #            action='store_true',
        #            help="Explicitly allow novaclient to perform \"insecure\" "
        #                 "SSL (https) requests. The server's certificate will "
        #                 "not be verified against any certificate authorities. "
        #                 "This option should be used with caution.")

        parser.add_argument('--bypass-url',
                            metavar='<bypass-url>',
                            default=cliutils.env('BYPASS_URL', default=None),
                            dest='bypass_url',
                            help="Use this API endpoint instead of the "
                            "Service Catalog.")
        parser.add_argument('--bypass_url', help=argparse.SUPPRESS)

        # The auth-system-plugins might require some extra options
        nova_auth_plugin.load_auth_system_opts(parser)

        return parser
예제 #3
0
 def password(self):
     if self._validate_string(self.args.os_password):
         return self.args.os_password
     verify_pass = \
         strutils.bool_from_string(cliutils.env("OS_VERIFY_PASSWORD"))
     return self._prompt_password(verify_pass)