Ejemplo n.º 1
0
Archivo: bind.py Proyecto: omps/pulp
    def bind(consumer_id, repo_id, distributor_id, notify_agent,
             binding_config):
        """
        Bind consumer to a specific distributor associated with
        a repository.  This call is idempotent.
        :param consumer_id: uniquely identifies the consumer.
        :type  consumer_id: str
        :param repo_id: uniquely identifies the repository.
        :type  repo_id: str
        :param distributor_id: uniquely identifies a distributor.
        :type  distributor_id: str

        :return: The Bind object
        :rtype:  SON

        :raise MissingResource: when given consumer does not exist.
        :raise InvalidValid:    when the repository or distributor id is invalid, or
        if the notify_agent value is invalid
        """
        # Validation
        missing_values = BindManager._validate_consumer_repo(
            consumer_id, repo_id, distributor_id)
        if missing_values:
            if 'consumer_id' in missing_values:
                # This is passed in via the URL so a 404 should be raised
                raise MissingResource(
                    consumer_id=missing_values['consumer_id'])
            else:
                # Everything else is a parameter so raise a 400
                raise InvalidValue(missing_values.keys())

        # ensure notify_agent is a boolean
        if not isinstance(notify_agent, bool):
            raise InvalidValue(['notify_agent'])

        # perform the bind
        collection = Bind.get_collection()
        try:
            bind = Bind(consumer_id, repo_id, distributor_id, notify_agent,
                        binding_config)
            collection.save(bind, safe=True)
        except DuplicateKeyError:
            BindManager._update_binding(consumer_id, repo_id, distributor_id,
                                        notify_agent, binding_config)
            BindManager._reset_bind(consumer_id, repo_id, distributor_id)
        # fetch the inserted/updated bind
        bind = BindManager.get_bind(consumer_id, repo_id, distributor_id)
        # update history
        details = {'repo_id': repo_id, 'distributor_id': distributor_id}
        manager = factory.consumer_history_manager()
        manager.record_event(consumer_id, 'repo_bound', details)
        return bind
Ejemplo n.º 2
0
Archivo: bind.py Proyecto: sahwar/pulp
    def bind(self, consumer_id, repo_id, distributor_id, notify_agent,
             binding_config):
        """
        Bind consumer to a specific distributor associated with
        a repository.  This call is idempotent.
        @param consumer_id: uniquely identifies the consumer.
        @type consumer_id: str
        @param repo_id: uniquely identifies the repository.
        @type repo_id: str
        @param distributor_id: uniquely identifies a distributor.
        @type distributor_id: str
        @return: The Bind object
        @rtype: SON
        @raise MissingResource: when given consumer does not exist.
        """
        # Validation

        # ensure notify_agent is a boolean
        if not isinstance(notify_agent, bool):
            raise InvalidValue(['notify_agent'])

        # ensure the consumer is valid
        manager = factory.consumer_manager()
        manager.get_consumer(consumer_id)

        # ensure the repository & distributor are valid
        manager = factory.repo_distributor_manager()
        manager.get_distributor(repo_id, distributor_id)

        # perform the bind
        collection = Bind.get_collection()
        try:
            bind = Bind(consumer_id, repo_id, distributor_id, notify_agent,
                        binding_config)
            collection.save(bind, safe=True)
        except DuplicateKeyError:
            self._update_binding(consumer_id, repo_id, distributor_id,
                                 notify_agent, binding_config)
            self.__reset_bind(consumer_id, repo_id, distributor_id)
        # fetch the inserted/updated bind
        bind = self.get_bind(consumer_id, repo_id, distributor_id)
        # update history
        details = {'repo_id': repo_id, 'distributor_id': distributor_id}
        manager = factory.consumer_history_manager()
        manager.record_event(consumer_id, 'repo_bound', details)
        return bind