def _bindings(bindings): """ Build the bindings needed by the agent. The returned bindings will be the payload created by the appropriate distributor. :param bindings: a list of binding object retrieved from the database :type bindings: list :return: list of binding objects to send to the agent :rtype: list """ agent_bindings = [] for binding in bindings: repo_id = binding['repo_id'] dist_qs = model.Distributor.objects.get_or_404 distributor = dist_qs( repo_id=binding['repo_id'], distributor_id=binding['distributor_id']) details = dist_controller.create_bind_payload( binding['repo_id'], binding['distributor_id'], binding['binding_config']) type_id = distributor['distributor_type_id'] agent_binding = dict(type_id=type_id, repo_id=repo_id, details=details) agent_bindings.append(agent_binding) return agent_bindings
def _bindings(bindings): """ Build the bindings needed by the agent. The returned bindings will be the payload created by the appropriate distributor. :param bindings: a list of binding object retrieved from the database :type bindings: list :return: list of binding objects to send to the agent :rtype: list """ agent_bindings = [] for binding in bindings: repo_id = binding['repo_id'] dist_qs = model.Distributor.objects.get_or_404 distributor = dist_qs(repo_id=binding['repo_id'], distributor_id=binding['distributor_id']) details = dist_controller.create_bind_payload( binding['repo_id'], binding['distributor_id'], binding['binding_config']) type_id = distributor['distributor_type_id'] agent_binding = dict(type_id=type_id, repo_id=repo_id, details=details) agent_bindings.append(agent_binding) return agent_bindings
def serialize(bind, include_details=True): """ Construct a REST object to be returned. Add _href and augments information used by the caller to consume published content. @param bind: A bind model/SON object. @type bind: dict/SON @return: A bind REST object. {consumer_id:<str>, repo_id:<str>, distributor_id:<str>, href:<str>, type_id:<str>, details:<dict>} @rtype: dict """ # bind serialized = dict(bind) consumer_id = bind['consumer_id'] repo_id = bind['repo_id'] distributor_id = bind['distributor_id'] # href # 1019155 - Make sure the binding URL points to: # /pulp/api/v2/consumers/<consumer_id>/bindings/<repo_id>/<distributor_id/ href_url = '%s/consumers/%s/bindings/%s/%s/' % ( http.API_V2_HREF, consumer_id, repo_id, distributor_id) href = link.link_obj(href_url) serialized.update(href) try: dist = model.Distributor.objects.get_or_404( repo_id=repo_id, distributor_id=distributor_id) except MissingResource: if include_details: raise else: serialized['type_id'] = dist.distributor_type_id if include_details: details = dist_controller.create_bind_payload(repo_id, distributor_id, bind['binding_config']) serialized['details'] = details return serialized
def test_expected(self, m_model, m_plug_api, m_plug_call_conf): """ Ensure that the appropriate call is made to the plugin to build a payload. """ repo = m_model.Repository.objects.get_repo_or_missing_resource.return_value dist = m_model.Distributor.objects.get_or_404.return_value m_dist_inst = mock.MagicMock() m_plug_config = mock.MagicMock() m_plug_api.get_distributor_by_id.return_value = (m_dist_inst, m_plug_config) result = distributor.create_bind_payload('rid', 'did', {'bind': 'conf'}) m_plug_api.get_distributor_by_id.assert_called_once_with(dist.distributor_type_id) m_plug_call_conf.assert_called_once_with(m_plug_config, dist.config) m_dist_inst.create_consumer_payload.assert_called_once_with( repo.to_transfer_repo(), m_plug_call_conf.return_value, {'bind': 'conf'}) self.assertTrue(result is m_dist_inst.create_consumer_payload.return_value)
def serialize(bind, include_details=True): """ Construct a REST object to be returned. Add _href and augments information used by the caller to consume published content. @param bind: A bind model/SON object. @type bind: dict/SON @return: A bind REST object. {consumer_id:<str>, repo_id:<str>, distributor_id:<str>, href:<str>, type_id:<str>, details:<dict>} @rtype: dict """ # bind serialized = dict(bind) consumer_id = bind['consumer_id'] repo_id = bind['repo_id'] distributor_id = bind['distributor_id'] # href # 1019155 - Make sure the binding URL points to: # /pulp/api/v2/consumers/<consumer_id>/bindings/<repo_id>/<distributor_id/ href_url = '%s/consumers/%s/bindings/%s/%s/' % ( http.API_V2_HREF, consumer_id, repo_id, distributor_id) href = link.link_obj(href_url) serialized.update(href) try: dist = model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id) except MissingResource: if include_details: raise else: serialized['type_id'] = dist.distributor_type_id if include_details: details = dist_controller.create_bind_payload(repo_id, distributor_id, bind['binding_config']) serialized['details'] = details return serialized