Пример #1
0
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _(
            'if "true", the repository will be published over the HTTP protocol'
        )
        self.opt_http = PulpCliOption('--serve-http',
                                      d,
                                      required=False,
                                      parse_func=parsers.parse_boolean)
        d = _(
            'if "true", the repository will be published over the HTTPS protocol'
        )
        self.opt_https = PulpCliOption('--serve-https',
                                       d,
                                       required=False,
                                       parse_func=parsers.parse_boolean)
        d = _(
            'full path to the CA certificate that should be used to verify client authorization '
            'certificates; setting this turns on client authorization for the repository'
        )
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)
        d = _(
            'relative path the repository will be served from. Only alphanumeric characters, '
            'forward slashes, underscores, and dashes are allowed.')
        self.opt_relative_url = PulpCliOption('--relative-url',
                                              d,
                                              required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)
        self.publishing_group.add_option(self.opt_relative_url)

        self.add_option_group(self.publishing_group)
Пример #2
0
    def __init__(self, context, renderer, distributor_id, name='run', description=DESC_PUBLISH_RUN,
                 method=None, override_config_options=()):
        """
        :param context: Pulp client context
        :type context: See okaara

        :param renderer: StatusRenderer subclass that will interpret the sync or publish progress
                         report
        :type  renderer: StatusRenderer

        :param distributor_id: Id of a distributor to be used for publishing
        :type distributor_id: str

        :param override_config_options: Additional publish options to be accepted from user. These
                                        options will override respective options from the default
                                        publish config. Each entry should be either a PulpCliOption
                                        or PulpCliFlag instance
        :type override_config_options: list
        """
        super(RunPublishRepositoryCommand, self).__init__(name, description, method, context,
                                                          renderer)

        self.distributor_id = distributor_id
        self.override_config_keywords = []

        # Process and add config override options in their own group and save option keywords
        if override_config_options:
            override_config_group = PulpCliOptionGroup(_("Publish Options"))
            self.add_option_group(override_config_group)

            for option in override_config_options:
                override_config_group.add_option(option)
                self.override_config_keywords.append(option.keyword)
Пример #3
0
def add_erratum_group(command):
    """
    Adds the erratum group and all of its options to the given command.
    """
    erratum_group = PulpCliOptionGroup(_('Erratum'))
    erratum_group.add_option(PulpCliOption('--erratum-id', _('if specified, the full details of an individual erratum are displayed'), required=False))
    command.add_option_group(erratum_group)
Пример #4
0
def add_required_group(command):
    """
    Adds the required group and all of its options to the given command.
    """
    required_group = PulpCliOptionGroup(_('Required'))
    required_group.add_option(PulpCliOption('--repo-id', _('identifies the repository to search within'), required=True))
    command.add_option_group(required_group)
Пример #5
0
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _(
            'if "true", the repository will be published over the HTTP protocol'
        )
        self.opt_http = PulpCliOption('--serve-http',
                                      d,
                                      required=False,
                                      parse_func=parsers.parse_boolean)
        d = _(
            'if "true", the repository will be published over the HTTPS protocol'
        )
        self.opt_https = PulpCliOption('--serve-https',
                                       d,
                                       required=False,
                                       parse_func=parsers.parse_boolean)
        d = _(
            'full path to the CA certificate that should be used to verify client authorization '
            'certificates; setting this turns on client authorization for the repository'
        )
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)

        self.add_option_group(self.publishing_group)
Пример #6
0
def add_pagination_group(command):
    """
    Adds the pagination group and all of its options to the given command.
    """
    pagination_group = PulpCliOptionGroup(_('Pagination'))
    pagination_group.add_option(PulpCliOption('--limit', _('maximum number of results to display'), aliases=['-l'], required=False))
    pagination_group.add_option(PulpCliOption('--skip', _('number of results to skip'), aliases=['-s'], required=False))
    command.add_option_group(pagination_group)
Пример #7
0
    def __init__(self, context):
        super(SearchErrataCommand, self).__init__(self.errata, context, name='errata',
                                                  description=DESC_ERRATA)

        erratum_group = PulpCliOptionGroup(_('Erratum'))

        m = _('if specified, the full details of an individual erratum are '
              'displayed, and all other options are ignored except for '
              '--repo-id.')
        erratum_group.add_option(PulpCliOption('--erratum-id', m, required=False))
        self.add_option_group(erratum_group)
