Пример #1
0
    def run(self, **kwargs):
        consumer_id = self.get_consumer_id(kwargs)
        delta = dict((k, v) for k, v in kwargs.items() if v is not None)

        if OPTION_NOTES.keyword in delta:
            notes_args = delta.pop(OPTION_NOTES.keyword)
            delta['notes'] = args_to_notes_dict(notes_args)

        if OPTION_NAME.keyword in delta:
            name = delta.pop(OPTION_NAME.keyword)
            delta[OPTION_NAME.keyword.replace('-', '_')] = name

        try:
            self.context.server.consumer.update(consumer_id, delta)

        except NotFoundException:
            msg = _('Consumer [ %(c)s ] does not exist on server') % {
                'c': consumer_id
            }
            self.context.prompt.render_failure_message(msg)
            return os.EX_DATAERR

        else:
            msg = _('Consumer [ %(c)s ] successfully updated') % {
                'c': consumer_id
            }
            self.context.prompt.render_success_message(msg)
Пример #2
0
Файл: cudl.py Проект: omps/pulp
    def _parse_basic_options(self, kwargs):
        """
        Parse the options known by this class

        :param kwargs:  user input as provided by okaara
        :type  kwargs:  dict

        :return:    tuple of repo_id, name, description, notes
        :rtype:     tuple
        """

        # Collect input
        repo_id = kwargs[OPTION_REPO_ID.keyword]
        name = repo_id
        if OPTION_NAME.keyword in kwargs:
            name = kwargs[OPTION_NAME.keyword]
        description = kwargs[OPTION_DESCRIPTION.keyword]
        if kwargs[OPTION_NOTES.keyword]:
            notes = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword],
                                                 include_none=True)
        else:
            notes = {}
        notes.update(self.default_notes)

        return repo_id, name, description, notes
Пример #3
0
    def update(self, **kwargs):

        # Assemble the delta for all options that were passed in
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message(
                "This consumer is not registered to the Pulp server.")
            return
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        if 'note' in delta.keys():
            if delta['note']:
                delta['notes'] = args_to_notes_dict(kwargs['note'],
                                                    include_none=False)
            delta.pop('note')
        # convert display-name to display_name
        key = 'display-name'
        if key in delta:
            v = delta.pop(key)
            key = key.replace('-', '_')
            delta[key] = v

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.prompt.render_success_message(
                'Consumer [%s] successfully updated' % consumer_id)
        except NotFoundException:
            self.prompt.write('Consumer [%s] does not exist on the server' %
                              consumer_id,
                              tag='not-found')
Пример #4
0
    def create(self, **kwargs):

        # All of the options will be present, even if the user didn't specify
        # them. Their values will be None, which the yum importer is set up
        # to handle.

        # Gather data
        repo_id = kwargs.pop('repo-id')
        description = kwargs.pop('description', None)
        display_name = kwargs.pop('display-name', None)
        auto_publish = kwargs.pop('auto-publish', None)

        if auto_publish:
            auto_publish = arg_to_bool(auto_publish)
            if auto_publish:
                self.context.prompt.render_failure_message(_('Value for auto-publish must be either true or false'))
                return

        try:
            notes = None
            if 'note' in kwargs and kwargs['note'] is not None:
                notes = args_to_notes_dict(kwargs['note'], include_none=False)
            importer_config = args_to_importer_config(kwargs)
            distributor_config = args_to_distributor_config(kwargs)
        except InvalidConfig, e:
            self.context.prompt.render_failure_message(e[0])
            return
Пример #5
0
    def test_dict_arg(self):
        """
        Tests to make sure that attempting to parse a dict returns the dict
        """
        # Setup
        test_dict = {'key': 'value', 'key2': 'value2'}

        # Test
        result = arg_utils.args_to_notes_dict(test_dict)
        self.assertTrue(test_dict is result)
Пример #6
0
    def test_dict_arg(self):
        """
        Tests to make sure that attempting to parse a dict returns the dict
        """
        # Setup
        test_dict = {'key': 'value', 'key2': 'value2'}

        # Test
        result = arg_utils.args_to_notes_dict(test_dict)
        self.assertTrue(test_dict is result)
Пример #7
0
    def test_include_none_false(self):
        """
        Tests to make sure keys with null values are not returned when include_none=False
        """
        # Setup
        test_list = ['key=value', 'key2=', 'key3=""']

        # Test
        result = arg_utils.args_to_notes_dict(test_list, include_none=False)
        self.assertTrue('key' in result)
        self.assertEqual(result['key'], 'value')
        self.assertFalse('key2' in result)
        self.assertFalse('key3' in result)
