Exemple #1
0
    def run(self, **kwargs):
        """
        Perform the update on the server.

        :param kwargs: The user input
        :type  kwargs: dict
        """
        arg_utils.convert_removed_options(kwargs)

        importer_config = self._parse_importer_config(kwargs)

        # Remove importer specific keys
        for key in importer_config.keys():
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][constants.CLI_DISTRIBUTOR_ID] = web_config

        super(UpdatePythonRepositoryCommand, self).run(**kwargs)
Exemple #2
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)

        if OPT_BRANCH.keyword in kwargs:
            value = kwargs.pop(OPT_BRANCH.keyword, None)
            if value == ['']:
                # clear out the specified branches
                value = None
            importer_config[constants.IMPORTER_CONFIG_KEY_BRANCHES] = value

        # Remove importer specific keys
        for key in importer_config.keys():
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][
                constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        super(UpdateOSTreeRepositoryCommand, self).run(**kwargs)
Exemple #3
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)
        if OPT_PACKAGE_FILE_PATH.keyword in kwargs:
            importer_config[OPT_PACKAGE_FILE_PATH.keyword] = \
                kwargs.get(OPT_PACKAGE_FILE_PATH.keyword)

        # Remove importer specific keys
        for key in importer_config.keys():
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][
                constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        super(UpdateDebRepositoryCommand, self).run(**kwargs)
    def test_null_values(self):
        # Setup
        args = {'key1': None}

        # Assert that all the args with a value of None are removed
        arg_utils.convert_removed_options(args)
        self.assertEqual({}, args)
Exemple #5
0
    def run(self, **kwargs):
        # -- importer metadata --
        queries = kwargs.pop(OPTION_QUERIES.keyword, None)
        if queries is None:
            queries = kwargs.pop(OPTION_QUERY.keyword, None)
        importer_config = self.parse_user_input(kwargs)
        importer_config.update({constants.CONFIG_QUERIES: queries})
        if importer_config:
            arg_utils.convert_removed_options(importer_config)
            kwargs['importer_config'] = importer_config

        # Remove the importer keys from kwargs so they don't get added to the repo config
        for key in importer_config:
            kwargs.pop(key.replace('_', '-'), None)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs.pop(OPTION_HTTP.keyword, None),
            constants.CONFIG_SERVE_HTTPS: kwargs.pop(OPTION_HTTPS.keyword, None)
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_HTTP,
                                             constants.CONFIG_SERVE_HTTPS), distributor_config)
        # Remove the distributor keys from kwargs so they don't get added to the repo config
        for key in distributor_config:
            kwargs.pop(key, None)

        kwargs['distributor_configs'] = {}
        if distributor_config:
            kwargs['distributor_configs'][constants.DISTRIBUTOR_ID] = distributor_config
        super(UpdatePuppetRepositoryCommand, self).run(**kwargs)
Exemple #6
0
    def test_null_values(self):
        # Setup
        args = {'key1': None}

        # Assert that all the args with a value of None are removed
        arg_utils.convert_removed_options(args)
        self.assertEqual({}, args)
Exemple #7
0
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate those
        # that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None)

        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig as e:
            self.prompt.render_failure_message(str(e))
            return

        # only add distributors if they actually have changes
        distributor_configs = {}
        if distributor_config:
            distributor_configs[
                ids.TYPE_ID_DISTRIBUTOR] = distributor_config  # noqa

        response = self.context.server.repo.update_repo_and_plugins(
            repo_id, display_name, description, notes, importer_config,
            distributor_configs)

        if not response.is_async():
            msg = _('Repository [%(r)s] successfully updated')
            self.prompt.render_success_message(msg % {'r': repo_id})
        else:
            self.poll([response.response_body], kwargs)
Exemple #8
0
    def run(self, **kwargs):
        """
        Perform the update on the server.

        :param kwargs: The user input
        :type  kwargs: dict
        """
        arg_utils.convert_removed_options(kwargs)

        importer_config = self._parse_importer_config(kwargs)

        # Remove importer specific keys
        for key in importer_config:
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}
        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][
                constants.CLI_DISTRIBUTOR_ID] = web_config

        super(UpdateNpmRepositoryCommand, self).run(**kwargs)
