コード例 #1
0
ファイル: publish.py プロジェクト: pombreda/pulp_puppet
    def _generate_metadata(self, modules):
        """
        Generates the repository metadata document for all modules in the

        :type modules: list of pulp.plugins.model.AssociatedUnit
        """
        _logger.info('Generating metadata for repository <%s>' % self.repo.id)

        # Convert the Pulp data types into the local model
        metadata = RepositoryMetadata()

        for m in modules:
            combined = copy.copy(m.unit_key)
            combined.update(m.metadata)
            module = Module.from_dict(combined)
            metadata.modules.append(module)

        # Write the JSON representation of the metadata to the repository
        json_metadata = metadata.to_json()
        build_dir = self._build_dir()
        metadata_file = os.path.join(build_dir,
                                     constants.REPO_METADATA_FILENAME)

        f = open(metadata_file, 'w')
        f.write(json_metadata)
        f.close()
コード例 #2
0
ファイル: publish.py プロジェクト: bmbouter/pulp_puppet
    def _generate_metadata(self, modules):
        """
        Generates the repository metadata document for all modules in the

        :type modules: list of pulp.plugins.model.AssociatedUnit
        """
        _logger.info('Generating metadata for repository <%s>' % self.repo.id)

        # Convert the Pulp data types into the local model
        metadata = RepositoryMetadata()

        for m in modules:
            combined = copy.copy(m.unit_key)
            combined.update(m.metadata)
            module = Module.from_dict(combined)
            metadata.modules.append(module)

        # Write the JSON representation of the metadata to the repository
        json_metadata = metadata.to_json()
        build_dir = self._build_dir()
        metadata_file = os.path.join(build_dir, constants.REPO_METADATA_FILENAME)

        f = open(metadata_file, 'w')
        f.write(json_metadata)
        f.close()
コード例 #3
0
    def test_from_dict(self):
        # Setup
        data = json.loads(VALID_MODULE_METADATA_JSON)

        # Test
        module = Module.from_dict(data)

        # Verify
        self.assert_valid_module(module)
コード例 #4
0
ファイル: test_common_model.py プロジェクト: jlsherrill/pulp
    def test_from_dict(self):
        # Setup
        data = json.loads(VALID_MODULE_METADATA_JSON)

        # Test
        module = Module.from_dict(data)

        # Verify
        self.assert_valid_module(module)
コード例 #5
0
def handle_uploaded_unit(repo, type_id, unit_key, metadata, file_path,
                         conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param repo: repository into which the unit is being uploaded
    :type  repo: pulp.plugins.model.Repository
    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module with unit_key if supplied
    initial_module = None
    if unit_key:
        initial_module = Module.from_dict(unit_key)

    # Extract the metadata from the module
    extracted_data = metadata_parser.extract_metadata(file_path,
                                                      repo.working_dir,
                                                      initial_module)
    checksum = metadata_parser.calculate_checksum(file_path)

    # Create a module from the metadata
    module = Module.from_json(extracted_data)
    module.checksum = checksum

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    return {'success_flag': True, 'summary': '', 'details': {}}
コード例 #6
0
ファイル: upload.py プロジェクト: asmacdo/pulp_puppet
def handle_uploaded_unit(repo, type_id, unit_key, metadata, file_path, conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param repo: repository into which the unit is being uploaded
    :type  repo: pulp.plugins.model.Repository
    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module with unit_key if supplied
    initial_module = None
    if unit_key:
        initial_module = Module.from_dict(unit_key)

    # Extract the metadata from the module
    extracted_data = metadata_parser.extract_metadata(file_path, repo.working_dir, initial_module)
    checksum = metadata_parser.calculate_checksum(file_path)

    # Create a module from the metadata
    module = Module.from_json(extracted_data)
    module.checksum = checksum

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    return {'success_flag': True, 'summary': '', 'details': {}}
コード例 #7
0
ファイル: upload.py プロジェクト: jlsherrill/pulp
def handle_uploaded_unit(type_id, unit_key, metadata, file_path, conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module out of the uploaded metadata
    combined = copy.copy(unit_key)
    combined.update(metadata)
    module = Module.from_dict(combined)

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    
コード例 #8
0
ファイル: directory.py プロジェクト: christoe/pulp_puppet
    def _import_modules(self, inventory, module_paths):
        """
        Import the puppet modules (tarballs) at the specified paths.

        :param inventory: A module inventory object.
        :type inventory: Inventory
        :param module_paths: A list of paths to puppet module files.
        :type module_paths: list
        :return: A list of the imported module unit keys.
        :rtype: list
        """
        imported_modules = []
        for module_path in module_paths:
            if self.canceled:
                return []
            puppet_manifest = self._extract_metadata(module_path)
            module = Module.from_dict(puppet_manifest)
            if inventory.already_associated(module):
                continue
            _LOG.info(IMPORT_MODULE % dict(mod=module_path))
            imported_modules.append(module.unit_key())
            self._add_module(module_path, module)
        return imported_modules