Beispiel #1
0
    def get_base_parser(self):
        parser = argparse.ArgumentParser(
            prog='ironic',
            description=__doc__.strip(),
            epilog=_('See "ironic help COMMAND" '
                     'for help on a specific command.'),
            add_help=False,
            formatter_class=HelpFormatter,
        )

        # Register global Keystone args first so their defaults are respected.
        # See https://bugs.launchpad.net/python-ironicclient/+bug/1463581
        kasession.register_argparse_arguments(parser)

        # Global arguments
        parser.add_argument(
            '-h',
            '--help',
            action='store_true',
            help=argparse.SUPPRESS,
        )

        parser.add_argument('--version',
                            action='version',
                            version=ironicclient.__version__)

        parser.add_argument('--debug',
                            default=bool(cliutils.env('IRONICCLIENT_DEBUG')),
                            action='store_true',
                            help=_('Defaults to env[IRONICCLIENT_DEBUG]'))

        parser.add_argument('--json',
                            default=False,
                            action='store_true',
                            help=_('Print JSON response without formatting.'))

        parser.add_argument('-v',
                            '--verbose',
                            default=False,
                            action="store_true",
                            help=_('Print more verbose output'))

        # for backward compatibility only
        parser.add_argument('--cert-file',
                            dest='os_cert',
                            help=_('DEPRECATED! Use --os-cert.'))

        # for backward compatibility only
        parser.add_argument('--key-file',
                            dest='os_key',
                            help=_('DEPRECATED! Use --os-key.'))

        # for backward compatibility only
        parser.add_argument('--ca-file',
                            dest='os_cacert',
                            help=_('DEPRECATED! Use --os-cacert.'))

        parser.add_argument('--os-username',
                            default=cliutils.env('OS_USERNAME'),
                            help=_('Defaults to env[OS_USERNAME]'))

        parser.add_argument('--os_username', help=argparse.SUPPRESS)

        parser.add_argument('--os-password',
                            default=cliutils.env('OS_PASSWORD'),
                            help=_('Defaults to env[OS_PASSWORD]'))

        parser.add_argument('--os_password', help=argparse.SUPPRESS)

        parser.add_argument('--os-tenant-id',
                            default=cliutils.env('OS_TENANT_ID'),
                            help=_('Defaults to env[OS_TENANT_ID]'))

        parser.add_argument('--os_tenant_id', help=argparse.SUPPRESS)

        parser.add_argument('--os-tenant-name',
                            default=cliutils.env('OS_TENANT_NAME'),
                            help=_('Defaults to env[OS_TENANT_NAME]'))

        parser.add_argument('--os_tenant_name', help=argparse.SUPPRESS)

        parser.add_argument('--os-auth-url',
                            default=cliutils.env('OS_AUTH_URL'),
                            help=_('Defaults to env[OS_AUTH_URL]'))

        parser.add_argument('--os_auth_url', help=argparse.SUPPRESS)

        parser.add_argument('--os-region-name',
                            default=cliutils.env('OS_REGION_NAME'),
                            help=_('Defaults to env[OS_REGION_NAME]'))

        parser.add_argument('--os_region_name', help=argparse.SUPPRESS)

        parser.add_argument('--os-auth-token',
                            default=cliutils.env('OS_AUTH_TOKEN'),
                            help=_('Defaults to env[OS_AUTH_TOKEN]'))

        parser.add_argument('--os_auth_token', help=argparse.SUPPRESS)

        parser.add_argument('--ironic-url',
                            default=cliutils.env('IRONIC_URL'),
                            help=_('Defaults to env[IRONIC_URL]'))

        parser.add_argument('--ironic_url', help=argparse.SUPPRESS)

        parser.add_argument('--ironic-api-version',
                            default=cliutils.env('IRONIC_API_VERSION',
                                                 default='1'),
                            help=_('Accepts 1.x (where "x" is microversion) '
                                   'or "latest", Defaults to '
                                   'env[IRONIC_API_VERSION] or 1'))

        parser.add_argument('--ironic_api_version', help=argparse.SUPPRESS)

        parser.add_argument('--os-service-type',
                            default=cliutils.env('OS_SERVICE_TYPE'),
                            help=_('Defaults to env[OS_SERVICE_TYPE] or '
                                   '"baremetal"'))

        parser.add_argument('--os_service_type', help=argparse.SUPPRESS)

        parser.add_argument('--os-endpoint',
                            dest='ironic_url',
                            default=cliutils.env('OS_SERVICE_ENDPOINT'),
                            help=_('Specify an endpoint to use instead of '
                                   'retrieving one from the service catalog '
                                   '(via authentication). '
                                   'Defaults to env[OS_SERVICE_ENDPOINT].'))

        parser.add_argument('--os_endpoint',
                            dest='ironic_url',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-endpoint-type',
                            default=cliutils.env('OS_ENDPOINT_TYPE'),
                            help=_('Defaults to env[OS_ENDPOINT_TYPE] or '
                                   '"publicURL"'))

        parser.add_argument('--os_endpoint_type', help=argparse.SUPPRESS)

        parser.add_argument('--os-user-domain-id',
                            default=cliutils.env('OS_USER_DOMAIN_ID'),
                            help=_('Defaults to env[OS_USER_DOMAIN_ID].'))

        parser.add_argument('--os-user-domain-name',
                            default=cliutils.env('OS_USER_DOMAIN_NAME'),
                            help=_('Defaults to env[OS_USER_DOMAIN_NAME].'))

        parser.add_argument('--os-project-id',
                            default=cliutils.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-name',
                            default=cliutils.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-domain-id',
                            default=cliutils.env('OS_PROJECT_DOMAIN_ID'),
                            help=_('Defaults to env[OS_PROJECT_DOMAIN_ID].'))

        parser.add_argument('--os-project-domain-name',
                            default=cliutils.env('OS_PROJECT_DOMAIN_NAME'),
                            help=_('Defaults to env[OS_PROJECT_DOMAIN_NAME].'))

        msg = _('Maximum number of retries in case of conflict error '
                '(HTTP 409). Defaults to env[IRONIC_MAX_RETRIES] or %d. '
                'Use 0 to disable retrying.') % http.DEFAULT_MAX_RETRIES
        parser.add_argument('--max-retries',
                            type=int,
                            help=msg,
                            default=cliutils.env(
                                'IRONIC_MAX_RETRIES',
                                default=str(http.DEFAULT_MAX_RETRIES)))

        msg = _('Amount of time (in seconds) between retries '
                'in case of conflict error (HTTP 409). '
                'Defaults to env[IRONIC_RETRY_INTERVAL] '
                'or %d.') % http.DEFAULT_RETRY_INTERVAL
        parser.add_argument('--retry-interval',
                            type=int,
                            help=msg,
                            default=cliutils.env(
                                'IRONIC_RETRY_INTERVAL',
                                default=str(http.DEFAULT_RETRY_INTERVAL)))

        return parser