Exemple #9
0
    def run(self, **kwargs):
        # -- importer metadata --
        queries = kwargs.pop(OPTION_QUERIES.keyword, None)
        if queries is None:
            queries = kwargs.pop(OPTION_QUERY.keyword, None)
        importer_config = self.parse_user_input(kwargs)
        importer_config.update({constants.CONFIG_QUERIES: queries})
        if importer_config:
            arg_utils.convert_removed_options(importer_config)
            kwargs['importer_config'] = importer_config

        # Remove the importer keys from kwargs so they don't get added to the repo config
        for key in importer_config:
            kwargs.pop(key, None)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs.pop(OPTION_HTTP.keyword, None),
            constants.CONFIG_SERVE_HTTPS: kwargs.pop(OPTION_HTTPS.keyword, None)
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_HTTP,
                                             constants.CONFIG_SERVE_HTTPS), distributor_config)
        # Remove the distributor keys from kwargs so they don't get added to the repo config
        for key in distributor_config:
            kwargs.pop(key, None)

        kwargs['distributor_configs'] = {}
        if distributor_config:
            kwargs['distributor_configs'][constants.DISTRIBUTOR_ID] = distributor_config
        super(UpdatePuppetRepositoryCommand, self).run(**kwargs)
Exemple #10
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)

        if OPT_BRANCH.keyword in kwargs:
            value = kwargs.pop(OPT_BRANCH.keyword, None)
            if value == ['']:
                # clear out the specified branches
                value = None
            importer_config[constants.IMPORTER_CONFIG_KEY_BRANCHES] = value

        # Remove importer specific keys
        for key in importer_config.keys():
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        super(UpdateOSTreeRepositoryCommand, self).run(**kwargs)
Exemple #11
0
    def test_empty_value(self):
        # Setup
        args = {'key1': ''}

        # Assert that args with a '' value are converted to None
        arg_utils.convert_removed_options(args)
        self.assertTrue(args['key1'] is None)
Exemple #12
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)
        if OPT_PACKAGE_FILE_PATH.keyword in kwargs:
            importer_config[OPT_PACKAGE_FILE_PATH.keyword] = \
                kwargs.get(OPT_PACKAGE_FILE_PATH.keyword)

        # Remove importer specific keys
        for key in importer_config.keys():
            kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        super(UpdateDebRepositoryCommand, self).run(**kwargs)
    def test_empty_value(self):
        # Setup
        args = {'key1': ''}

        # Assert that args with a '' value are converted to None
        arg_utils.convert_removed_options(args)
        self.assertTrue(args['key1'] is None)
    def test_non_empty_values(self):
        # Setup
        args = {'key1': 'real_val', 'key2': 'another_val'}
        original_args = args.copy()

        # Test to make sure none of the keys or values are touched
        arg_utils.convert_removed_options(args)
        self.assertEqual(args, original_args)
Exemple #15
0
    def test_non_empty_values(self):
        # Setup
        args = {'key1': 'real_val', 'key2': 'another_val'}
        original_args = args.copy()

        # Test to make sure none of the keys or values are touched
        arg_utils.convert_removed_options(args)
        self.assertEqual(args, original_args)
Exemple #16
0
    def run(self, **kwargs):
        schedule_id = kwargs.pop(OPT_SCHEDULE_ID.keyword)
        ft = kwargs.pop(OPT_FAILURE_THRESHOLD.keyword, None)
        if ft:
            kwargs['failure_threshold'] = ft

        convert_removed_options(kwargs)
        convert_boolean_arguments([OPT_ENABLED.keyword], kwargs)

        self.strategy.update_schedule(schedule_id, **kwargs)
        self.context.prompt.render_success_message(_('Successfully updated schedule'))
Exemple #17
0
    def update(self, **kwargs):
        schedule_id = kwargs.pop('schedule-id')
        ft = kwargs.pop('failure-threshold', None)
        if ft:
            kwargs['failure_threshold'] = ft

        convert_removed_options(kwargs)
        convert_boolean_arguments(['enabled'], kwargs)

        response = self.strategy.update_schedule(schedule_id, **kwargs)
        self.context.prompt.render_success_message(_('Successfully updated schedule'))
Exemple #18
0
    def run(self, **kwargs):
        schedule_id = kwargs.pop(OPT_SCHEDULE_ID.keyword)
        ft = kwargs.pop(OPT_FAILURE_THRESHOLD.keyword, None)
        if ft:
            kwargs['failure_threshold'] = ft

        convert_removed_options(kwargs)
        convert_boolean_arguments([OPT_ENABLED.keyword], kwargs)

        self.strategy.update_schedule(schedule_id, **kwargs)
        self.context.prompt.render_success_message(
            _('Successfully updated schedule'))