Пример #8
0
    def test_include_none_false(self):
        """
        Tests to make sure keys with null values are not returned when include_none=False
        """
        # Setup
        test_list = ['key=value', 'key2=', 'key3=""']

        # Test
        result = arg_utils.args_to_notes_dict(test_list, include_none=False)
        self.assertTrue('key' in result)
        self.assertEqual(result['key'], 'value')
        self.assertFalse('key2' in result)
        self.assertFalse('key3' in result)
Пример #9
0
    def create(self, **kwargs):

        # Collect input
        id = kwargs['repo-id']
        name = id
        if 'display-name' in kwargs:
            name = kwargs['display-name']
        description = kwargs['description']
        notes = arg_utils.args_to_notes_dict(kwargs['note'], include_none=True)

        # Call the server
        self.context.server.repo.create(id, name, description, notes)
        self.prompt.render_success_message('Repository [%s] successfully created' % id)
Пример #10
0
    def run(self, **kwargs):
        # Collect input
        id = kwargs[OPTION_REPO_ID.keyword]
        name = id
        if OPTION_NAME.keyword in kwargs:
            name = kwargs[OPTION_NAME.keyword]
        description = kwargs[OPTION_DESCRIPTION.keyword]
        notes = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword], include_none=True)

        # Call the server
        self.context.server.repo.create(id, name, description, notes)
        msg = _('Repository [%(r)s] successfully created')
        self.prompt.render_success_message(msg % {'r' : id})
Пример #11
0
    def run(self, **kwargs):
        # Collect input
        repo_id = kwargs[OPTION_REPO_ID.keyword]
        name = repo_id
        if OPTION_NAME.keyword in kwargs:
            name = kwargs[OPTION_NAME.keyword]
        description = kwargs[OPTION_DESCRIPTION.keyword]
        notes = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword],
                                             include_none=True)

        # Call the server
        self.context.server.repo.create(repo_id, name, description, notes)
        msg = _('Repository [%(r)s] successfully created')
        self.prompt.render_success_message(msg % {'r': repo_id})
Пример #12
0
    def update(self, **kwargs):
        # Assemble the delta for all options that were passed in
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        delta.pop('group-id') # not needed in the delta

        if delta.pop('note', None) is not None:
            delta['notes'] = arg_utils.args_to_notes_dict(kwargs['note'], include_none=True)
        try:
            self.context.server.repo_group.update(kwargs['group-id'], delta)
            self.prompt.render_success_message(
                'Repo group [%s] successfully updated' % kwargs['group-id'])
        except NotFoundException:
            self.prompt.write(
                'Repo group [%s] does not exist on the server' % kwargs['group-id'], tag='not-found')
Пример #13
0
    def run(self, **kwargs):
        # Assemble the delta for all options that were passed in
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        delta.pop(OPTION_GROUP_ID.keyword) # not needed in the delta

        if delta.pop(OPTION_NOTES.keyword, None) is not None:
            delta['notes'] = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword], include_none=True)
        try:
            self.context.server.repo_group.update(kwargs[OPTION_GROUP_ID.keyword], delta)
            msg = 'Repo group [%(g)s] successfully updated'
            self.prompt.render_success_message(msg % {'g' : kwargs['group-id']})
        except NotFoundException:
            msg = 'Repo group [%(g)s] does not exist on the server'
            self.prompt.write(msg % {'g' : kwargs['group-id']}, tag='not-found')
Пример #14
0
    def create(self, **kwargs):
        # Collect input
        consumer_group_id = kwargs['consumer-group-id']
        name = consumer_group_id
        if 'display-name' in kwargs:
            name = kwargs['display-name']
        description = kwargs['description']
        notes = kwargs.get('notes', None)
        if notes:
            notes = arg_utils.args_to_notes_dict(notes, include_none=True)

        # Call the server
        self.context.server.consumer_group.create(consumer_group_id, name, description, notes)
        self.prompt.render_success_message(
            'Consumer Group [%s] successfully created' % consumer_group_id)