Beispiel #2
0
    def populate_parser(parser):
        plugins = loading_base.get_available_plugin_names()
        default_auth = "v3password"

        parser.add_argument(
            "--os-auth-type",
            "--os-auth-plugin",
            metavar="<name>",
            default=utils.env("OS_AUTH_TYPE", default=default_auth),
            choices=plugins,
            help="Authentication type to use, available "
            "types are: %s" % ", ".join(plugins),
        )

        # arguments come from session and plugins
        loading_session.register_argparse_arguments(parser)
        for plugin_name in plugins:
            plugin = loading_base.get_plugin_loader(plugin_name)
            # NOTE(aloga): we do not want a project to be passed from the
            # CLI, as we will iterate over it for each configured VO and
            # project. However, as the plugin is expecting them when
            # parsing the arguments we need to set them to None before
            # calling the load_auth_from_argparse_arguments method in the
            # __init__ method of this class.
            for opt in filter(
                    lambda x: x.name not in ("project-name", "project-id"),
                    plugin.get_options(),
            ):
                parser.add_argument(*opt.argparse_args,
                                    default=opt.argparse_default,
                                    metavar="<auth-%s>" % opt.name,
                                    help=opt.help,
                                    dest="os_%s" % opt.dest.replace("-", "_"))

        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(
            "--os-cacert",
            metavar="<ca-certificate>",
            default=utils.env("OS_CACERT", default=requests.certs.where()),
            help="Specify a CA bundle file to use in "
            "verifying a TLS (https) server certificate. "
            "Defaults to env[OS_CACERT].",
        )

        parser.add_argument(
            "--os-cert",
            metavar="<certificate>",
            default=utils.env("OS_CERT", default=None),
            help="Defaults to env[OS_CERT].",
        )

        parser.add_argument(
            "--os-key",
            metavar="<key>",
            default=utils.env("OS_KEY", default=None),
            help="Defaults to env[OS_KEY].",
        )

        parser.add_argument(
            "--timeout",
            default=600,
            metavar="<seconds>",
            help="Set request timeout (in seconds).",
        )

        parser.add_argument(
            "--select-flavors",
            default="all",
            choices=["all", "public", "private"],
            help="Select all (default), public or private flavors/templates.",
        )

        parser.add_argument(
            "--all-images",
            action="store_true",
            default=False,
            help=("If set, include information about all images (including "
                  "snapshots), otherwise only publish images with cloudkeeper "
                  "metadata, ignoring the others."),
        )