Exemple #19
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)

        # traversal depth
        if OPT_DEPTH.keyword in kwargs:
            value = kwargs.get(OPT_DEPTH.keyword)
            importer_config[constants.IMPORTER_CONFIG_KEY_DEPTH] = value

        # branch list
        if OPT_BRANCH.keyword in kwargs:
            value = kwargs.pop(OPT_BRANCH.keyword)
            if value == CLEAR_THE_LIST:
                value = None
            importer_config[constants.IMPORTER_CONFIG_KEY_BRANCHES] = value

        # gpg key list
        if OPT_GPG_KEY.keyword in kwargs:
            value = kwargs.pop(OPT_GPG_KEY.keyword)
            if value == CLEAR_THE_LIST:
                value = None
            else:
                value = map(read, value)
            importer_config[constants.IMPORTER_CONFIG_KEY_GPG_KEYS] = value

        # Remove importer specific keys
        for key in importer_config.keys():
            if key not in (OPT_DEPTH.keyword, ):
                kwargs.pop(key, None)

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        # traversal depth
        depth = kwargs.pop(OPT_DEPTH.keyword, None)
        if depth is not None:
            web_config[constants.DISTRIBUTOR_CONFIG_KEY_DEPTH] = depth

        if web_config:
            kwargs['distributor_configs'] = {}
            kwargs['distributor_configs'][
                constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        super(UpdateOSTreeRepositoryCommand, self).run(**kwargs)
Exemple #20
0
    def run(self, **kwargs):

        # -- repository metadata --
        repo_id = kwargs[options.OPTION_REPO_ID.keyword]
        description = kwargs[options.OPTION_DESCRIPTION.keyword]
        notes = kwargs.pop(options.OPTION_NOTES.keyword) or {}

        # Add a note to indicate this is a Puppet repository
        notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE_PUPPET

        name = repo_id
        if options.OPTION_NAME.keyword in kwargs:
            name = kwargs[options.OPTION_NAME.keyword]

        # -- importer metadata --
        importer_config = self.parse_user_input(kwargs)
        importer_config.update(
            {constants.CONFIG_QUERIES: kwargs[OPTION_QUERIES.keyword] or kwargs[OPTION_QUERY.keyword]}
        )
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs[OPTION_HTTP.keyword],
            constants.CONFIG_SERVE_HTTPS: kwargs[OPTION_HTTPS.keyword],
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments(
            (constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS), distributor_config
        )

        distributors = [
            dict(
                distributor_type=constants.DISTRIBUTOR_TYPE_ID,
                distributor_config=distributor_config,
                auto_publish=True,
                distributor_id=constants.DISTRIBUTOR_ID,
            )
        ]

        # Create the repository
        self.context.server.repo.create_and_configure(
            repo_id, name, description, notes, constants.IMPORTER_TYPE_ID, importer_config, distributors
        )

        msg = _("Successfully created repository [%(r)s]")
        self.context.prompt.render_success_message(msg % {"r": repo_id})
Exemple #21
0
    def run(self, **kwargs):

        # -- repository metadata --
        repo_id = kwargs[options.OPTION_REPO_ID.keyword]
        description = kwargs[options.OPTION_DESCRIPTION.keyword]
        notes = kwargs.pop(options.OPTION_NOTES.keyword) or {}

        # Add a note to indicate this is a Puppet repository
        notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE_PUPPET

        name = repo_id
        if options.OPTION_NAME.keyword in kwargs:
            name = kwargs[options.OPTION_NAME.keyword]

        # -- importer metadata --
        importer_config = {
            constants.CONFIG_FEED:
            kwargs[OPTION_FEED.keyword],
            constants.CONFIG_QUERIES:
            kwargs[OPTION_QUERIES.keyword] or kwargs[OPTION_QUERY.keyword],
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs[OPTION_HTTP.keyword],
            constants.CONFIG_SERVE_HTTPS: kwargs[OPTION_HTTPS.keyword],
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments(
            (constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS),
            distributor_config)

        distributors = [
            dict(distributor_type=constants.DISTRIBUTOR_TYPE_ID,
                 distributor_config=distributor_config,
                 auto_publish=True,
                 distributor_id=constants.DISTRIBUTOR_ID)
        ]

        # Create the repository
        self.context.server.repo.create_and_configure(
            repo_id, name, description, notes, constants.IMPORTER_TYPE_ID,
            importer_config, distributors)

        msg = _('Successfully created repository [%(r)s]')
        self.context.prompt.render_success_message(msg % {'r': repo_id})
Exemple #22
0
    def run(self, **kwargs):
        # -- repository metadata --
        repo_id = kwargs.pop(options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(options.OPTION_DESCRIPTION.keyword, None)
        name = kwargs.pop(options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(options.OPTION_NOTES.keyword, None)

        # -- importer metadata --
        queries = kwargs.pop(OPTION_QUERIES.keyword, None)
        if queries is None:
            queries = kwargs.pop(OPTION_QUERY.keyword, None)
        importer_config = {
            constants.CONFIG_FEED: kwargs.pop(OPTION_FEED.keyword, None),
            constants.CONFIG_QUERIES: queries
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs.pop(OPTION_HTTP.keyword, None),
            constants.CONFIG_SERVE_HTTPS: kwargs.pop(OPTION_HTTPS.keyword,
                                                     None),
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments(
            (constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS),
            distributor_config)

        distributor_configs = {constants.DISTRIBUTOR_ID: distributor_config}

        # -- server update --
        response = self.context.server.repo.update_repo_and_plugins(
            repo_id, name, description, notes, importer_config,
            distributor_configs)

        if not response.is_async():
            msg = _('Repository [%(r)s] successfully updated')
            self.context.prompt.render_success_message(msg % {'r': repo_id})
        else:
            d = _(
                'Repository update postponed due to another operation. Progress '
                'on this task can be viewed using the commands under "repo tasks".'
            )
            self.context.prompt.render_paragraph(d, tag='postponed')
            self.context.prompt.render_reasons(response.response_body.reasons)
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate those
        # that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None)

        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig, e:
            self.prompt.render_failure_message(str(e))
            return
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate those
        # that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None)

        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig, e:
            self.prompt.render_failure_message(str(e))
            return
Exemple #25
0
    def run(self, **kwargs):
        # -- repository metadata --
        repo_id = kwargs.pop(options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(options.OPTION_DESCRIPTION.keyword, None)
        name = kwargs.pop(options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(options.OPTION_NOTES.keyword, None)

        # -- importer metadata --
        queries = kwargs.pop(OPTION_QUERIES.keyword, None)
        if queries is None:
            queries = kwargs.pop(OPTION_QUERY.keyword, None)
        importer_config = self.parse_user_input(kwargs)
        importer_config.update({constants.CONFIG_QUERIES: queries})
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP: kwargs.pop(OPTION_HTTP.keyword, None),
            constants.CONFIG_SERVE_HTTPS: kwargs.pop(OPTION_HTTPS.keyword, None),
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments(
            (constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS), distributor_config
        )

        distributor_configs = {constants.DISTRIBUTOR_ID: distributor_config}

        # -- server update --
        response = self.context.server.repo.update_repo_and_plugins(
            repo_id, name, description, notes, importer_config, distributor_configs
        )

        if not response.is_async():
            msg = _("Repository [%(r)s] successfully updated")
            self.context.prompt.render_success_message(msg % {"r": repo_id})
        else:
            d = _(
                "Repository update postponed due to another operation. Progress "
                'on this task can be viewed using the commands under "repo tasks".'
            )
            self.context.prompt.render_paragraph(d, tag="postponed")
            self.context.prompt.render_reasons(response.response_body.reasons)
Exemple #26
0
    def run(self, **kwargs):
        # -- repository metadata --
        repo_id = kwargs.pop(options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(options.OPTION_DESCRIPTION.keyword, None)
        name = kwargs.pop(options.OPTION_NAME.keyword, None)

        notes = None
        if options.OPTION_NOTES.keyword in kwargs and kwargs[options.OPTION_NOTES.keyword] is not None:
            notes = arg_utils.args_to_notes_dict(kwargs[options.OPTION_NOTES.keyword], include_none=True)

            # Make sure the note indicating it's a puppet repository is still present
            notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE_PUPPET

        # -- importer metadata --
        importer_config = {
            constants.CONFIG_FEED : kwargs.pop(OPTION_FEED.keyword, None),
            constants.CONFIG_QUERIES : kwargs.pop(OPTION_QUERY.keyword, None),
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP : kwargs.pop(OPTION_HTTP.keyword, None),
            constants.CONFIG_SERVE_HTTPS : kwargs.pop(OPTION_HTTPS.keyword, None),
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS), distributor_config)

        distributor_configs = {constants.DISTRIBUTOR_ID : distributor_config}

        # -- server update --
        response = self.context.server.repo.update_repo_and_plugins(repo_id, name,
                        description, notes, importer_config, distributor_configs)

        if not response.is_async():
            msg = _('Repository [%(r)s] successfully updated')
            self.context.prompt.render_success_message(msg % {'r' : repo_id})
        else:
            d = _('Repository update postponed due to another operation. Progress '
                'on this task can be viewed using the commands under "repo tasks".')
            self.context.prompt.render_paragraph(d, tag='postponed')
            self.context.prompt.render_reasons(response.response_body.reasons)
Exemple #27
0
    def run(self, **kwargs):
        repo_id = kwargs[options.OPTION_REPO_ID.keyword]
        description = kwargs[options.OPTION_DESCRIPTION.keyword]
        notes = kwargs.pop(options.OPTION_NOTES.keyword) or {}

        # Add a note to indicate this is a Deb repository
        notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE

        name = repo_id
        if options.OPTION_NAME.keyword in kwargs:
            name = kwargs[options.OPTION_NAME.keyword]

        # -- importer metadata --
        importer_config = {
            constants.CONFIG_URL: kwargs[OPTION_URL.keyword],
            constants.CONFIG_DIST: kwargs[OPTION_DIST.keyword],
            constants.CONFIG_COMPONENT: kwargs[OPTION_COMPONENT.keyword],
            constants.CONFIG_ARCH: kwargs[OPTION_ARCH.keyword],
            constants.CONFIG_QUERIES: kwargs[OPTION_QUERY.keyword],
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_INSECURE: kwargs[OPTION_INSECURE.keyword],
        }

        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_INSECURE), distributor_config)

        distributors = [
            dict(distributor_type=constants.DISTRIBUTOR_TYPE_ID, distributor_config=distributor_config,
                 auto_publish=True, distributor_id=constants.DISTRIBUTOR_ID)
        ]

        # Create the repository
        self.context.server.repo.create_and_configure(repo_id, name, description,
            notes, constants.IMPORTER_TYPE_ID, importer_config)
        #notes, constants.IMPORTER_TYPE_ID, importer_config, distributors)
        msg = _('Successfully created repository [%(r)s]')
        self.context.prompt.render_success_message(msg % {'r': repo_id})
Exemple #28
0
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate
        # those that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None) or {}

        # Add a note to indicate this is an DEB repository
        notes[pulp_constants.REPO_NOTE_TYPE_KEY] = constants.REPO_NOTE_PKG

        # Generate the appropriate plugin configs
        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig as e:
            self.prompt.render_failure_message(str(e))
            return os.EX_DATAERR

        # Special (temporary until we fix the distributor) distributor
        # config handling
        self.process_relative_url(repo_id, importer_config, distributor_config)
        self.process_distributor_serve_protocol(distributor_config)

        # Create the repository; let exceptions bubble up to the framework
        # exception handler
        distributors = self.package_distributors(distributor_config)
        self.context.server.repo.create_and_configure(repo_id, display_name,
                                                      description, notes,
                                                      ids.TYPE_ID_IMPORTER,
                                                      importer_config,
                                                      distributors)

        msg = _('Successfully created repository [%(r)s]')
        self.prompt.render_success_message(msg % {'r': repo_id})
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate
        # those that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None) or {}

        # Add a note to indicate this is an RPM repository
        notes[pulp_constants.REPO_NOTE_TYPE_KEY] = constants.REPO_NOTE_PKG

        # Generate the appropriate plugin configs
        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig, e:
            self.prompt.render_failure_message(str(e))
            return os.EX_DATAERR
    def run(self, **kwargs):

        # Remove any entries that weren't set by the user and translate
        # those that are explicitly empty to None
        arg_utils.convert_removed_options(kwargs)

        # Gather data
        repo_id = kwargs.pop(std_options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = kwargs.pop(std_options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(std_options.OPTION_NOTES.keyword, None) or {}

        # Add a note to indicate this is an RPM repository
        notes[pulp_constants.REPO_NOTE_TYPE_KEY] = constants.REPO_NOTE_PKG

        # Generate the appropriate plugin configs
        try:
            importer_config = self.parse_user_input(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig, e:
            self.prompt.render_failure_message(str(e))
            return os.EX_DATAERR
Exemple #31
0
    def run(self, **kwargs):
        # -- repository metadata --
        repo_id = kwargs.pop(options.OPTION_REPO_ID.keyword)
        description = kwargs.pop(options.OPTION_DESCRIPTION.keyword, None)
        name = kwargs.pop(options.OPTION_NAME.keyword, None)
        notes = kwargs.pop(options.OPTION_NOTES.keyword, None)

        # -- importer metadata --
        importer_config = {
            constants.CONFIG_URL: kwargs[OPTION_URL.keyword],
            constants.CONFIG_DIST: kwargs[OPTION_DIST.keyword],
            constants.CONFIG_COMPONENT: kwargs[OPTION_COMPONENT.keyword],
            constants.CONFIG_ARCH: kwargs[OPTION_ARCH.keyword],
            constants.CONFIG_QUERIES: kwargs[OPTION_QUERY.keyword],
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_INSECURE: kwargs[OPTION_INSECURE.keyword],
        }

        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS), distributor_config)

        distributor_configs = {constants.DISTRIBUTOR_ID: distributor_config}

        # -- server update --
        response = self.context.server.repo.update_repo_and_plugins(repo_id, name,
            description, notes, importer_config, distributor_configs)

        if not response.is_async():
            msg = _('Repository [%(r)s] successfully updated')
            self.context.prompt.render_success_message(msg % {'r': repo_id})
        else:
            d = _('Repository update postponed due to another operation. Progress '
                  'on this task can be viewed using the commands under "repo tasks".')
            self.context.prompt.render_paragraph(d, tag='postponed')
            self.context.prompt.render_reasons(response.response_body.reasons)
Exemple #32
0
    def run(self, **user_input):
        """
        Run the repository creation.
        """
        # Turn missing options to None
        arg_utils.convert_removed_options(user_input)

        repo_id = user_input.pop(std_options.OPTION_REPO_ID.keyword)
        description = user_input.pop(std_options.OPTION_DESCRIPTION.keyword, None)
        display_name = user_input.pop(std_options.OPTION_NAME.keyword, None)
        notes = user_input.pop(std_options.OPTION_NOTES.keyword, None) or {}

        # Mark this as an ISO repository
        notes[pulp_constants.REPO_NOTE_TYPE_KEY] = constants.REPO_NOTE_ISO

        # Build the importer and distributor configs
        try:
            importer_config = self.parse_user_input(user_input)
            distributor_config = self._parse_distributor_config(user_input)
        except arg_utils.InvalidConfig, e:
            self.prompt.render_failure_message(str(e), tag='create-failed')
            return os.EX_DATAERR
Exemple #33
0
    def run(self, **kwargs):

        # -- repository metadata --
        repo_id = kwargs[options.OPTION_REPO_ID.keyword]
        description = kwargs[options.OPTION_DESCRIPTION.keyword]
        notes = {}
        if kwargs[options.OPTION_NOTES.keyword]:
            notes = arg_utils.args_to_notes_dict(kwargs[options.OPTION_NOTES.keyword], include_none=True)
        name = repo_id
        if options.OPTION_NAME.keyword in kwargs:
            name = kwargs[options.OPTION_NAME.keyword]

        # Add a note to indicate this is a Puppet repository
        notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE_PUPPET

        # -- importer metadata --
        importer_config = {
            constants.CONFIG_FEED : kwargs[OPTION_FEED.keyword],
            constants.CONFIG_QUERIES : kwargs[OPTION_QUERY.keyword],
        }
        arg_utils.convert_removed_options(importer_config)

        # -- distributor metadata --
        distributor_config = {
            constants.CONFIG_SERVE_HTTP : kwargs[OPTION_HTTP.keyword],
            constants.CONFIG_SERVE_HTTPS : kwargs[OPTION_HTTPS.keyword],
        }
        arg_utils.convert_removed_options(distributor_config)
        arg_utils.convert_boolean_arguments((constants.CONFIG_SERVE_HTTP, constants.CONFIG_SERVE_HTTPS), distributor_config)

        distributors = [(constants.DISTRIBUTOR_TYPE_ID, distributor_config, True, constants.DISTRIBUTOR_ID)]

        # Create the repository
        self.context.server.repo.create_and_configure(repo_id, name, description,
            notes, constants.IMPORTER_TYPE_ID, importer_config, distributors)

        msg = _('Successfully created repository [%(r)s]')
        self.context.prompt.render_success_message(msg % {'r' : repo_id})
Exemple #34
0
    def run(self, **user_input):
        """
        Run the repository creation.
        """
        # Turn missing options to None
        arg_utils.convert_removed_options(user_input)

        repo_id = user_input.pop(std_options.OPTION_REPO_ID.keyword)
        description = user_input.pop(std_options.OPTION_DESCRIPTION.keyword,
                                     None)
        display_name = user_input.pop(std_options.OPTION_NAME.keyword, None)
        notes = user_input.pop(std_options.OPTION_NOTES.keyword, None) or {}

        # Mark this as an ISO repository
        notes[pulp_constants.REPO_NOTE_TYPE_KEY] = constants.REPO_NOTE_ISO

        # Build the importer and distributor configs
        try:
            importer_config = self.parse_user_input(user_input)
            distributor_config = self._parse_distributor_config(user_input)
        except arg_utils.InvalidConfig, e:
            self.prompt.render_failure_message(str(e), tag='create-failed')
            return os.EX_DATAERR
Exemple #35
0
def _prep_config(kwargs, plugin_config_keys):
    """
    Performs common initialization for both importer and distributor config
    parsing. The common conversion includes:

    * Create a base config dict pulling the given plugin_config_keys from the
      user-specified arguments
    * Translate the client-side argument names into the plugin expected keys
    * Strip out any None values which means the user did not specify the
      argument in the call
    * Convert any empty strings into None which represents the user removing
      the config value

    @param plugin_config_keys: one of the *_CONFIG_KEYS constants
    @return: dictionary to use as the basis for the config
    """

    # User-specified flags use hyphens but the importer/distributor want
    # underscores, so do a quick translation here before anything else.
    for k in kwargs.keys():
        v = kwargs.pop(k)
        new_key = k.replace('-', '_')
        kwargs[new_key] = v

    # Populate the plugin config with the plugin-relevant keys in the user args
    user_arg_keys = [k[1] for k in plugin_config_keys]
    plugin_config = dict([(k, v) for k, v in kwargs.items() if k in user_arg_keys])

    # Simple name translations
    for plugin_key, cli_key in plugin_config_keys:
        plugin_config[plugin_key] = plugin_config.pop(cli_key, None)

    # Apply option removal conventions
    convert_removed_options(plugin_config)

    return plugin_config
Exemple #36
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)

        name = kwargs.pop(OPT_UPSTREAM_NAME.keyword, None)
        if name is not None:
            importer_config[constants.CONFIG_KEY_UPSTREAM_NAME] = name

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}
        export_config = {}
        value = kwargs.pop(OPT_PROTECTED.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_PROTECTED] = value
            export_config[constants.CONFIG_KEY_PROTECTED] = value

        value = kwargs.pop(OPT_REDIRECT_URL.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_REDIRECT_URL] = value
            export_config[constants.CONFIG_KEY_REDIRECT_URL] = value

        value = kwargs.pop(OPT_REPO_REGISTRY_ID.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_REPO_REGISTRY_ID] = value
            export_config[constants.CONFIG_KEY_REPO_REGISTRY_ID] = value

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config or export_config:
            kwargs['distributor_configs'] = {}

        if web_config:
            kwargs['distributor_configs'][
                constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        if export_config:
            kwargs['distributor_configs'][
                constants.CLI_EXPORT_DISTRIBUTOR_ID] = export_config

        # Update Tags
        repo_id = kwargs.get(OPTION_REPO_ID.keyword)
        response = self.context.server.repo.repository(repo_id).response_body
        scratchpad = response.get(u'scratchpad', {})
        image_tags = scratchpad.get(u'tags', [])

        user_tags = kwargs.get(OPTION_TAG.keyword)
        if user_tags:
            user_tags = kwargs.pop(OPTION_TAG.keyword)
            for tag, image_id in user_tags:
                if len(image_id) < 6:
                    msg = _(
                        'The image id, (%s), must be at least 6 characters.')
                    self.prompt.render_failure_message(msg % image_id)
                    return

            # Ensure the specified images exist in the repo
            images_requested = set([image_id for tag, image_id in user_tags])
            images = ['^%s' % image_id for image_id in images_requested]
            image_regex = '|'.join(images)
            search_criteria = {
                'type_ids': constants.IMAGE_TYPE_ID,
                'match': [['image_id', image_regex]],
                'fields': ['image_id']
            }

            response = self.context.server.repo_unit.search(repo_id, **search_criteria).\
                response_body
            if len(response) != len(images):
                images_found = set(
                    [x[u'metadata'][u'image_id'] for x in response])
                missing_images = images_requested.difference(images_found)
                msg = _(
                    'Unable to create tag in repository. The following image(s) do not '
                    'exist in the repository: %s.')
                self.prompt.render_failure_message(msg %
                                                   ', '.join(missing_images))
                return

            # Get the full image id from the returned values and save in tags_to_update dictionary
            tags_to_update = {}
            for image in response:
                found_image_id = image[u'metadata'][u'image_id']
                for tag, image_id in user_tags:
                    if found_image_id.startswith(image_id):
                        tags_to_update[tag] = found_image_id

            # Create a list of tag dictionaries that can be saved on the repo scratchpad
            # using the original tags and new tags specified by the user
            image_tags = tags.generate_updated_tags(scratchpad, tags_to_update)
            scratchpad[u'tags'] = image_tags
            kwargs[u'scratchpad'] = scratchpad

        remove_tags = kwargs.get(OPTION_REMOVE_TAG.keyword)
        if remove_tags:
            kwargs.pop(OPTION_REMOVE_TAG.keyword)
            for tag in remove_tags:
                # For each tag in remove_tags, remove the respective tag dictionary
                # for matching tag.
                for image_tag in image_tags[:]:
                    if tag == image_tag[constants.IMAGE_TAG_KEY]:
                        image_tags.remove(image_tag)

            scratchpad[u'tags'] = image_tags
            kwargs[u'scratchpad'] = scratchpad

        super(UpdateDockerRepositoryCommand, self).run(**kwargs)
Exemple #37
0
    def run(self, **kwargs):
        arg_utils.convert_removed_options(kwargs)

        importer_config = self.parse_user_input(kwargs)

        name = kwargs.pop(OPT_UPSTREAM_NAME.keyword, None)
        if name is not None:
            importer_config[constants.CONFIG_KEY_UPSTREAM_NAME] = name

        if importer_config:
            kwargs['importer_config'] = importer_config

        # Update distributor configuration
        web_config = {}
        export_config = {}
        value = kwargs.pop(OPT_PROTECTED.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_PROTECTED] = value
            export_config[constants.CONFIG_KEY_PROTECTED] = value

        value = kwargs.pop(OPT_REDIRECT_URL.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_REDIRECT_URL] = value
            export_config[constants.CONFIG_KEY_REDIRECT_URL] = value

        value = kwargs.pop(OPT_REPO_REGISTRY_ID.keyword, None)
        if value is not None:
            web_config[constants.CONFIG_KEY_REPO_REGISTRY_ID] = value
            export_config[constants.CONFIG_KEY_REPO_REGISTRY_ID] = value

        value = kwargs.pop(OPT_AUTO_PUBLISH.keyword, None)
        if value is not None:
            web_config['auto_publish'] = value

        if web_config or export_config:
            kwargs['distributor_configs'] = {}

        if web_config:
            kwargs['distributor_configs'][constants.CLI_WEB_DISTRIBUTOR_ID] = web_config

        if export_config:
            kwargs['distributor_configs'][constants.CLI_EXPORT_DISTRIBUTOR_ID] = export_config

        # Update Tags
        repo_id = kwargs.get(OPTION_REPO_ID.keyword)
        response = self.context.server.repo.repository(repo_id).response_body
        scratchpad = response.get(u'scratchpad', {})
        image_tags = scratchpad.get(u'tags', [])

        user_tags = kwargs.get(OPTION_TAG.keyword)
        if user_tags:
            user_tags = kwargs.pop(OPTION_TAG.keyword)
            for tag, image_id in user_tags:
                if len(image_id) < 6:
                    msg = _('The image id, (%s), must be at least 6 characters.')
                    self.prompt.render_failure_message(msg % image_id)
                    return

            # Ensure the specified images exist in the repo
            images_requested = set([image_id for tag, image_id in user_tags])
            images = ['^%s' % image_id for image_id in images_requested]
            image_regex = '|'.join(images)
            search_criteria = {
                'type_ids': constants.IMAGE_TYPE_ID,
                'match': [['image_id', image_regex]],
                'fields': ['image_id']
            }

            response = self.context.server.repo_unit.search(repo_id, **search_criteria).\
                response_body
            if len(response) != len(images):
                images_found = set([x[u'metadata'][u'image_id'] for x in response])
                missing_images = images_requested.difference(images_found)
                msg = _('Unable to create tag in repository. The following image(s) do not '
                        'exist in the repository: %s.')
                self.prompt.render_failure_message(msg % ', '.join(missing_images))
                return

            # Get the full image id from the returned values and save in tags_to_update dictionary
            tags_to_update = {}
            for image in response:
                found_image_id = image[u'metadata'][u'image_id']
                for tag, image_id in user_tags:
                    if found_image_id.startswith(image_id):
                        tags_to_update[tag] = found_image_id

            # Create a list of tag dictionaries that can be saved on the repo scratchpad
            # using the original tags and new tags specified by the user
            image_tags = tags.generate_updated_tags(scratchpad, tags_to_update)
            scratchpad[u'tags'] = image_tags
            kwargs[u'scratchpad'] = scratchpad

        remove_tags = kwargs.get(OPTION_REMOVE_TAG.keyword)
        if remove_tags:
            kwargs.pop(OPTION_REMOVE_TAG.keyword)
            for tag in remove_tags:
                # For each tag in remove_tags, remove the respective tag dictionary
                # for matching tag.
                for image_tag in image_tags[:]:
                    if tag == image_tag[constants.IMAGE_TAG_KEY]:
                        image_tags.remove(image_tag)

            scratchpad[u'tags'] = image_tags
            kwargs[u'scratchpad'] = scratchpad

        super(UpdateDockerRepositoryCommand, self).run(**kwargs)