Пример #15
0
    def register(self, **kwargs):

        # Get consumer id
        id = kwargs['consumer-id']

        # Check if this consumer is already registered
        existing_consumer = load_consumer_id(self.context)
        if existing_consumer:
            m = _(
                'This system has already been registered as a consumer. Please '
                'use the unregister command to remove the consumer before attempting '
                'to re-register.')
            self.prompt.render_failure_message(m)
            return

        # Get other consumer parameters
        name = id
        if 'display-name' in kwargs:
            name = kwargs['display-name']
        description = kwargs['description']
        notes = None
        if 'note' in kwargs.keys():
            if kwargs['note']:
                notes = args_to_notes_dict(kwargs['note'], include_none=False)

        # Check write permissions to cert directory
        id_cert_dir = self.context.config['filesystem']['id_cert_dir']
        if not os.access(id_cert_dir, os.W_OK):
            msg = _(
                "Write permission is required for %(d)s to perform this operation."
            )
            self.prompt.render_failure_message(msg % {'d': id_cert_dir})
            return exceptions.CODE_PERMISSIONS_EXCEPTION

        # Call the server
        consumer = self.context.server.consumer.register(
            id, name, description, notes).response_body

        # Write consumer cert
        id_cert_name = self.context.config['filesystem']['id_cert_filename']
        cert_filename = os.path.join(id_cert_dir, id_cert_name)
        f = open(cert_filename, 'w')
        f.write(consumer['certificate'])
        f.close()

        self.prompt.render_success_message(
            'Consumer [%s] successfully registered' % id)
Пример #16
0
    def update(self, **kwargs):

        # Assemble the delta for all options that were passed in
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        delta.pop(OPTION_CONSUMER_ID.keyword) # not needed in the delta
        if OPTION_NOTES.keyword in delta.keys():
            delta['notes'] = args_to_notes_dict(delta['note'])
            delta.pop(OPTION_NOTES.keyword)
        if OPTION_NAME.keyword in delta:
            v = delta.pop(OPTION_NAME.keyword)
            key = OPTION_NAME.keyword.replace('-', '_')
            delta[key] = v

        try:
            self.context.server.consumer.update(kwargs[OPTION_CONSUMER_ID.keyword], delta)
            self.prompt.render_success_message('Consumer [%s] successfully updated' % kwargs[OPTION_CONSUMER_ID.keyword])
        except NotFoundException:
            self.prompt.write('Consumer [%s] does not exist on the server' % kwargs[OPTION_CONSUMER_ID.keyword], tag='not-found')
Пример #17
0
    def update(self, **kwargs):

        # Assemble the delta for all options that were passed in
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
            return
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        if 'note' in delta.keys():
            if delta['note']:
                delta['notes'] = args_to_notes_dict(kwargs['note'], include_none=False)
            delta.pop('note')

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.prompt.render_success_message('Consumer [%s] successfully updated' % consumer_id)
        except NotFoundException:
            self.prompt.write('Consumer [%s] does not exist on the server' % consumer_id, tag='not-found')
Пример #18
0
    def update(self, **kwargs):
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message(
                "This consumer is not registered to the Pulp "
                "server.")
            return

        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        if 'note' in delta.keys():
            if delta['note']:
                delta['notes'] = args_to_notes_dict(kwargs['note'],
                                                    include_none=False)
            delta.pop('note')
        # convert display-name to display_name
        key = 'display-name'
        if key in delta:
            v = delta.pop(key)
            key = key.replace('-', '_')
            delta[key] = v

        if kwargs.get(OPTION_EXCHANGE_KEYS.keyword):
            path = self.context.config['authentication']['rsa_pub']
            fp = open(path)
            try:
                delta['rsa_pub'] = fp.read()
            finally:
                fp.close()

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.prompt.render_success_message(
                'Consumer [%s] successfully updated' % consumer_id)
            if not kwargs.get(OPTION_EXCHANGE_KEYS.keyword):
                return
            try:
                update_server_key(self.context.config)
            except Exception, e:
                msg = _('Download server RSA key failed [%(e)s]' % {'e': e})
                self.prompt.render_failure_message(msg)
        except NotFoundException:
            self.prompt.write('Consumer [%s] does not exist on the server' %
                              consumer_id,
                              tag='not-found')