Пример #8
0
class ISODistributorConfigMixin(object):
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _(
            'if "true", the repository will be published over the HTTP protocol'
        )
        self.opt_http = PulpCliOption('--serve-http',
                                      d,
                                      required=False,
                                      parse_func=parsers.parse_boolean)
        d = _(
            'if "true", the repository will be published over the HTTPS protocol'
        )
        self.opt_https = PulpCliOption('--serve-https',
                                       d,
                                       required=False,
                                       parse_func=parsers.parse_boolean)
        d = _(
            'full path to the CA certificate that should be used to verify client authorization '
            'certificates; setting this turns on client authorization for the repository'
        )
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)
        d = _(
            'relative path the repository will be served from. Only alphanumeric characters, '
            'forward slashes, underscores, and dashes are allowed.')
        self.opt_relative_url = PulpCliOption('--relative-url',
                                              d,
                                              required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)
        self.publishing_group.add_option(self.opt_relative_url)

        self.add_option_group(self.publishing_group)

    def _parse_distributor_config(self, user_input):
        """
        Generate an ISODistributor configuration based on the given parameters (user input).

        :param user_input: The keys and values passed to the CLI by the user
        :type  user_input: dict
        """
        key_tuples = (
            (constants.CONFIG_SERVE_HTTP, self.opt_http.keyword),
            (constants.CONFIG_SERVE_HTTPS, self.opt_https.keyword),
            (constants.CONFIG_SSL_AUTH_CA_CERT, self.opt_auth_ca.keyword),
            (constants.CONFIG_RELATIVE_URL, self.opt_relative_url.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)

        arg_utils.convert_file_contents((constants.CONFIG_SSL_AUTH_CA_CERT, ),
                                        config)

        return config
Пример #9
0
    def __init__(self,
                 name,
                 description,
                 method,
                 context,
                 renderer,
                 override_config_options=()):
        """
        Initialize the command, and call the superclass __init__().

        :param name:        The name of the command
        :type  name:        basestring
        :param description: The description of the command
        :type  description: basestring
        :param method:      The method to be run if the command is used
        :type  method:      callable
        :param context:     The CLI context from Okaara
        :type  context:     pulp.client.extensions.core.ClientContext
        :param renderer:    The renderer to be used to print progress reports
        :type  renderer:    StatusRenderer
        :param override_config_options: Additional options to be accepted from the user. These
                                        options will override respective options from the default
                                        config. Each entry should be either a PulpCliOption
                                        or PulpCliFlag instance
        :type override_config_options: tuple
        """
        if method is None:
            method = self.run

        super(SyncPublishCommand, self).__init__(name, description, method,
                                                 context)

        self.renderer = renderer
        self.add_option(options.OPTION_REPO_ID)
        self.context = context
        self.prompt = context.prompt
        self.override_config_keywords = []

        # Process and add config override options in their own group and save option keywords
        if override_config_options:
            override_config_group = PulpCliOptionGroup(_("Options"))
            self.add_option_group(override_config_group)

            for option in override_config_options:
                override_config_group.add_option(option)
                self.override_config_keywords.append(option.keyword)
Пример #10
0
    def __init__(self,
                 context,
                 renderer,
                 distributor_id,
                 name='run',
                 description=DESC_PUBLISH_RUN,
                 method=None,
                 override_config_options=()):
        """
        :param context: Pulp client context
        :type context: See okaara

        :param renderer: StatusRenderer subclass that will interpret the sync or publish progress report
        :type  renderer: StatusRenderer

        :param distributor_id: Id of a distributor to be used for publishing
        :type distributor_id: str

        :param override_config_options: Additional publish options to be accepted from user. These options will override 
            respective options from the default publish config. Each entry should be
            either a PulpCliOption or PulpCliFlag instance
        :type override_config_options: list
        """
        if method is None:
            method = self.run

        super(RunPublishRepositoryCommand,
              self).__init__(name, description, method)

        self.context = context
        self.prompt = context.prompt
        self.renderer = renderer
        self.distributor_id = distributor_id
        self.override_config_keywords = []

        self.add_option(options.OPTION_REPO_ID)
        self.create_flag('--' + NAME_BACKGROUND, DESC_BACKGROUND)

        # Process and add config override options in their own group and save option keywords
        if override_config_options:
            override_config_group = PulpCliOptionGroup(_("Publish Options"))
            self.add_option_group(override_config_group)

            for option in override_config_options:
                override_config_group.add_option(option)
                self.override_config_keywords.append(option.keyword)
Пример #11
0
def add_distributor_config_to_command(command):
    """
    Adds the repository configuration related options to the given command,
    organizing them into the appropriate groups.

    :param command: command to add options to
    :type  command: pulp.clients.extensions.extensions.PulpCliCommand
    """

    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)

    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)
    publish_group.add_option(OPT_PUBLISH_DEFAULT_RELEASE)

    # Order added indicates order in usage, so pay attention to this order
    # when dorking with it to make sure it makes sense
    command.add_option_group(publish_group)
Пример #12
0
    def __init__(
        self,
        options_bundle=None,
        include_sync=True,
        include_ssl=True,
        include_proxy=True,
        include_throttling=True,
        include_unit_policy=True,
    ):

        # If the caller didn't dork with any of the options, instantiate one with the defaults
        self.options_bundle = options_bundle or OptionsBundle()

        # Created now, but won't be added to the command until the include_* flags are checked.
        # Stored as instance variables so a class using this mixin can further manipulate them.
        self.sync_group = PulpCliOptionGroup(GROUP_NAME_SYNC)
        self.ssl_group = PulpCliOptionGroup(GROUP_NAME_SSL)
        self.proxy_group = PulpCliOptionGroup(GROUP_NAME_PROXY)
        self.throttling_group = PulpCliOptionGroup(GROUP_NAME_THROTTLING)
        self.unit_policy_group = PulpCliOptionGroup(GROUP_NAME_UNIT_POLICY)

        if include_sync:
            self.populate_sync_group()
            self.add_option_group(self.sync_group)

        if include_ssl:
            self.populate_ssl_group()
            self.add_option_group(self.ssl_group)

        if include_proxy:
            self.populate_proxy_group()
            self.add_option_group(self.proxy_group)

        if include_throttling:
            self.populate_throttling_group()
            self.add_option_group(self.throttling_group)

        if include_unit_policy:
            self.populate_unit_policy()
            self.add_option_group(self.unit_policy_group)
