Exemple #1
0
 def run_synchronization(self, progress, cancelled, options):
     """
     Run a repo_sync() on this child repository.
     :param progress: A progress report.
     :type progress: pulp_node.progress.RepositoryProgress
     :param options: node synchronization options.
     :type options: dict
     :return: The task result.
     """
     poller = TaskPoller(self.binding)
     max_download = options.get(
         constants.MAX_DOWNLOAD_CONCURRENCY_KEYWORD,
         constants.DEFAULT_DOWNLOAD_CONCURRENCY)
     configuration = {
         importer_constants.KEY_MAX_DOWNLOADS: max_download,
         importer_constants.KEY_MAX_SPEED: options.get(constants.MAX_DOWNLOAD_BANDWIDTH_KEYWORD)
     }
     http = self.binding.repo_actions.sync(self.repo_id, configuration)
     if http.response_code != httplib.ACCEPTED:
         raise RepoSyncRestError(self.repo_id, http.response_code)
     task = http.response_body[0]
     result = poller.join(task.task_id, progress, cancelled)
     if cancelled():
         self._cancel_synchronization(task)
     return result
Exemple #2
0
    def run_synchronization(self, progress, cancelled, options):
        """
        Run a repo_sync() on this repository.
        :param progress: A progress report.
        :type progress: pulp_node.progress.RepositoryProgress
        :param options: node synchronization options.
        :type options: dict
        :return: The task result.
        """
        warnings.warn(TASK_DEPRECATION_WARNING, NodeDeprecationWarning)

        bindings = resources.pulp_bindings()
        poller = TaskPoller(bindings)
        max_download = options.get(constants.MAX_DOWNLOAD_CONCURRENCY_KEYWORD, constants.DEFAULT_DOWNLOAD_CONCURRENCY)
        node_certificate = options[constants.PARENT_SETTINGS][constants.NODE_CERTIFICATE]
        key, certificate = Bundle.split(node_certificate)
        configuration = {
            importer_constants.KEY_MAX_DOWNLOADS: max_download,
            importer_constants.KEY_MAX_SPEED: options.get(constants.MAX_DOWNLOAD_BANDWIDTH_KEYWORD),
            importer_constants.KEY_SSL_CLIENT_KEY: key,
            importer_constants.KEY_SSL_CLIENT_CERT: certificate,
            importer_constants.KEY_SSL_VALIDATION: False,
        }
        http = bindings.repo_actions.sync(self.repo_id, configuration)
        if http.response_code != httplib.ACCEPTED:
            raise RepoSyncRestError(self.repo_id, http.response_code)
        # The repo sync is returned with a single sync task in the Call Report
        task = http.response_body.spawned_tasks[0]
        result = poller.join(task.task_id, progress, cancelled)
        if cancelled():
            self._cancel_synchronization(task)
        return result
Exemple #3
0
 def run_synchronization(self, progress, cancelled, options):
     """
     Run a repo_sync() on this repository.
     :param progress: A progress report.
     :type progress: pulp_node.progress.RepositoryProgress
     :param options: node synchronization options.
     :type options: dict
     :return: The task result.
     """
     bindings = resources.pulp_bindings()
     poller = TaskPoller(bindings)
     max_download = options.get(
         constants.MAX_DOWNLOAD_CONCURRENCY_KEYWORD,
         constants.DEFAULT_DOWNLOAD_CONCURRENCY)
     node_certificate = options[constants.PARENT_SETTINGS][constants.NODE_CERTIFICATE]
     key, certificate = Bundle.split(node_certificate)
     configuration = {
         importer_constants.KEY_MAX_DOWNLOADS: max_download,
         importer_constants.KEY_MAX_SPEED: options.get(constants.MAX_DOWNLOAD_BANDWIDTH_KEYWORD),
         importer_constants.KEY_SSL_CLIENT_KEY: key,
         importer_constants.KEY_SSL_CLIENT_CERT: certificate,
         importer_constants.KEY_SSL_VALIDATION: False,
     }
     http = bindings.repo_actions.sync(self.repo_id, configuration)
     if http.response_code != httplib.ACCEPTED:
         raise RepoSyncRestError(self.repo_id, http.response_code)
     # The repo sync is returned with a single sync task in the Call Report
     task = http.response_body.spawned_tasks[0]
     result = poller.join(task.task_id, progress, cancelled)
     if cancelled():
         self._cancel_synchronization(task)
     return result
