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 xrange(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
    def get_base_parser(self):
        parser = LibraClientArgumentParser(
            prog="libra",
            description=__doc__.strip(),
            epilog='See "libraclient 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=libraclient.__version__)

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

        parser.add_argument(
            "--no-cache",
            default=not strutils.bool_from_string(cliutils.env("OS_NO_CACHE", default="true")),
            action="store_false",
            dest="os_cache",
            help=argparse.SUPPRESS,
        )
        parser.add_argument("--no_cache", action="store_false", dest="os_cache", help=argparse.SUPPRESS)

        parser.add_argument(
            "--os-cache",
            default=cliutils.env("OS_CACHE", default=False),
            action="store_true",
            help="Use the auth token cache.",
        )

        parser.add_argument("--timings", default=False, action="store_true", help="Print call timing info")

        parser.add_argument(
            "--api-timeout",
            default=600,
            metavar="<seconds>",
            type=positive_non_zero_float,
            help="Set HTTP call timeout (in seconds)",
        )

        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-region-name",
            metavar="<region-name>",
            default=cliutils.env("OS_REGION_NAME", "LIBRA_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>",
            default=cliutils.env("LIBRA_SERVICE_TYPE", default=DEFAULT_SERVICE_TYPE),
            help="Defaults to libra for most actions",
        )
        parser.add_argument("--service_type", help=argparse.SUPPRESS)

        parser.add_argument(
            "--service-name",
            metavar="<service-name>",
            default=cliutils.env("LIBRA_SERVICE_NAME", default=DEFAULT_SERVICE_NAME),
            help="Defaults to env[LIBRA_SERVICE_NAME]",
        )
        parser.add_argument("--service_name", help=argparse.SUPPRESS)

        parser.add_argument(
            "--endpoint-type",
            metavar="<endpoint-type>",
            default=cliutils.env("LIBRA_ENDPOINT_TYPE", default=DEFAULT_ENDPOINT_TYPE),
            help="Defaults to env[LIBRA_ENDPOINT_TYPE] or " + DEFAULT_ENDPOINT_TYPE + ".",
        )

        parser.add_argument(
            "--libra-api-version",
            metavar="<compute-api-ver>",
            default=cliutils.env("LIBRA_API_VERSION", default=DEFAULT_API_VERSION),
            help="Accepts 1.1" "defaults to env[LIBRA_API_VERSION].",
        )
        parser.add_argument("--os_compute_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]",
        )

        parser.add_argument(
            "--insecure",
            default=cliutils.env("LIBRA_INSECURE", default=False),
            action="store_true",
            help='Explicitly allow libraclient 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.",
        )

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

        return parser
 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)