Пример #13
0
    def __init__(self, name, description, method, context, renderer, override_config_options=()):
        """
        Initialize the command, and call the superclass __init__().

        :param name:        The name of the command
        :type  name:        basestring
        :param description: The description of the command
        :type  description: basestring
        :param method:      The method to be run if the command is used
        :type  method:      callable
        :param context:     The CLI context from Okaara
        :type  context:     pulp.client.extensions.core.ClientContext
        :param renderer:    The renderer to be used to print progress reports
        :type  renderer:    StatusRenderer
        :param override_config_options: Additional options to be accepted from the user. These
                                        options will override respective options from the default
                                        config. Each entry should be either a PulpCliOption
                                        or PulpCliFlag instance
        :type override_config_options: tuple
        """
        if method is None:
            method = self.run

        super(SyncPublishCommand, self).__init__(name, description, method, context)

        self.renderer = renderer
        self.add_option(options.OPTION_REPO_ID)
        self.context = context
        self.prompt = context.prompt
        self.override_config_keywords = []

        # Process and add config override options in their own group and save option keywords
        if override_config_options:
            override_config_group = PulpCliOptionGroup(_("Options"))
            self.add_option_group(override_config_group)

            for option in override_config_options:
                override_config_group.add_option(option)
                self.override_config_keywords.append(option.keyword)
Пример #14
0
    def __init__(self,
                 options_bundle=None,
                 include_sync=True,
                 include_ssl=True,
                 include_proxy=True,
                 include_throttling=True,
                 include_unit_policy=True):

        # If the caller didn't dork with any of the options, instantiate one with the defaults
        self.options_bundle = options_bundle or OptionsBundle()

        # Created now, but won't be added to the command until the include_* flags are checked.
        # Stored as instance variables so a class using this mixin can further manipulate them.
        self.sync_group = PulpCliOptionGroup(GROUP_NAME_SYNC)
        self.ssl_group = PulpCliOptionGroup(GROUP_NAME_SSL)
        self.proxy_group = PulpCliOptionGroup(GROUP_NAME_PROXY)
        self.throttling_group = PulpCliOptionGroup(GROUP_NAME_THROTTLING)
        self.unit_policy_group = PulpCliOptionGroup(GROUP_NAME_UNIT_POLICY)

        if include_sync:
            self.populate_sync_group()
            self.add_option_group(self.sync_group)

        if include_ssl:
            self.populate_ssl_group()
            self.add_option_group(self.ssl_group)

        if include_proxy:
            self.populate_proxy_group()
            self.add_option_group(self.proxy_group)

        if include_throttling:
            self.populate_throttling_group()
            self.add_option_group(self.throttling_group)

        if include_unit_policy:
            self.populate_unit_policy()
            self.add_option_group(self.unit_policy_group)
Пример #15
0
    def __init__(self, context, renderer, distributor_id, name='run', description=DESC_PUBLISH_RUN, 
                 method=None, override_config_options=[]):
        """
        :param context: Pulp client context
        :type context: See okaara

        :param renderer: StatusRenderer subclass that will interpret the sync or publish progress report
        :type  renderer: StatusRenderer

        :param distributor_id: Id of a distributor to be used for publishing
        :type distributor_id: str

        :param override_config_options: Additional publish options to be accepted from user. These options will override 
                                        respective options from the default publish config.
        :type override_config_options: List of PulpCliOption and PulpCliFlag instances 
        """
        if method is None:
            method = self.run

        super(RunPublishRepositoryCommand, self).__init__(name, description, method)

        self.context = context
        self.prompt = context.prompt
        self.renderer = renderer
        self.distributor_id = distributor_id
        self.override_config_keywords = []

        self.add_option(options.OPTION_REPO_ID)
        self.create_flag('--' + NAME_BACKGROUND, DESC_BACKGROUND)

        # Process and add config override options in their own group and save option keywords
        if override_config_options:
            override_config_group = PulpCliOptionGroup(_("Publish Options"))
            self.add_option_group(override_config_group)

            for option in override_config_options:
                override_config_group.add_option(option)
                self.override_config_keywords.append(option.keyword)
Пример #16
0
def add_display_group(command, default_fields):
    """
    Adds the display group and all of its options to the given command.
    """
    d  = 'comma-separated list of fields to include for each unit; if unspecified all of the following will be displayed; '
    d += 'valid fields: %(f)s'
    description = _(d) % {'f' : ', '.join(default_fields)}

    display_group = PulpCliOptionGroup(_('Display'))
    display_group.add_option(PulpCliOption('--fields', description, aliases=['-f'], required=False, default=','.join(default_fields)))
    display_group.add_option(PulpCliOption('--ascending', _('comma-separated list of fields to sort ascending; the order of the fields determines the order priority'), aliases=['-a'], required=False))
    display_group.add_option(PulpCliOption('--descending', _('comma-separated list of fields to sort descending; ignored if --ascending is specified'), aliases=['-d'], required=False))
    command.add_option_group(display_group)