Exemple #4
0
 def run_synchronization(self, progress, cancelled):
     """
     Run a repo_sync() on this child repository.
     :param progress: A progress report.
     :type progress: pulp_node.progress.RepositoryProgress
     :return: The task result.
     """
     poller = TaskPoller(self.binding)
     http = self.binding.repo_actions.sync(self.repo_id, {})
     if http.response_code != httplib.ACCEPTED:
         raise RepoSyncRestError(self.repo_id, http.response_code)
     task = http.response_body[0]
     result = poller.join(task.task_id, progress, cancelled)
     if cancelled():
         self._cancel_synchronization(task)
     return result
Exemple #5
0
 def run_synchronization(self, progress, cancelled):
     """
     Run a repo_sync() on this child repository.
     :param progress: A progress report.
     :type progress: pulp_node.progress.RepositoryProgress
     :return: The task result.
     """
     poller = TaskPoller(self.binding)
     http = self.binding.repo_actions.sync(self.repo_id, {})
     if http.response_code != httplib.ACCEPTED:
         raise RepoSyncRestError(self.repo_id, http.response_code)
     task = http.response_body[0]
     result = poller.join(task.task_id, progress, cancelled)
     if cancelled():
         self._cancel_synchronization(task)
     return result
Exemple #6
0
 def __init__(self, repo_id, details=None):
     """
     :param repo_id: The repository ID.
     :type repo_id: str
     :param details: The repositories details.
     :type details: dict
     """
     Repository.__init__(self, repo_id, details)
     self.poller = TaskPoller(self.binding)