Beispiel #3
0
    def populate_parser(parser):
        plugins = loading_base.get_available_plugin_names()
        default_auth = "v3password"

        parser.add_argument('--os-auth-type',
                            '--os-auth-plugin',
                            metavar='<name>',
                            default=utils.env('OS_AUTH_TYPE',
                                              default=default_auth),
                            choices=plugins,
                            help='Authentication type to use, available '
                                 'types are: %s' % ", ".join(plugins))

        # arguments come from session and plugins
        loading_session.register_argparse_arguments(parser)
        for plugin_name in plugins:
            plugin = loading_base.get_plugin_loader(plugin_name)
            # NOTE(aloga): we do not want a project to be passed from the
            # CLI, as we will iterate over it for each configured VO and
            # project. However, as the plugin is expecting them when
            # parsing the arguments we need to set them to None before
            # calling the load_auth_from_argparse_arguments method in the
            # __init__ method of this class.
            for opt in filter(lambda x: x.name not in ("project-name",
                                                       "project-id"),
                              plugin.get_options()):
                parser.add_argument(*opt.argparse_args,
                                    default=opt.argparse_default,
                                    metavar='<auth-%s>' % opt.name,
                                    help=opt.help,
                                    dest='os_%s' % opt.dest.replace("-", "_"))

        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(
            '--os-cacert',
            metavar='<ca-certificate>',
            default=utils.env('OS_CACERT', default=requests.certs.where()),
            help='Specify a CA bundle file to use in '
            'verifying a TLS (https) server certificate. '
            'Defaults to env[OS_CACERT].')

        parser.add_argument(
            '--os-cert',
            metavar='<certificate>',
            default=utils.env('OS_CERT', default=None),
            help='Defaults to env[OS_CERT].')

        parser.add_argument(
            '--os-key',
            metavar='<key>',
            default=utils.env('OS_KEY', default=None),
            help='Defaults to env[OS_KEY].')

        parser.add_argument(
            '--timeout',
            default=600,
            metavar='<seconds>',
            help='Set request timeout (in seconds).')

        parser.add_argument(
            '--select-flavors',
            default='all',
            choices=['all', 'public', 'private'],
            help='Select all (default), public or private flavors/templates.')

        parser.add_argument(
            '--all-images',
            action='store_true',
            default=False,
            help=('If set, include information about all images (including '
                  'snapshots), otherwise only publish images with cloudkeeper '
                  'metadata, ignoring the others.'))
    def get_base_parser(self):
        parser = argparse.ArgumentParser(
            prog='ironic',
            description=__doc__.strip(),
            epilog=_('See "ironic help COMMAND" '
                     'for help on a specific command.'),
            add_help=False,
            formatter_class=HelpFormatter,
        )

        # Register global Keystone args first so their defaults are respected.
        # See https://bugs.launchpad.net/python-ironicclient/+bug/1463581
        kasession.register_argparse_arguments(parser)

        # Global arguments
        parser.add_argument('-h', '--help',
                            action='store_true',
                            help=argparse.SUPPRESS,
                            )

        parser.add_argument('--version',
                            action='version',
                            version=ironicclient.__version__)

        parser.add_argument('--debug',
                            default=bool(cliutils.env('IRONICCLIENT_DEBUG')),
                            action='store_true',
                            help=_('Defaults to env[IRONICCLIENT_DEBUG]'))

        parser.add_argument('--json',
                            default=False,
                            action='store_true',
                            help=_('Print JSON response without formatting.'))

        parser.add_argument('-v', '--verbose',
                            default=False, action="store_true",
                            help=_('Print more verbose output'))

        # for backward compatibility only
        parser.add_argument('--cert-file',
                            dest='os_cert',
                            help=_('DEPRECATED! Use --os-cert.'))

        # for backward compatibility only
        parser.add_argument('--key-file',
                            dest='os_key',
                            help=_('DEPRECATED! Use --os-key.'))

        # for backward compatibility only
        parser.add_argument('--ca-file',
                            dest='os_cacert',
                            help=_('DEPRECATED! Use --os-cacert.'))

        parser.add_argument('--os-username',
                            default=cliutils.env('OS_USERNAME'),
                            help=_('Defaults to env[OS_USERNAME]'))

        parser.add_argument('--os_username',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-password',
                            default=cliutils.env('OS_PASSWORD'),
                            help=_('Defaults to env[OS_PASSWORD]'))

        parser.add_argument('--os_password',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-tenant-id',
                            default=cliutils.env('OS_TENANT_ID'),
                            help=_('Defaults to env[OS_TENANT_ID]'))

        parser.add_argument('--os_tenant_id',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-tenant-name',
                            default=cliutils.env('OS_TENANT_NAME'),
                            help=_('Defaults to env[OS_TENANT_NAME]'))

        parser.add_argument('--os_tenant_name',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-auth-url',
                            default=cliutils.env('OS_AUTH_URL'),
                            help=_('Defaults to env[OS_AUTH_URL]'))

        parser.add_argument('--os_auth_url',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-region-name',
                            default=cliutils.env('OS_REGION_NAME'),
                            help=_('Defaults to env[OS_REGION_NAME]'))

        parser.add_argument('--os_region_name',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-auth-token',
                            default=cliutils.env('OS_AUTH_TOKEN'),
                            help=_('Defaults to env[OS_AUTH_TOKEN]'))

        parser.add_argument('--os_auth_token',
                            help=argparse.SUPPRESS)

        parser.add_argument('--ironic-url',
                            default=cliutils.env('IRONIC_URL'),
                            help=_('Defaults to env[IRONIC_URL]'))

        parser.add_argument('--ironic_url',
                            help=argparse.SUPPRESS)

        parser.add_argument('--ironic-api-version',
                            default=cliutils.env(
                                'IRONIC_API_VERSION', default='1'),
                            help=_('Accepts 1.x (where "x" is microversion) '
                                   'or "latest", Defaults to '
                                   'env[IRONIC_API_VERSION] or 1'))

        parser.add_argument('--ironic_api_version',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-service-type',
                            default=cliutils.env('OS_SERVICE_TYPE'),
                            help=_('Defaults to env[OS_SERVICE_TYPE] or '
                                   '"baremetal"'))

        parser.add_argument('--os_service_type',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-endpoint',
                            dest='ironic_url',
                            default=cliutils.env('OS_SERVICE_ENDPOINT'),
                            help=_('Specify an endpoint to use instead of '
                                   'retrieving one from the service catalog '
                                   '(via authentication). '
                                   'Defaults to env[OS_SERVICE_ENDPOINT].'))

        parser.add_argument('--os_endpoint',
                            dest='ironic_url',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-endpoint-type',
                            default=cliutils.env('OS_ENDPOINT_TYPE'),
                            help=_('Defaults to env[OS_ENDPOINT_TYPE] or '
                                   '"publicURL"'))

        parser.add_argument('--os_endpoint_type',
                            help=argparse.SUPPRESS)

        parser.add_argument('--os-user-domain-id',
                            default=cliutils.env('OS_USER_DOMAIN_ID'),
                            help=_('Defaults to env[OS_USER_DOMAIN_ID].'))

        parser.add_argument('--os-user-domain-name',
                            default=cliutils.env('OS_USER_DOMAIN_NAME'),
                            help=_('Defaults to env[OS_USER_DOMAIN_NAME].'))

        parser.add_argument('--os-project-id',
                            default=cliutils.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-name',
                            default=cliutils.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-domain-id',
                            default=cliutils.env('OS_PROJECT_DOMAIN_ID'),
                            help=_('Defaults to env[OS_PROJECT_DOMAIN_ID].'))

        parser.add_argument('--os-project-domain-name',
                            default=cliutils.env('OS_PROJECT_DOMAIN_NAME'),
                            help=_('Defaults to env[OS_PROJECT_DOMAIN_NAME].'))

        msg = _('Maximum number of retries in case of conflict error '
                '(HTTP 409). Defaults to env[IRONIC_MAX_RETRIES] or %d. '
                'Use 0 to disable retrying.') % http.DEFAULT_MAX_RETRIES
        parser.add_argument('--max-retries', type=int, help=msg,
                            default=cliutils.env(
                                'IRONIC_MAX_RETRIES',
                                default=str(http.DEFAULT_MAX_RETRIES)))

        msg = _('Amount of time (in seconds) between retries '
                'in case of conflict error (HTTP 409). '
                'Defaults to env[IRONIC_RETRY_INTERVAL] '
                'or %d.') % http.DEFAULT_RETRY_INTERVAL
        parser.add_argument('--retry-interval', type=int, help=msg,
                            default=cliutils.env(
                                'IRONIC_RETRY_INTERVAL',
                                default=str(http.DEFAULT_RETRY_INTERVAL)))

        return parser