Пример #17
0
class ISODistributorConfigMixin(object):
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _('if "true", the repository will be published over the HTTP protocol')
        self.opt_http = PulpCliOption('--serve-http', d, required=False,
                                      parse_func=parsers.parse_boolean)
        d = _('if "true", the repository will be published over the HTTPS protocol')
        self.opt_https = PulpCliOption('--serve-https', d, required=False,
                                       parse_func=parsers.parse_boolean)
        d = _('full path to the CA certificate that should be used to verify client authorization '
              'certificates; setting this turns on client authorization for the repository')
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)
        d = _(
            'relative path the repository will be served from. Only alphanumeric characters, '
            'forward slashes, underscores, and dashes are allowed.')
        self.opt_relative_url = PulpCliOption('--relative-url', d, required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)
        self.publishing_group.add_option(self.opt_relative_url)

        self.add_option_group(self.publishing_group)

    def _parse_distributor_config(self, user_input):
        """
        Generate an ISODistributor configuration based on the given parameters (user input).

        :param user_input: The keys and values passed to the CLI by the user
        :type  user_input: dict
        """
        key_tuples = (
            (constants.CONFIG_SERVE_HTTP, self.opt_http.keyword),
            (constants.CONFIG_SERVE_HTTPS, self.opt_https.keyword),
            (constants.CONFIG_SSL_AUTH_CA_CERT, self.opt_auth_ca.keyword),
            (constants.CONFIG_RELATIVE_URL, self.opt_relative_url.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)

        arg_utils.convert_file_contents((constants.CONFIG_SSL_AUTH_CA_CERT,), config)

        return config
Пример #18
0
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _('if "true", the repository will be published over the HTTP protocol')
        self.opt_http = PulpCliOption('--serve-http', d, required=False,
                                      parse_func=parsers.parse_boolean)
        d = _('if "true", the repository will be published over the HTTPS protocol')
        self.opt_https = PulpCliOption('--serve-https', d, required=False,
                                       parse_func=parsers.parse_boolean)
        d = _('full path to the CA certificate that should be used to verify client authorization '
              'certificates; setting this turns on client authorization for the repository')
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)

        self.add_option_group(self.publishing_group)
Пример #19
0
def add_distributor_config_to_command(command):
    """
    Adds the repository configuration related options to the given command,
    organizing them into the appropriate groups.

    :param command: command to add options to
    :type  command: pulp.clients.extensions.extensions.PulpCliCommand
    """

    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)

    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)

    # Order added indicates order in usage, so pay attention to this order
    # when dorking with it to make sure it makes sense
    command.add_option_group(publish_group)
Пример #20
0
    def __init__(self):
        self.publishing_group = PulpCliOptionGroup(_('Publishing'))

        d = _('if "true", the repository will be published over the HTTP protocol')
        self.opt_http = PulpCliOption('--serve-http', d, required=False,
                                      parse_func=parsers.parse_boolean)
        d = _('if "true", the repository will be published over the HTTPS protocol')
        self.opt_https = PulpCliOption('--serve-https', d, required=False,
                                       parse_func=parsers.parse_boolean)
        d = _('full path to the CA certificate that should be used to verify client authorization '
              'certificates; setting this turns on client authorization for the repository')
        self.opt_auth_ca = PulpCliOption('--auth-ca', d, required=False)
        d = _(
            'relative path the repository will be served from. Only alphanumeric characters, '
            'forward slashes, underscores, and dashes are allowed.')
        self.opt_relative_url = PulpCliOption('--relative-url', d, required=False)

        self.publishing_group.add_option(self.opt_http)
        self.publishing_group.add_option(self.opt_https)
        self.publishing_group.add_option(self.opt_auth_ca)
        self.publishing_group.add_option(self.opt_relative_url)

        self.add_option_group(self.publishing_group)
Пример #21
0
def add_to_command(command):
    """
    Adds the repository configuration related options to the given command,
    organizing them into the appropriate groups.

    :param command: command to add options to
    :type  command: pulp.clients.extensions.extensions.PulpCliCommand
    """

    # Groups
    basic_group = PulpCliOptionGroup(NAME_BASIC)
    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)

    # Order added indicates order in usage, so pay attention to this order when
    # dorking with it to make sure it makes sense
    command.add_option_group(basic_group)
    command.add_option_group(publish_group)

    # Metadata Options - Reorganized using standard commands
    basic_group.add_option(std_options.OPTION_REPO_ID)
    basic_group.add_option(std_options.OPTION_NAME)
    basic_group.add_option(std_options.OPTION_DESCRIPTION)
    basic_group.add_option(std_options.OPTION_NOTES)

    # Publish Options
    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)
    publish_group.add_option(OPT_CHECKSUM_TYPE)