Exemple #7
0
class ChildRepository(Child, Repository):
    """
    Represents a repository associated with the child inventory.
    :ivar poller: A task poller used to poll for tasks status and progress.
    :type poller: TaskPoller
    """

    @classmethod
    def fetch_all(cls):
        """
        Fetch all repositories from the child inventory.
        :return: A list of: ChildRepository
        :rtype: list
        """
        all = []
        for repo in cls.binding.repo_search.search():
            repo_id = repo['id']
            details = {
                'repository':repo,
                'distributors':[]
            }
            r = cls(repo_id, details)
            all.append(r)
        return all

    @classmethod
    def fetch(cls, repo_id):
        """
        Fetch a specific repository from the child inventory.
        :param repo_id: Repository ID.
        :type repo_id: str
        :return: The fetched repository.
        :rtype: ChildRepository
        """
        details = {}
        try:
            http = cls.binding.repo.repository(repo_id)
            details['repository'] = http.response_body
            http = cls.binding.repo_distributor.distributors(repo_id)
            details['distributors'] = http.response_body
            http = cls.binding.repo_importer.importers(repo_id)
            details['importers'] = http.response_body
            return cls(repo_id, details)
        except NotFoundException:
            return None

    @classmethod
    def purge_orphans(cls):
        """
        Purge orphaned units within the child inventory.
        """
        http = cls.binding.content_orphan.remove_all()
        if http.response_code != httplib.ACCEPTED:
            raise ModelError('purge_orphans() failed:%d', http.response_code)

    def __init__(self, repo_id, details=None):
        """
        :param repo_id: The repository ID.
        :type repo_id: str
        :param details: The repositories details.
        :type details: dict
        """
        Repository.__init__(self, repo_id, details)
        self.poller = TaskPoller(self.binding)

    def add(self):
        """
        Add the child repository and associated plugins..
        """
        # repository
        self.binding.repo.create(
            self.repo_id,
            self.basic_properties['display_name'],
            self.basic_properties['description'],
            self.basic_properties['notes'])
        # distributors
        for details in self.distributors:
            dist_id = details['id']
            dist = ChildDistributor(self.repo_id, dist_id, details)
            dist.add()
        # importers
        for details in self.importers:
            imp_id = details['id']
            importer = ChildImporter(self.repo_id, imp_id, details)
            importer.add()
        log.info('Repository: %s, added', self.repo_id)

    def update(self, delta):
        """
        Update this child repository.
        :param delta: The properties that need to be updated.
        :type delta: dict
        """
        self.binding.repo.update(self.repo_id, delta)
        log.info('Repository: %s, updated', self.repo_id)

    def delete(self):
        """
        Delete the child repository.
        """
        self.binding.repo.delete(self.repo_id)
        log.info('Repository: %s, deleted', self.repo_id)

    def merge(self, parent):
        """
        Merge parent repositories.
          1. Determine the delta and update the repository properties.
          2. Merge importers
          3. Merge distributors
        :param parent: The parent repository.
        :type parent: ParentRepository
        """
        delta = {}
        for k,v in parent.basic_properties.items():
            if self.basic_properties.get(k) != v:
                self.basic_properties[k] = v
                delta[k] = v
        if delta:
            self.update(delta)
        self.merge_importers(parent)
        self.merge_distributors(parent)

    def merge_importers(self, parent):
        """
        Merge importers.
          - Delete importers associated to this child repository but not
            associated with the parent repository.
          - Merge importers associated with this child repository AND associated
            with parent repository.
          - Add importers associated with the parent repository but NOT associated
            with this child repository.
        :param parent: The parent repository.
        :type parent: ParentRepository
        """
        self.delete_importers(parent)
        for details in parent.importers:
            imp_id = details['id']
            imp = Importer(self.repo_id, imp_id, details)
            myimp = ChildImporter.fetch(self.repo_id, imp_id)
            if myimp:
                myimp.merge(imp)
            else:
                myimp = ChildImporter(self.repo_id, imp_id, details)
                myimp.add()

    def delete_importers(self, parent):
        """
        Delete importers associated with this child repository but not
        associated with the parent repository.
        :param parent: The parent repository.
        :type parent: ParentRepository
        """
        parent_ids = [d['id'] for d in parent.importers]
        for details in self.importers:
            imp_id = details['id']
            if imp_id not in parent_ids:
                imp = ChildImporter(self.repo_id, imp_id, {})
                imp.delete()

    def merge_distributors(self, parent):
        """
        Merge distributors.
          - Delete distributors associated to this child repository but not
            associated with the parent repository.
          - Merge distributors associated with this child repository AND
            associated with parent repository.
          - Add distributors associated with the parent repository but NOT
            associated with this child repository.
        :param parent: The parent repository.
        :type parent: ParentRepository
        """
        self.delete_distributors(parent)
        for details in parent.distributors:
            dist_id = details['id']
            dist = Distributor(self.repo_id, dist_id, details)
            mydist = ChildDistributor.fetch(self.repo_id, dist_id)
            if mydist:
                mydist.merge(dist)
            else:
                mydist = ChildDistributor(self.repo_id, dist_id, details)
                mydist.add()

    def delete_distributors(self, parent):
        """
        Delete distributors associated with this child repository but not
        associated with the parent repository.
        :param parent: The parent repository.
        :type parent: ParentRepository
        """
        parent_ids = [d['id'] for d in parent.distributors]
        for details in self.distributors:
            dist_id = details['id']
            if dist_id not in parent_ids:
                dist = ChildDistributor(self.repo_id, dist_id, {})
                dist.delete()

    def run_synchronization(self, progress):
        """
        Run a repo_sync() on this child repository.
        :param progress: A progress report.
        :type progress: pulp_node.progress.RepositoryProgress
        :return: The task result.
        """
        http = self.binding.repo_actions.sync(self.repo_id, {})
        if http.response_code == httplib.ACCEPTED:
            task = http.response_body[0]
            return self.poller.join(task.task_id, progress)
        else:
            raise ModelError('synchronization failed: http=%d', http.response_code)

    def cancel_synchronization(self):
        """
        Cancel running synchronization.
        """
        self.poller.abort()