示例#1
0
def delete(repo_id):
    """
    Get the itinerary for deleting a repository.
      1. Delete the repository on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :return: A TaskRequest object with the details of any errors or spawned tasks
    :rtype TaskRequest
    """
    # delete repository
    manager = managers.repo_manager()
    manager.delete_repo(repo_id)

    # append unbind itineraries foreach bound consumer
    options = {}
    manager = managers.consumer_bind_manager()

    additional_tasks = []
    errors = []
    for bind in manager.find_by_repo(repo_id):
        try:
            report = consumer.unbind(bind["consumer_id"], bind["repo_id"], bind["distributor_id"], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            errors.append(e)
示例#2
0
def distributor_delete(repo_id, distributor_id):
    """
    Get the itinerary for deleting a repository distributor.
      1. Delete the distributor on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor id
    :type distributor_id: str
    :return: Any errors that may have occurred and the list of tasks spawned for each consumer
    :rtype TaskResult
    """
    # delete distributor

    manager = managers.repo_distributor_manager()
    manager.remove_distributor(repo_id, distributor_id)

    # append unbind itineraries foreach bound consumer

    unbind_errors = []
    additional_tasks = []
    options = {}
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        try:
            report = consumer.unbind(bind["consumer_id"], bind["repo_id"], bind["distributor_id"], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            unbind_errors.append(e)
示例#3
0
文件: repository.py 项目: omps/pulp
def distributor_delete(repo_id, distributor_id):
    """
    Get the itinerary for deleting a repository distributor.
      1. Delete the distributor on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor id
    :type distributor_id: str
    :return: Any errors that may have occurred and the list of tasks spawned for each consumer
    :rtype TaskResult
    """
    # delete distributor

    manager = managers.repo_distributor_manager()
    manager.remove_distributor(repo_id, distributor_id)

    # append unbind itineraries foreach bound consumer

    unbind_errors = []
    additional_tasks = []
    options = {}
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        try:
            report = consumer.unbind(bind['consumer_id'],
                                     bind['repo_id'],
                                     bind['distributor_id'],
                                     options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            unbind_errors.append(e)
示例#4
0
文件: consumers.py 项目: ipanova/pulp
    def DELETE(self, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.  Designed to be idempotent.
        @param consumer_id: A consumer ID.
        @type consumer_id: str
        @param repo_id: A repo ID.
        @type repo_id: str
        @param distributor_id: A distributor ID.
        @type distributor_id: str
        @return: A call_report
        @rtype: TaskResult
        """
        body = self.params()
        forced = body.get('force', False)
        options = body.get('options', {})
        if forced:
            call_report = consumer.force_unbind(consumer_id, repo_id, distributor_id, options)
        else:
            call_report = consumer.unbind(consumer_id, repo_id, distributor_id, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return self.ok(call_report.serialize())
示例#5
0
文件: repository.py 项目: omps/pulp
def delete(repo_id):
    """
    Get the itinerary for deleting a repository.
      1. Delete the repository on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :return: A TaskRequest object with the details of any errors or spawned tasks
    :rtype TaskRequest
    """
    # delete repository
    manager = managers.repo_manager()
    manager.delete_repo(repo_id)

    # append unbind itineraries foreach bound consumer
    options = {}
    manager = managers.consumer_bind_manager()

    additional_tasks = []
    errors = []
    for bind in manager.find_by_repo(repo_id):
        try:
            report = consumer.unbind(bind['consumer_id'],
                                     bind['repo_id'],
                                     bind['distributor_id'],
                                     options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            errors.append(e)
示例#6
0
 def test_unbind_with_agent_notification(self, mock_bind_manager):
     binding_config = {'notify_agent': True}
     agent_options = {'bar': 'baz'}
     mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
     mock_bind_manager.consumer_agent_manager.return_value.unbind.return_value = \
         {'task_id': 'foo-request-id'}
     result = consumer.unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id',
                              agent_options)
     mock_bind_manager.consumer_agent_manager.return_value.unbind.assert_called_once_with(
         'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options)
     self.assertTrue(isinstance(result, TaskResult))
     self.assertEquals(result.spawned_tasks, [{'task_id': 'foo-request-id'}])
示例#7
0
    def test_unbind_no_agent_notification(self, mock_bind_manager):
        binding_config = {'notify_agent': False}
        agent_options = {'bar': 'baz'}
        mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
        result = consumer.unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id',
                                 agent_options)

        mock_bind_manager.consumer_bind_manager.return_value.delete.assert_called_once_with(
            'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', True)

        self.assertEquals(None, result)

        #Make sure we didn't process the agent
        self.assertFalse(mock_bind_manager.consumer_agent_manager.called)
示例#8
0
    def test_unbind_no_agent_notification(self, mock_bind_manager):
        binding_config = {'notify_agent': False}
        agent_options = {'bar': 'baz'}
        mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
        result = consumer.unbind('foo_consumer_id', 'foo_repo_id',
                                 'foo_distributor_id', agent_options)

        mock_bind_manager.consumer_bind_manager.return_value.delete.assert_called_once_with(
            'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', True)

        self.assertEqual(result.error, None)
        self.assertEqual(result.return_value, {'notify_agent': False})
        self.assertEqual(result.spawned_tasks, [])

        #Make sure we didn't process the agent
        self.assertFalse(mock_bind_manager.consumer_agent_manager.called)
示例#9
0
 def test_unbind_with_agent_notification(self, mock_bind_manager):
     binding_config = {'notify_agent': True}
     agent_options = {'bar': 'baz'}
     mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
     mock_bind_manager.consumer_agent_manager.return_value.unbind.return_value = \
         {'task_id': 'foo-request-id'}
     result = consumer.unbind('foo_consumer_id', 'foo_repo_id',
                              'foo_distributor_id', agent_options)
     mock_bind_manager.consumer_bind_manager.return_value.unbind.assert_called_once_with(
         'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id')
     mock_bind_manager.consumer_agent_manager.return_value.unbind.assert_called_once_with(
         'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id',
         agent_options)
     self.assertTrue(isinstance(result, TaskResult))
     self.assertEquals(result.spawned_tasks, [{
         'task_id': 'foo-request-id'
     }])
示例#10
0
    def DELETE(self, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.  Designed to be idempotent.
        @param consumer_id: A consumer ID.
        @type consumer_id: str
        @param repo_id: A repo ID.
        @type repo_id: str
        @param distributor_id: A distributor ID.
        @type distributor_id: str
        @return: The list of call_reports
        @rtype: list
        """
        body = self.params()
        forced = body.get('force', False)
        options = body.get('options', {})
        if forced:
            result = consumer.force_unbind(consumer_id, repo_id, distributor_id, options)
        else:
            result = consumer.unbind(consumer_id, repo_id, distributor_id, options)

        if isinstance(result, TaskResult):
            raise OperationPostponed(result)
示例#11
0
    def delete(self, request, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str
        :param repo_id: A repo ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str

        :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True
        :raises InvalidValue: if some parameters are invalid

        :return: Response representing the deleted binding(in case 'notify agent' is set to False)
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        forced = body.get('force', False)
        if not isinstance(forced, bool):
            raise InvalidValue(['force'])
        options = body.get('options', {})
        if not isinstance(options, dict):
            raise InvalidValue(['options'])
        if forced:
            call_report = consumer_task.force_unbind(consumer_id, repo_id, distributor_id, options)
        else:
            call_report = consumer_task.unbind(consumer_id, repo_id, distributor_id, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return generate_json_response_with_pulp_encoder(call_report.serialize())