Пример #19
0
    def register(self, **kwargs):

        # Get consumer id
        id = kwargs["consumer-id"]

        # Check if this consumer is already registered
        existing_consumer = load_consumer_id(self.context)
        if existing_consumer:
            m = (
                "This system has already been registered as a consumer. Please "
                "use the unregister command to remove the consumer before attempting "
                "to reregister."
            )
            self.prompt.render_failure_message(_(m))
            return

        # Get other consumer parameters
        name = id
        if "display-name" in kwargs:
            name = kwargs["display-name"]
        description = kwargs["description"]
        notes = None
        if "note" in kwargs.keys():
            if kwargs["note"]:
                notes = args_to_notes_dict(kwargs["note"], include_none=False)

        # Check write permissions to cert directory
        id_cert_dir = self.context.config["filesystem"]["id_cert_dir"]
        if not os.access(id_cert_dir, os.W_OK):
            msg = _("Write permission is required for %(d)s to perform this operation.")
            self.prompt.render_failure_message(msg % {"d": id_cert_dir})
            return os.EX_NOPERM

        # Call the server
        consumer = self.context.server.consumer.register(id, name, description, notes).response_body

        # Write consumer cert
        id_cert_name = self.context.config["filesystem"]["id_cert_filename"]
        cert_filename = os.path.join(id_cert_dir, id_cert_name)
        f = open(cert_filename, "w")
        f.write(consumer["certificate"])
        f.close()

        self.prompt.render_success_message("Consumer [%s] successfully registered" % id)
Пример #20
0
    def run(self, **kwargs):
        # Assemble the delta for all options that were passed in
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        delta.pop(OPTION_REPO_ID.keyword) # not needed in the delta

        # Translate the argument to key name
        if delta.pop(OPTION_NAME.keyword, None) is not None:
            delta['display_name'] = kwargs[OPTION_NAME.keyword]

        if delta.pop(OPTION_NOTES.keyword, None) is not None:
            delta['notes'] = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword], include_none=True)

        try:
            self.context.server.repo.update(kwargs[OPTION_REPO_ID.keyword], delta)
            msg = _('Repository [%(r)s] successfully updated')
            self.prompt.render_success_message(msg % {'r' : kwargs[OPTION_REPO_ID.keyword]})
        except NotFoundException:
            msg = _('Repository [%(r)s] does not exist on the server')
            self.prompt.write(msg % {'r' : kwargs[OPTION_REPO_ID.keyword]}, tag='not-found')
Пример #21
0
def parse_notes(value):
    """
    Returns a value suitable to send to the server for a notes value on a
    repository. The given value will actually be a list of values regardless
    of whether or not the user specified multiple notes.

    :param value: list of user entered values or empty list if unspecified
    :type  value: list
    :return: dictionary representation of all user entered notes
    :rtype: dict
    """

    if value is None:
        return None

    try:
        return arg_utils.args_to_notes_dict(value)
    except arg_utils.InvalidConfig:
        raise ValueError(_('invalid syntax for specifying notes'))
Пример #22
0
def parse_notes(value):
    """
    Returns a value suitable to send to the server for a notes value on a
    repository. The given value will actually be a list of values regardless
    of whether or not the user specified multiple notes.

    :param value: list of user entered values or empty list if unspecified
    :type  value: list
    :return: dictionary representation of all user entered notes
    :rtype: dict
    """

    if value is None:
        return None

    try:
        return arg_utils.args_to_notes_dict(value)
    except arg_utils.InvalidConfig:
        raise ValueError(_('invalid syntax for specifying notes'))
Пример #23
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)
Пример #24
0
    def register(self, **kwargs):

        # Get consumer id
        id = kwargs['consumer-id']

        # Check if this consumer is already registered
        existing_consumer = load_consumer_id(self.context)
        if existing_consumer:
            m = _('This system has already been registered as a consumer. Please '
                  'use the unregister command to remove the consumer before attempting '
                  'to re-register.')
            self.prompt.render_failure_message(m)
            return

        # Get other consumer parameters
        name = id
        if 'display-name' in kwargs:
            name = kwargs['display-name']
        description = kwargs['description']
        notes = None
        if 'note' in kwargs.keys():
            if kwargs['note']:
                notes = args_to_notes_dict(kwargs['note'], include_none=False)

        # Check write permissions to cert directory
        id_cert_dir = self.context.config['filesystem']['id_cert_dir']
        if not os.access(id_cert_dir, os.W_OK):
            msg = _("Write permission is required for %(d)s to perform this operation.")
            self.prompt.render_failure_message(msg % {'d': id_cert_dir})
            return exceptions.CODE_PERMISSIONS_EXCEPTION

        # Call the server
        consumer = self.context.server.consumer.register(id, name, description, notes).response_body

        # Write consumer cert
        id_cert_name = self.context.config['filesystem']['id_cert_filename']
        cert_filename = os.path.join(id_cert_dir, id_cert_name)
        f = open(cert_filename, 'w')
        f.write(consumer['certificate'])
        f.close()

        self.prompt.render_success_message('Consumer [%s] successfully registered' % id)