Пример #22
0
class ImporterConfigMixin(object):
    """
    Mixin to add to a command that will provide options on the CLI to accept the standard
    configuration values for a Pulp importer. This mixin also provides a method to parse
    the submitted user input and generate a config dict suitable for an importer
    config values. The produced configuration uses the keys in
    pulp.common.plugins.importer_constants.

    Touch points are provided to manipulate the options created by this mixin for each group
    (the populate_* methods). If options are added through overridden versions of those methods,
    the corresponding parse_* method should be updated to read those.
    The option groups are also stored as instance variables, further allowing the subclass
    the ability to manipulate them.

    The option instances that will be used in this mixin are contained in an OptionsBundle
    instance. If no changes to the option defaults are required, this can be omitted from
    this object's instantiation. If tweaks to the options are required, they should be done
    in an instance of OptionsBundle and then passed to this class at instantiation.

    This mixin must be used in a class that subclasses PulpCliCommand as well. The usage is as
    follows:

    * Define a class that extends both PulpCliCommand and ImporterConfigMixin.
    * Call the ImporterConfigMixin.__init__ method in its constructor. This will add the
      necessary options to the command.
    * In the execution method of the command, run parse_user_input(), passing in the args
      parsed from the user input. The result of that is a dict that can be used server-side
      to configure an importer.
    """

    def __init__(self,
                 options_bundle=None,
                 include_sync=True,
                 include_ssl=True,
                 include_proxy=True,
                 include_throttling=True,
                 include_unit_policy=True):

        # If the caller didn't dork with any of the options, instantiate one with the defaults
        self.options_bundle = options_bundle or OptionsBundle()

        # Created now, but won't be added to the command until the include_* flags are checked.
        # Stored as instance variables so a class using this mixin can further manipulate them.
        self.sync_group = PulpCliOptionGroup(GROUP_NAME_SYNC)
        self.ssl_group = PulpCliOptionGroup(GROUP_NAME_SSL)
        self.proxy_group = PulpCliOptionGroup(GROUP_NAME_PROXY)
        self.throttling_group = PulpCliOptionGroup(GROUP_NAME_THROTTLING)
        self.unit_policy_group = PulpCliOptionGroup(GROUP_NAME_UNIT_POLICY)

        if include_sync:
            self.populate_sync_group()
            self.add_option_group(self.sync_group)

        if include_ssl:
            self.populate_ssl_group()
            self.add_option_group(self.ssl_group)

        if include_proxy:
            self.populate_proxy_group()
            self.add_option_group(self.proxy_group)

        if include_throttling:
            self.populate_throttling_group()
            self.add_option_group(self.throttling_group)

        if include_unit_policy:
            self.populate_unit_policy()
            self.add_option_group(self.unit_policy_group)

    def populate_sync_group(self):
        """
        Adds options to the synchronization group. This is only called if the include_sync flag is
        set to True in the constructor.
        """
        self.sync_group.add_option(self.options_bundle.opt_feed)
        self.sync_group.add_option(self.options_bundle.opt_validate)

    def populate_ssl_group(self):
        """
        Adds options to the SSL group. This is only called if the include_ssl flag is
        set to True in the constructor.
        """
        self.ssl_group.add_option(self.options_bundle.opt_feed_ca_cert)
        self.ssl_group.add_option(self.options_bundle.opt_verify_feed_ssl)
        self.ssl_group.add_option(self.options_bundle.opt_feed_cert)
        self.ssl_group.add_option(self.options_bundle.opt_feed_key)

    def populate_proxy_group(self):
        """
        Adds options to the proxy group. This is only called if the include_proxy flag is
        set to True in the constructor.
        """
        self.proxy_group.add_option(self.options_bundle.opt_proxy_host)
        self.proxy_group.add_option(self.options_bundle.opt_proxy_port)
        self.proxy_group.add_option(self.options_bundle.opt_proxy_user)
        self.proxy_group.add_option(self.options_bundle.opt_proxy_pass)

    def populate_throttling_group(self):
        """
        Adds options to the throttling group. This is only called if the include_throttling flag is
        set to True in the constructor.
        """
        self.throttling_group.add_option(self.options_bundle.opt_max_downloads)
        self.throttling_group.add_option(self.options_bundle.opt_max_speed)

    def populate_unit_policy(self):
        """
        Adds options to the unit policy group. This is only called if the include_unit_policy flag
        is set to True in the constructor.
        """
        self.unit_policy_group.add_option(self.options_bundle.opt_remove_missing)
        self.unit_policy_group.add_option(self.options_bundle.opt_retain_old_count)

    def parse_user_input(self, user_input):
        """
        Reads the user input for any specified values that correspond to the importer config
        and returns a suitable dict for passing the importer as its configuration. As the values
        are read, they will be removed from the supplied user_input dict.

        The supplied user input should already have the arg_utils.convert_removed_options method
        run on it to properly strip out unset values and convert empty strings into None values for
        keys that should explicitly have a null value.

        :param user_input: keyword arguments from the CLI framework containing user input
        :type  user_input: dict

        :return: suitable representation of the importer config that can be stored on the repo
        :rtype:  dict
        """
        config = {}
        config.update(self.parse_sync_group(user_input))
        config.update(self.parse_ssl_group(user_input))
        config.update(self.parse_proxy_group(user_input))
        config.update(self.parse_throttling_group(user_input))
        config.update(self.parse_unit_policy(user_input))
        return config

    def parse_sync_group(self, user_input):
        """
        Reads any basic synchronization config options from the user input and packages them into
        the Pulp standard importer config format.

        :param user_input: keyword arguments from the CLI framework containing user input
        :type  user_input: dict

        :return: suitable representation of the config that can be stored on the repo
        :rtype:  dict
        """
        key_tuples = (
            (constants.KEY_FEED, self.options_bundle.opt_feed.keyword),
            (constants.KEY_VALIDATE, self.options_bundle.opt_validate.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)

        return config

    def parse_ssl_group(self, user_input):
        """
        Reads any SSL-related config options from the user input and packages them into
        the Pulp standard importer config format.

        :param user_input: keyword arguments from the CLI framework containing user input
        :type  user_input: dict

        :return: suitable representation of the config that can be stored on the repo
        :rtype:  dict
        """
        key_tuples = (
            (constants.KEY_SSL_CA_CERT, self.options_bundle.opt_feed_ca_cert.keyword),
            (constants.KEY_SSL_VALIDATION, self.options_bundle.opt_verify_feed_ssl.keyword),
            (constants.KEY_SSL_CLIENT_CERT, self.options_bundle.opt_feed_cert.keyword),
            (constants.KEY_SSL_CLIENT_KEY, self.options_bundle.opt_feed_key.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)

        arg_utils.convert_file_contents(('ssl_ca_cert', 'ssl_client_cert', 'ssl_client_key'),
                                        config)

        return config

    def parse_proxy_group(self, user_input):
        """
        Reads any proxy-related config options from the user input and packages them into
        the Pulp standard importer config format.

        :param user_input: keyword arguments from the CLI framework containing user input
        :type  user_input: dict

        :return: suitable representation of the config that can be stored on the repo
        :rtype:  dict
        """
        key_tuples = (
            (constants.KEY_PROXY_HOST, self.options_bundle.opt_proxy_host.keyword),
            (constants.KEY_PROXY_PORT, self.options_bundle.opt_proxy_port.keyword),
            (constants.KEY_PROXY_USER, self.options_bundle.opt_proxy_user.keyword),
            (constants.KEY_PROXY_PASS, self.options_bundle.opt_proxy_pass.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)
        return config

    def parse_throttling_group(self, user_input):
        """
        Reads any throttling-related config options from the user input and packages them into
        the Pulp standard importer config format.

        :param user_input: keyword arguments from the CLI framework containing user input
        :type  user_input: dict

        :return: suitable representation of the config that can be stored on the repo
        :rtype:  dict
        """
        key_tuples = (
            (constants.KEY_MAX_DOWNLOADS, self.options_bundle.opt_max_downloads.keyword),
            (constants.KEY_MAX_SPEED, self.options_bundle.opt_max_speed.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)
        return config

    def parse_unit_policy(self, user_input):
        """
        Reads any unit policy-related config options from the user input and packages them into
        the Pulp standard importer config format.
        """
        key_tuples = (
            (constants.KEY_UNITS_REMOVE_MISSING, self.options_bundle.opt_remove_missing.keyword),
            (constants.KEY_UNITS_RETAIN_OLD_COUNT,
             self.options_bundle.opt_retain_old_count.keyword),
        )

        config = {}
        for config_key, input_key in key_tuples:
            safe_parse(user_input, config, input_key, config_key)
        return config
Пример #23
0
def add_repo_options(command, is_update):
    """
    Adds options/flags for all repo configuration values (repo, importer, and
    distributor). This is meant to be called for both create and update commands
    to simplify consistency

    @param command: command to add options to
    """

    # Groups
    basic_group = PulpCliOptionGroup('Basic')
    throttling_group = PulpCliOptionGroup('Throttling')
    ssl_group = PulpCliOptionGroup('Feed Authentication')
    proxy_group = PulpCliOptionGroup('Feed Proxy')
    sync_group = PulpCliOptionGroup('Synchronization')
    publish_group = PulpCliOptionGroup('Publishing')
    repo_auth_group = PulpCliOptionGroup('Client Authentication')

    # Order added indicates order in usage, so pay attention to this order when
    # dorking with it to make sure it makes sense
    command.add_option_group(basic_group)
    command.add_option_group(sync_group)
    command.add_option_group(publish_group)
    command.add_option_group(ssl_group)
    command.add_option_group(repo_auth_group)
    command.add_option_group(proxy_group)
    command.add_option_group(throttling_group)

    # Metadata Options
    basic_group.add_option(PulpCliOption('--repo-id', 'uniquely identifies the repository; only alphanumeric, -, and _ allowed', required=True))
    basic_group.add_option(PulpCliOption('--feed', 'URL of the external source repository to sync', required=False))
    basic_group.add_option(PulpCliOption('--display-name', 'user-readable display name for the repository', required=False))
    basic_group.add_option(PulpCliOption('--description', 'user-readable description of the repo\'s contents', required=False))

    d =  'adds/updates/deletes key-value pairs to programmatically identify the repository; '
    d += 'pairs must be separated by an equal sign (e.g. key=value); multiple notes can '
    d += 'be %(i)s by specifying this option multiple times; notes are deleted by '
    d += 'specifying "" as the value'
    d = _(d)

    if is_update:
        d = d % {'i' : _('changed')}
    else:
        d = d % {'i' : _('added')}

    basic_group.add_option(PulpCliOption('--note', d, required=False, allow_multiple=True))
    d =  'if "true", on each successful sync the repository will automatically be ' \
    'published on the configured protocols; if "false" synchronized content will ' \
    'only be available after manually publishing the repository; defaults to "true"'
    basic_group.add_option(PulpCliOption('--auto-publish', _(d), required=False))

    # Synchronization Options
    sync_group.add_option(PulpCliOption('--only-newest', 'if "true", only the newest version of a given package is downloaded; defaults to false', required=False))
    sync_group.add_option(PulpCliOption('--skip-types', 'comma-separated list of types to omit when synchronizing, if not specified all types will be synchronized; valid values are: %s' % ', '.join(VALID_SKIP_TYPES), required=False))
    sync_group.add_option(PulpCliOption('--verify-size', 'if "true", the size of each synchronized file will be verified against the repo metadata; defaults to false', required=False))
    sync_group.add_option(PulpCliOption('--verify-checksum', 'if "true", the checksum of each synchronized file will be verified against the repo metadata; defaults to false', required=False))
    sync_group.add_option(PulpCliOption('--remove-old', 'if "true", removes old packages from the repo; defaults to false', required=False))
    sync_group.add_option(PulpCliOption('--retain-old-count', 'count indicating how many old rpm versions to retain; defaults to 0; this count only takes effect when remove-old option is set to true.', required=False))

    # Proxy Options
    proxy_group.add_option(PulpCliOption('--proxy-url', 'URL to the proxy server to use', required=False))
    proxy_group.add_option(PulpCliOption('--proxy-port', 'port on the proxy server to make requests', required=False))
    proxy_group.add_option(PulpCliOption('--proxy-user', 'username used to authenticate with the proxy server', required=False))
    proxy_group.add_option(PulpCliOption('--proxy-pass', 'password used to authenticate with the proxy server', required=False))

    # Throttling Options
    throttling_group.add_option(PulpCliOption('--max-speed', 'maximum bandwidth used per download thread, in KB/sec, when synchronizing the repo', required=False))
    throttling_group.add_option(PulpCliOption('--num-threads', 'number of threads that will be used to synchronize the repo', required=False))

    # SSL Options
    ssl_group.add_option(PulpCliOption('--feed-ca-cert', 'full path to the CA certificate that should be used to verify the external repo server\'s SSL certificate', required=False))
    ssl_group.add_option(PulpCliOption('--verify-feed-ssl', 'if "true", the feed\'s SSL certificate will be verified against the feed_ca_cert; defaults to false', required=False))
    ssl_group.add_option(PulpCliOption('--feed-cert', 'full path to the certificate to use for authentication when accessing the external feed', required=False))
    ssl_group.add_option(PulpCliOption('--feed-key', 'full path to the private key for feed_cert', required=False))

    # Publish Options
    publish_group.add_option(PulpCliOption('--relative-url', 'relative path the repository will be served from; defaults to relative path of the feed URL', required=False))
    publish_group.add_option(PulpCliOption('--serve-http', 'if "true", the repository will be served over HTTP; defaults to false', required=False))
    publish_group.add_option(PulpCliOption('--serve-https', 'if "true", the repository will be served over HTTPS; defaults to true', required=False))
    publish_group.add_option(PulpCliOption('--checksum-type', 'type of checksum to use during metadata generation', required=False))
    publish_group.add_option(PulpCliOption('--gpg-key', 'GPG key used to sign and verify packages in the repository', required=False))
    publish_group.add_option(PulpCliOption('--regenerate-metadata', 'if "true", when the repository is published the repo metadata will be regenerated instead of reusing the metadata downloaded from the feed; defaults to true', required=False))

    # Publish Security Options
    repo_auth_group.add_option(PulpCliOption('--host-ca', 'full path to the CA certificate that signed the repository hosts\'s SSL certificate when serving over HTTPS', required=False))
    repo_auth_group.add_option(PulpCliOption('--auth-ca', 'full path to the CA certificate that should be used to verify client authentication certificates; setting this turns on client authentication for the repository', required=False))
    repo_auth_group.add_option(PulpCliOption('--auth-cert', 'full path to the entitlement certificate that will be given to bound consumers to grant access to this repository', required=False))
Пример #24
0
def add_to_command(command):
    """
    Adds the repository configuration related options to the given command,
    organizing them into the appropriate groups.

    :param command: command to add options to
    :type  command: pulp.clients.extensions.extensions.PulpCliCommand
    """

    # Groups
    basic_group = PulpCliOptionGroup(NAME_BASIC)
    throttling_group = PulpCliOptionGroup(NAME_THROTTLING)
    ssl_group = PulpCliOptionGroup(NAME_FEED)
    proxy_group = PulpCliOptionGroup(NAME_PROXY)
    sync_group = PulpCliOptionGroup(NAME_SYNC)
    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)
    repo_auth_group = PulpCliOptionGroup(NAME_AUTH)

    # Order added indicates order in usage, so pay attention to this order when
    # dorking with it to make sure it makes sense
    command.add_option_group(basic_group)
    command.add_option_group(sync_group)
    command.add_option_group(publish_group)
    command.add_option_group(ssl_group)
    command.add_option_group(repo_auth_group)
    command.add_option_group(proxy_group)
    command.add_option_group(throttling_group)

    # Metadata Options - Reorganized using standard commands
    basic_group.add_option(std_options.OPTION_REPO_ID)
    basic_group.add_option(std_options.OPTION_NAME)
    basic_group.add_option(std_options.OPTION_DESCRIPTION)
    basic_group.add_option(std_options.OPTION_NOTES)

    # Synchronization Options
    sync_group.add_option(OPT_FEED)
    sync_group.add_option(OPT_NEWEST)
    sync_group.add_option(OPT_SKIP)
    sync_group.add_option(OPT_VERIFY_SIZE)
    sync_group.add_option(OPT_VERIFY_CHECKSUM)
    sync_group.add_option(OPT_REMOVE_OLD)
    sync_group.add_option(OPT_RETAIN_OLD_COUNT)

    # Proxy Options
    proxy_group.add_option(OPT_PROXY_URL)
    proxy_group.add_option(OPT_PROXY_PORT)
    proxy_group.add_option(OPT_PROXY_USER)
    proxy_group.add_option(OPT_PROXY_PASS)

    # Throttling Options
    throttling_group.add_option(OPT_MAX_SPEED)
    throttling_group.add_option(OPT_NUM_THREADS)

    # SSL Options
    ssl_group.add_option(OPT_FEED_CA_CERT)
    ssl_group.add_option(OPT_VERIFY_FEED_SSL)
    ssl_group.add_option(OPT_FEED_CERT)
    ssl_group.add_option(OPT_FEED_KEY)

    # Publish Options

    # The server-side APIs don't allow this to be updated, so hide it as an
    # option entirely; RPM repos are always published automatically with our
    # CLI until we clean that up. jdob, Sept 24, 2012
    # publish_group.add_option(OPT_AUTO_PUBLISH)

    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)
    publish_group.add_option(OPT_CHECKSUM_TYPE)
    publish_group.add_option(OPT_GPG_KEY)

    # Publish Security Options
    repo_auth_group.add_option(OPT_HOST_CA)
    repo_auth_group.add_option(OPT_AUTH_CA)
    repo_auth_group.add_option(OPT_AUTH_CERT)
Пример #25
0
def add_distributor_config_to_command(command):
    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)
    repo_auth_group = PulpCliOptionGroup(NAME_AUTH)

    # The server-side APIs don't allow this to be updated, so hide it as an
    # option entirely; RPM repos are always published automatically with our
    # CLI until we clean that up. jdob, Sept 24, 2012
    # publish_group.add_option(OPT_AUTO_PUBLISH)

    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)
    publish_group.add_option(OPT_CHECKSUM_TYPE)
    publish_group.add_option(OPT_GPG_KEY)
    publish_group.add_option(OPT_GENERATE_SQLITE)
    publish_group.add_option(OPT_REPOVIEW)

    # Order added indicates order in usage, so pay attention to this order when
    # dorking with it to make sure it makes sense
    command.add_option_group(publish_group)
    command.add_option_group(repo_auth_group)

    # Publish Security Options
    repo_auth_group.add_option(OPT_HOST_CA)
    repo_auth_group.add_option(OPT_AUTH_CA)
    repo_auth_group.add_option(OPT_AUTH_CERT)
Пример #26
0
def add_distributor_config_to_command(command):
    publish_group = PulpCliOptionGroup(NAME_PUBLISHING)
    repo_auth_group = PulpCliOptionGroup(NAME_AUTH)

    # The server-side APIs don't allow this to be updated, so hide it as an
    # option entirely; RPM repos are always published automatically with our
    # CLI until we clean that up. jdob, Sept 24, 2012
    # publish_group.add_option(OPT_AUTO_PUBLISH)

    publish_group.add_option(OPT_RELATIVE_URL)
    publish_group.add_option(OPT_SERVE_HTTP)
    publish_group.add_option(OPT_SERVE_HTTPS)
    publish_group.add_option(OPT_CHECKSUM_TYPE)
    publish_group.add_option(OPT_GPG_KEY)
    publish_group.add_option(OPT_GENERATE_SQLITE)

    # Order added indicates order in usage, so pay attention to this order when
    # dorking with it to make sure it makes sense
    command.add_option_group(publish_group)
    command.add_option_group(repo_auth_group)

    # Publish Security Options
    repo_auth_group.add_option(OPT_HOST_CA)
    repo_auth_group.add_option(OPT_AUTH_CA)
    repo_auth_group.add_option(OPT_AUTH_CERT)