Beispiel #1
0
    def save_unit(self, unit):
        """
        Performs two distinct steps on the Pulp server:
        - Creates or updates Pulp's knowledge of the content unit.
        - Associates the unit to the repository being synchronized.

        If a unit with the provided unit key already exists, it is updated with
        the attributes on the passed-in unit.

        A reference to the provided unit is returned from this call. This call
        will populate the unit's id field with the UUID for the unit.

        :param unit: unit object returned from the init_unit call
        :type  unit: Unit

        :return: object reference to the provided unit, its state updated from the call
        :rtype:  Unit
        """
        try:
            association_manager = manager_factory.repo_unit_association_manager()

            # Save or update the unit
            pulp_unit = common_utils.to_pulp_unit(unit)
            unit.id = self._update_unit(unit, pulp_unit)

            # Associate it with the repo
            association_manager.associate_unit_by_id(
                self.repo_id, unit.type_id, unit.id)

            return unit
        except Exception, e:
            _logger.exception(_('Content unit association failed [%s]' % str(unit)))
            raise ImporterConduitException(e), None, sys.exc_info()[2]
Beispiel #2
0
    def save_unit(self, unit):
        """
        Performs two distinct steps on the Pulp server:
        - Creates or updates Pulp's knowledge of the content unit.
        - Associates the unit to the repository being synchronized.

        This call is idempotent. If the unit already exists or the association
        already exists, this call will have no effect.

        A reference to the provided unit is returned from this call. This call
        will populate the unit's id field with the UUID for the unit.

        @param unit: unit object returned from the init_unit call
        @type  unit: L{Unit}

        @return: object reference to the provided unit, its state updated from the call
        @rtype:  L{Unit}
        """
        try:
            content_query_manager = manager_factory.content_query_manager()
            content_manager = manager_factory.content_manager()
            association_manager = manager_factory.repo_unit_association_manager(
            )

            # Save or update the unit
            pulp_unit = common_utils.to_pulp_unit(unit)
            try:
                existing_unit = content_query_manager.get_content_unit_by_keys_dict(
                    unit.type_id, unit.unit_key)
                unit.id = existing_unit['_id']
                content_manager.update_content_unit(unit.type_id, unit.id,
                                                    pulp_unit)
                self._updated_count += 1
            except MissingResource:
                unit.id = content_manager.add_content_unit(
                    unit.type_id, None, pulp_unit)
                self._added_count += 1

            # Associate it with the repo
            association_manager.associate_unit_by_id(
                self.repo_id, unit.type_id, unit.id,
                self.association_owner_type, self.association_owner_id)

            return unit
        except Exception, e:
            _LOG.exception(
                _('Content unit association failed [%s]' % str(unit)))
            raise ImporterConduitException(e), None, sys.exc_info()[2]
Beispiel #3
0
    def save_unit(self, unit):
        """
        Performs two distinct steps on the Pulp server:
        - Creates or updates Pulp's knowledge of the content unit.
        - Associates the unit to the repository being synchronized.

        If a unit with the provided unit key already exists, it is updated with
        the attributes on the passed-in unit.

        A reference to the provided unit is returned from this call. This call
        will populate the unit's id field with the UUID for the unit.

        @param unit: unit object returned from the init_unit call
        @type  unit: L{Unit}

        @return: object reference to the provided unit, its state updated from the call
        @rtype:  L{Unit}
        """
        try:
            content_query_manager = manager_factory.content_query_manager()
            content_manager = manager_factory.content_manager()
            association_manager = manager_factory.repo_unit_association_manager()

            # Save or update the unit
            pulp_unit = common_utils.to_pulp_unit(unit)
            try:
                existing_unit = content_query_manager.get_content_unit_by_keys_dict(unit.type_id, unit.unit_key)
                unit.id = existing_unit['_id']
                content_manager.update_content_unit(unit.type_id, unit.id, pulp_unit)
                self._updated_count += 1
            except MissingResource:
                unit.id = content_manager.add_content_unit(unit.type_id, None, pulp_unit)
                self._added_count += 1

            # Associate it with the repo
            association_manager.associate_unit_by_id(self.repo_id, unit.type_id, unit.id, self.association_owner_type, self.association_owner_id)

            return unit
        except Exception, e:
            _LOG.exception(_('Content unit association failed [%s]' % str(unit)))
            raise ImporterConduitException(e), None, sys.exc_info()[2]