Пример #25
0
    def update(self, **kwargs):
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message("This consumer is not registered to the Pulp "
                                               "server.")
            return

        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        if 'note' in delta.keys():
            if delta['note']:
                delta['notes'] = args_to_notes_dict(kwargs['note'], include_none=False)
            delta.pop('note')
        # convert display-name to display_name
        key = 'display-name'
        if key in delta:
            v = delta.pop(key)
            key = key.replace('-', '_')
            delta[key] = v

        if kwargs.get(OPTION_EXCHANGE_KEYS.keyword):
            path = self.context.config['authentication']['rsa_pub']
            fp = open(path)
            try:
                delta['rsa_pub'] = fp.read()
            finally:
                fp.close()

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.prompt.render_success_message('Consumer [%s] successfully updated' % consumer_id)
            if not kwargs.get(OPTION_EXCHANGE_KEYS.keyword):
                return
            try:
                update_server_key(self.context.config)
            except Exception, e:
                msg = _('Download server RSA key failed [%(e)s]' % {'e': e})
                self.prompt.render_failure_message(msg)
        except NotFoundException:
            self.prompt.write('Consumer [%s] does not exist on the server' % consumer_id,
                              tag='not-found')
Пример #26
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})
Пример #27
0
    def run(self, **kwargs):
        consumer_id = self.get_consumer_id(kwargs)
        delta = dict((k, v) for k, v in kwargs.items() if v is not None)

        if OPTION_NOTES.keyword in delta:
            notes_args = delta.pop(OPTION_NOTES.keyword)
            delta["notes"] = args_to_notes_dict(notes_args)

        if OPTION_NAME.keyword in delta:
            name = delta.pop(OPTION_NAME.keyword)
            delta[OPTION_NAME.keyword.replace("-", "_")] = name

        try:
            self.context.server.consumer.update(consumer_id, delta)

        except NotFoundException:
            msg = _("Consumer [ %(c)s ] does not exist on server") % {"c": consumer_id}
            self.context.prompt.render_failure_message(msg)
            return os.EX_DATAERR

        else:
            msg = _("Consumer [ %(c)s ] successfully updated") % {"c": consumer_id}
            self.context.prompt.render_success_message(msg)
Пример #28
0
    def update(self, **kwargs):

        # Gather data
        repo_id = kwargs.pop('repo-id')
        description = kwargs.pop('description', None)
        display_name = kwargs.pop('display-name', None)
        auto_publish = kwargs.pop('auto-publish', None)

        if auto_publish:
            auto_publish = arg_to_bool(auto_publish)
            if auto_publish is None:
                self.context.prompt.render_failure_message(_('Value for auto-publish must be either true or false'))
                return

        try:
            notes = None
            if 'note' in kwargs and kwargs['note'] is not None:
                notes = args_to_notes_dict(kwargs['note'], include_none=True)

            importer_config = args_to_importer_config(kwargs)
        except InvalidConfig, e:
            self.context.prompt.render_failure_message(e[0])
            return
Пример #29
0
    def update(self, **kwargs):

        # Assemble the delta for all options that were passed in
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
            return
        delta = dict([(k, v) for k, v in kwargs.items() if v is not None])
        if "note" in delta.keys():
            if delta["note"]:
                delta["notes"] = args_to_notes_dict(kwargs["note"], include_none=False)
            delta.pop("note")
        # convert display-name to display_name
        key = "display-name"
        if key in delta:
            v = delta.pop(key)
            key = key.replace("-", "_")
            delta[key] = v

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.prompt.render_success_message("Consumer [%s] successfully updated" % consumer_id)
        except NotFoundException:
            self.prompt.write("Consumer [%s] does not exist on the server" % consumer_id, tag="not-found")
Пример #30
0
    def _parse_basic_options(self, kwargs):
        """
        Parse the options known by this class

        :param kwargs:  user input as provided by okaara
        :type  kwargs:  dict

        :return:    tuple of repo_id, name, description, notes
        :rtype:     tuple
        """

        # Collect input
        repo_id = kwargs[OPTION_REPO_ID.keyword]
        name = repo_id
        if OPTION_NAME.keyword in kwargs:
            name = kwargs[OPTION_NAME.keyword]
        description = kwargs[OPTION_DESCRIPTION.keyword]
        if kwargs[OPTION_NOTES.keyword]:
            notes = arg_utils.args_to_notes_dict(kwargs[OPTION_NOTES.keyword], include_none=True)
        else:
            notes = {}
        notes.update(self.default_notes)

        return repo_id, name, description, notes