Beispiel #5
0
    def populate_parser(parser):
        plugins = loading_base.get_available_plugin_names()
        default_auth = "v3password"

        parser.add_argument('--os-auth-type',
                            '--os-auth-plugin',
                            metavar='<name>',
                            default=utils.env('OS_AUTH_TYPE',
                                              default=default_auth),
                            choices=plugins,
                            help='Authentication type to use, available '
                            'types are: %s' % ", ".join(plugins))

        # arguments come from session and plugins
        loading_session.register_argparse_arguments(parser)
        for plugin_name in plugins:
            plugin = loading_base.get_plugin_loader(plugin_name)
            for opt in plugin.get_options():
                # NOTE(aloga): we do not want a project to be passed from the
                # CLI, as we will iterate over it for each configured VO and
                # project. However, as the plugin is expecting them when
                # parsing the arguments we need to set them to None before
                # calling the load_auth_from_argparse_arguments method in the
                # __init__ method of this class.
                if opt.name in ("project-name", "project-id"):
                    continue

                parser.add_argument(*opt.argparse_args,
                                    default=opt.argparse_default,
                                    metavar='<auth-%s>' % opt.name,
                                    help=opt.help,
                                    dest='os_%s' % opt.dest.replace("-", "_"))

        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('--os-cacert',
                            metavar='<ca-certificate>',
                            default=utils.env('OS_CACERT',
                                              default=requests.certs.where()),
                            help='Specify a CA bundle file to use in '
                            'verifying a TLS (https) server certificate. '
                            'Defaults to env[OS_CACERT].')

        parser.add_argument('--os-cert',
                            metavar='<certificate>',
                            default=utils.env('OS_CERT', default=None),
                            help='Defaults to env[OS_CERT].')

        parser.add_argument('--os-key',
                            metavar='<key>',
                            default=utils.env('OS_KEY', default=None),
                            help='Defaults to env[OS_KEY].')

        parser.add_argument('--timeout',
                            default=600,
                            metavar='<seconds>',
                            help='Set request timeout (in seconds).')

        parser.add_argument(
            '--select-flavors',
            default='all',
            choices=['all', 'public', 'private'],
            help='Select all (default), public or private flavors/templates.')

        parser.add_argument(
            '--all-images',
            action='store_true',
            default=False,
            help=('If set, include information about all images (including '
                  'snapshots), otherwise only publish images with cloudkeeper '
                  'metadata, ignoring the others.'))