Example #1
0
 def _delete_units(self, request, unit_inventory):
     """
     Determine the list of units contained in the child inventory
     but are not contained in the parent inventory and un-associate them.
     :param request: A synchronization request.
     :type request: SyncRequest
     :param unit_inventory: The inventory of both parent and child content units.
     :type unit_inventory: UnitInventory
     """
     for unit in unit_inventory.units_on_child_only():
         if request.cancelled():
             return
         try:
             _unit = AssociatedUnit(
                 type_id=unit['type_id'],
                 unit_key=unit['unit_key'],
                 metadata={},
                 storage_path=None,
                 created=None,
                 updated=None)
             _unit.id = unit['unit_id']
             request.conduit.remove_unit(_unit)
         except Exception:
             _log.exception(unit['unit_id'])
             request.summary.errors.append(DeleteUnitError(request.repo_id))
Example #2
0
def to_plugin_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of content unit into the plugin's object
    representation.

    @param pulp_unit: raw dictionary of unit metadata
    @type  pulp_unit: dict

    @param type_def: Pulp stored definition for the unit type
    @type  type_def: L{pulp.server.db.model.content.ContentType}

    @return: plugin unit representation of the given unit
    @rtype:  L{pulp.server.content.plugins.data.AssociatedUnit}
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit["metadata"] = dict(pulp_unit["metadata"])

    key_list = type_def["unit_key"]

    unit_key = {}

    for k in key_list:
        unit_key[k] = pulp_unit["metadata"].pop(k)

    storage_path = pulp_unit["metadata"].pop("_storage_path", None)
    unit_id = pulp_unit.pop("unit_id", None)
    created = pulp_unit.pop("created", None)
    updated = pulp_unit.pop("updated", None)
    owner_type = pulp_unit.pop("owner_type", None)
    owner_id = pulp_unit.pop("owner_id", None)

    u = AssociatedUnit(
        type_def["id"], unit_key, pulp_unit["metadata"], storage_path, created, updated, owner_type, owner_id
    )
    u.id = unit_id

    return u
Example #3
0
def to_plugin_associated_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object representation.

    @param pulp_unit: raw dictionary of unit metadata
    @type  pulp_unit: dict

    @param type_def: Pulp stored definition for the unit type
    @type  type_def: pulp.server.db.model.content.ContentType

    @return: plugin unit representation of the given unit
    @rtype:  pulp.plugins.model.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    key_list = type_def['unit_key']

    unit_key = {}

    for k in key_list:
        unit_key[k] = pulp_unit['metadata'].pop(k)

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)
    owner_type = pulp_unit.pop('owner_type', None)
    owner_id = pulp_unit.pop('owner_id', None)

    u = AssociatedUnit(type_def['id'], unit_key, pulp_unit['metadata'],
                       storage_path, created, updated, owner_type, owner_id)
    u.id = unit_id

    return u
Example #4
0
def to_plugin_associated_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object representation.

    @param pulp_unit: raw dictionary of unit metadata
    @type  pulp_unit: dict

    @param type_def: Pulp stored definition for the unit type
    @type  type_def: pulp.server.db.model.content.ContentType

    @return: plugin unit representation of the given unit
    @rtype:  pulp.plugins.model.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    key_list = type_def['unit_key']

    unit_key = {}

    for k in key_list:
        unit_key[k] = pulp_unit['metadata'].pop(k)

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)
    owner_type = pulp_unit.pop('owner_type', None)
    owner_id = pulp_unit.pop('owner_id', None)

    u = AssociatedUnit(type_def['id'], unit_key, pulp_unit['metadata'], storage_path,
                       created, updated, owner_type, owner_id)
    u.id = unit_id

    return u
Example #5
0
def to_plugin_associated_unit(pulp_unit, unit_type_id, unit_key_fields):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object representation.

    :param pulp_unit: raw dictionary of unit metadata
    :type  pulp_unit: dict
    :param unit_type_id: unique identifier for the type of unit
    :type  unit_type_id: str
    :param unit_key_fields: collection of keys required for the type's unit key
    :type  unit_key_fields: list or tuple

    :return: plugin unit representation of the given unit
    :rtype:  pulp.plugins.model.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    unit_key = {}

    for k in unit_key_fields:
        unit_key[k] = pulp_unit['metadata'].pop(k)

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)

    u = AssociatedUnit(unit_type_id, unit_key, pulp_unit['metadata'],
                       storage_path, created, updated)
    u.id = unit_id

    return u
Example #6
0
def to_plugin_associated_unit(pulp_unit, unit_type_id, unit_key_fields):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object representation.

    :param pulp_unit: raw dictionary of unit metadata
    :type  pulp_unit: dict
    :param unit_type_id: unique identifier for the type of unit
    :type  unit_type_id: str
    :param unit_key_fields: collection of keys required for the type's unit key
    :type  unit_key_fields: list or tuple

    :return: plugin unit representation of the given unit
    :rtype:  pulp.plugins.model.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    unit_key = {}

    for k in unit_key_fields:
        unit_key[k] = pulp_unit['metadata'].pop(k)

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)

    u = AssociatedUnit(unit_type_id, unit_key, pulp_unit['metadata'], storage_path,
                       created, updated)
    u.id = unit_id

    return u