Пример #31
0
    def register(self, **kwargs):
        consumer_id = kwargs['consumer-id']

        # Check if this consumer is already registered

        existing_consumer = load_consumer_id(self.context)
        if existing_consumer:
            m = _(
                'This system has already been registered as a consumer. Please '
                'use the unregister command to remove the consumer before attempting '
                'to re-register.')
            self.prompt.render_failure_message(m)
            return

        # Get other consumer parameters

        name = kwargs.get('display-name', consumer_id)
        description = kwargs.get('description')
        notes = kwargs.get('note')
        if notes:
            notes = args_to_notes_dict(notes, include_none=False)

        # Check write permissions to cert directory
        id_cert_dir = self.context.config['filesystem']['id_cert_dir']
        if not os.access(id_cert_dir, os.W_OK):
            msg = _(
                "Write permission is required for %(d)s to perform this operation."
            )
            self.prompt.render_failure_message(msg % {'d': id_cert_dir})
            return exceptions.CODE_PERMISSIONS_EXCEPTION

        # RSA key
        path = self.context.config['authentication']['rsa_key']
        key = RSA.gen_key(2048, 65535, no_passphrase_callback)
        key.save_key(path, None)
        path = self.context.config['authentication']['rsa_pub']
        key.save_pub_key(path)
        fp = open(path)
        try:
            rsa_pub = fp.read()
        finally:
            fp.close()

        # Call the server

        reply = self.context.server.consumer.register(consumer_id,
                                                      name=name,
                                                      description=description,
                                                      notes=notes,
                                                      rsa_pub=rsa_pub)

        certificate = reply.response_body['certificate']

        # Write consumer certificate

        id_cert_name = self.context.config['filesystem']['id_cert_filename']
        cert_filename = os.path.join(id_cert_dir, id_cert_name)
        fp = open(cert_filename, 'w')
        try:
            fp.write(certificate)
        finally:
            fp.close()

        # download server public key

        try:
            update_server_key(self.context.config)
        except Exception, e:
            msg = _('Download server RSA key failed [%(e)s]' % {'e': e})
            self.prompt.render_failure_message(msg)
Пример #32
0
    def register(self, **kwargs):
        consumer_id = kwargs['consumer-id']

        # Check if this consumer is already registered

        existing_consumer = load_consumer_id(self.context)
        if existing_consumer:
            m = _('This system has already been registered as a consumer. Please '
                  'use the unregister command to remove the consumer before attempting '
                  'to re-register.')
            self.prompt.render_failure_message(m)
            return

        # Get other consumer parameters

        name = kwargs.get('display-name', consumer_id)
        description = kwargs.get('description')
        notes = kwargs.get('note')
        if notes:
            notes = args_to_notes_dict(notes, include_none=False)

        # Check write permissions to cert directory
        id_cert_dir = self.context.config['filesystem']['id_cert_dir']
        if not os.access(id_cert_dir, os.W_OK):
            msg = _("Write permission is required for %(d)s to perform this operation.")
            self.prompt.render_failure_message(msg % {'d': id_cert_dir})
            return exceptions.CODE_PERMISSIONS_EXCEPTION

        # RSA key
        path = self.context.config['authentication']['rsa_key']
        key = RSA.gen_key(2048, 65535, no_passphrase_callback)
        key.save_key(path, None)
        path = self.context.config['authentication']['rsa_pub']
        key.save_pub_key(path)
        fp = open(path)
        try:
            rsa_pub = fp.read()
        finally:
            fp.close()

        # Call the server

        reply = self.context.server.consumer.register(
            consumer_id,
            name=name,
            description=description,
            notes=notes,
            rsa_pub=rsa_pub)

        certificate = reply.response_body['certificate']

        # Write consumer certificate

        id_cert_name = self.context.config['filesystem']['id_cert_filename']
        cert_filename = os.path.join(id_cert_dir, id_cert_name)
        # os.WRONLY opens the file for writing only; os.O_CREAT will create the
        # file if it does not already exist.
        fp = os.fdopen(os.open(cert_filename, os.O_WRONLY | os.O_CREAT, 0600), 'w')
        try:
            fp.write(certificate)
        finally:
            fp.close()

        update_server_key(self)
        self.prompt.render_success_message('Consumer [%s] successfully registered' % consumer_id)