Ejemplo n.º 1
0
Archivo: bind.py Proyecto: nbetm/pulp
    def _validate_consumer_repo(consumer_id, repo_id, distributor_id):
        """
        Validate that the given consumer, repository, and distributor are present.
        Rather than raising an exception, this method returns a dictionary of missing
        values and allows the caller to decide what exception to raise.

        :param consumer_id:     The consumer id to validate
        :type  consumer_id:     str
        :param repo_id:         The repository id to validate
        :type  repo_id:         str
        :param distributor_id:  The distributor_id to validate
        :type  distributor_id:  str

        :return: A dictionary containing the missing values, or an empty dict if everything is valid
        :rtype:  dict
        """
        missing_values = {}

        try:
            factory.consumer_manager().get_consumer(consumer_id)
        except MissingResource:
            missing_values['consumer_id'] = consumer_id
        try:
            model.Repository.objects.get_repo_or_missing_resource(repo_id)
        except MissingResource:
            missing_values['repo_id'] = repo_id
        try:
            factory.repo_distributor_manager().get_distributor(repo_id, distributor_id)
        except MissingResource:
            missing_values['distributor_id'] = distributor_id

        return missing_values
Ejemplo n.º 2
0
    def get(self, request, consumer_id):
        """
        List schedules <action>.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: The consumer ID.
        :type consumer_id: str

        :raises MissingResource: if consumer does not exist

        :return: Response containing consumer's schedules <action>
        :rtype: django.http.HttpResponse
        """

        try:
            factory.consumer_manager().get_consumer(consumer_id)
        except MissingResource:
            raise MissingResource(consumer_id=consumer_id)
        schedules = self.manager.get(consumer_id, self.ACTION)

        schedule_objs = []
        for schedule in schedules:
            obj = scheduled_unit_management_obj(schedule.for_display())
            add_link_schedule(obj, self.ACTION, consumer_id)
            schedule_objs.append(obj)

        return generate_json_response_with_pulp_encoder(schedule_objs)
Ejemplo n.º 3
0
    def GET(self, consumer_id, repo_id=None):
        """
        Fetch all bind objects referencing the specified consumer_id. Optionally,
        specify a repo_id to fetch all bind objects for the consumer_id to the repo_id

        :param consumer_id: The specified consumer.
        :type  consumer_id: str
        :param repo_id:     The repository to retrieve bindings for (optional)
        :type  repo_id:     str

        :return: A list of dictionaries that represent pulp.server.db.model.consumer.Bind objects
        :rtype:  list
        """
        # Check to make sure the resources exist
        missing_resources = {}
        if repo_id is not None:
            repo = managers.repo_query_manager().find_by_id(repo_id)
            if repo is None:
                missing_resources['repo_id'] = repo_id
        # If get_consumer raises MissingResource we might miss reporting a bad repo_id
        try:
            managers.consumer_manager().get_consumer(consumer_id)
        except MissingResource:
            missing_resources['consumer_id'] = consumer_id

        if len(missing_resources) > 0:
            raise MissingResource(**missing_resources)

        manager = managers.consumer_bind_manager()
        bindings = manager.find_by_consumer(consumer_id, repo_id)
        bindings = [serialization.binding.serialize(b) for b in bindings]
        return self.ok(bindings)
Ejemplo n.º 4
0
    def _validate_consumer_repo(consumer_id, repo_id, distributor_id):
        """
        Validate that the given consumer, repository, and distributor are present.
        Rather than raising an exception, this method returns a dictionary of missing
        values and allows the caller to decide what exception to raise.

        :param consumer_id:     The consumer id to validate
        :type  consumer_id:     str
        :param repo_id:         The repository id to validate
        :type  repo_id:         str
        :param distributor_id:  The distributor_id to validate
        :type  distributor_id:  str

        :return: A dictionary containing the missing values, or an empty dict if everything is valid
        :rtype:  dict
        """
        missing_values = {}

        try:
            factory.consumer_manager().get_consumer(consumer_id)
        except MissingResource:
            missing_values['consumer_id'] = consumer_id
        try:
            model.Repository.objects.get_repo_or_missing_resource(repo_id)
        except MissingResource:
            missing_values['repo_id'] = repo_id
        try:
            factory.repo_distributor_manager().get_distributor(repo_id, distributor_id)
        except MissingResource:
            missing_values['distributor_id'] = distributor_id

        return missing_values
Ejemplo n.º 5
0
    def get(self, request, consumer_id):
        """
        List schedules <action>.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: The consumer ID.
        :type consumer_id: str

        :raises MissingResource: if consumer does not exist

        :return: Response containing consumer's schedules <action>
        :rtype: django.http.HttpResponse
        """

        try:
            factory.consumer_manager().get_consumer(consumer_id)
        except MissingResource:
            raise MissingResource(consumer_id=consumer_id)
        schedules = self.manager.get(consumer_id, self.ACTION)

        schedule_objs = []
        for schedule in schedules:
            obj = scheduled_unit_management_obj(schedule.for_display())
            add_link_schedule(obj, self.ACTION, consumer_id)
            schedule_objs.append(obj)

        return generate_json_response_with_pulp_encoder(schedule_objs)
Ejemplo n.º 6
0
    def POST(self):
        body = self.params()
        id = body.get('id')
        display_name = body.get('display_name')
        description = body.get('description')
        notes = body.get('notes')

        manager = managers.consumer_manager()
        args = [id, display_name, description, notes]
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [
            resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id),
            action_tag('create')
        ]

        call_request = CallRequest(manager.register,
                                   args,
                                   weight=weight,
                                   tags=tags)
        call_request.creates_resource(
            dispatch_constants.RESOURCE_CONSUMER_TYPE, id)

        call_report = CallReport.from_call_request(call_request)
        call_report.serialize_result = False

        consumer = execution.execute_sync(call_request, call_report)
        consumer.update(
            {'_href': serialization.link.child_link_obj(consumer['id'])})
        return self.created(consumer['_href'], consumer)
Ejemplo n.º 7
0
    def DELETE(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_manager = managers.schedule_manager()

        tags = [
            resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                         consumer_id),
            resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                         schedule_id),
            action_tag('delete_unit_update_schedule')
        ]

        call_request = CallRequest(
            schedule_manager.delete_unit_update_schedule,
            [consumer_id, schedule_id],
            tags=tags,
            archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                    consumer_id)
        call_request.deletes_resource(
            dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)
        result = execution.execute(call_request)
        return self.ok(result)
Ejemplo n.º 8
0
    def POST(self, consumer_id):
        """
        Create a bind association between the specified
        consumer by id included in the URL path and a repo-distributor
        specified in the POST body: {repo_id:<str>, distributor_id:<str>}.
        Designed to be idempotent so only MissingResource is expected to
        be raised by manager.
        @param consumer_id: The consumer to bind.
        @type consumer_id: str
        @return: The list of call_reports
        @rtype: list
        """
        # validate consumer
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        # get other options and validate them
        body = self.params()
        repo_id = body.get('repo_id')
        distributor_id = body.get('distributor_id')
        binding_config = body.get('binding_config', None)
        options = body.get('options', {})
        notify_agent = body.get('notify_agent', True)

        managers.repo_query_manager().get_repository(repo_id)
        managers.repo_distributor_manager().get_distributor(
            repo_id, distributor_id)

        # bind
        call_requests = bind_itinerary(consumer_id, repo_id, distributor_id,
                                       notify_agent, binding_config, options)
        execution.execute_multiple(call_requests)
Ejemplo n.º 9
0
    def test_syntactic_sugar_methods(self):
        """
        Tests the syntactic sugar methods for retrieving specific managers.
        """
        # Setup
        factory.initialize()

        # Test
        self.assertTrue(isinstance(factory.authentication_manager(), AuthenticationManager))
        self.assertTrue(isinstance(factory.cert_generation_manager(), CertGenerationManager))
        self.assertTrue(isinstance(factory.certificate_manager(), CertificateManager))
        self.assertTrue(isinstance(factory.password_manager(), PasswordManager))
        self.assertTrue(isinstance(factory.permission_manager(), PermissionManager))
        self.assertTrue(isinstance(factory.permission_query_manager(), PermissionQueryManager))
        self.assertTrue(isinstance(factory.role_manager(), RoleManager))
        self.assertTrue(isinstance(factory.role_query_manager(), RoleQueryManager))
        self.assertTrue(isinstance(factory.user_manager(), UserManager))             
        self.assertTrue(isinstance(factory.user_query_manager(), UserQueryManager))
        self.assertTrue(isinstance(factory.repo_manager(), RepoManager))
        self.assertTrue(isinstance(factory.repo_unit_association_manager(), RepoUnitAssociationManager))
        self.assertTrue(isinstance(factory.repo_publish_manager(), RepoPublishManager))
        self.assertTrue(isinstance(factory.repo_query_manager(), RepoQueryManager))
        self.assertTrue(isinstance(factory.repo_sync_manager(), RepoSyncManager))
        self.assertTrue(isinstance(factory.content_manager(), ContentManager))
        self.assertTrue(isinstance(factory.content_query_manager(), ContentQueryManager))
        self.assertTrue(isinstance(factory.content_upload_manager(), ContentUploadManager))
        self.assertTrue(isinstance(factory.consumer_manager(), ConsumerManager))
        self.assertTrue(isinstance(factory.topic_publish_manager(), TopicPublishManager))
Ejemplo n.º 10
0
    def PUT(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        install_options = None
        units = schedule_data.pop('units', None)

        if 'options' in schedule_data:
            install_options = {'options': schedule_data.pop('options')}

        schedule_manager = managers.schedule_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
                action_tag('update_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.update_unit_uninstall_schedule,
                                   [consumer_id, schedule_id, units, install_options, schedule_data],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.current_link_obj())
        return self.ok(scheduled_obj)
Ejemplo n.º 11
0
    def POST(self, consumer_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        units = schedule_data.pop('units', None)
        uninstall_options = {'options': schedule_data.pop('options', {})}

        if not units:
            raise MissingValue(['units'])

        schedule_manager = managers.schedule_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                action_tag('create_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.create_unit_uninstall_schedule,
                                   [consumer_id, units, uninstall_options, schedule_data],
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(scheduled_obj['_href'], scheduled_obj)
Ejemplo n.º 12
0
    def bind(self, consumer_id, repo_id, distributor_id, options):
        """
        Request the agent to perform the specified bind. This method will be called
        after the server-side representation of the binding has been created.

        :param consumer_id: The consumer ID.
        :type consumer_id: str
        :param repo_id: A repository ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str
        :param options: The options are handler specific.
        :type options: dict
        """
        # agent request
        consumer_manager = managers.consumer_manager()
        binding_manager = managers.consumer_bind_manager()

        consumer = consumer_manager.get_consumer(consumer_id)
        binding = binding_manager.get_bind(consumer_id, repo_id, distributor_id)

        agent_bindings = self.__bindings([binding])
        agent = PulpAgent(consumer)
        agent.consumer.bind(agent_bindings, options)

        # request tracking
        action_id = factory.context().call_request_id
        consumer_manager = managers.consumer_bind_manager()
        consumer_manager.action_pending(
            consumer_id,
            repo_id,
            distributor_id,
            Bind.Action.BIND,
            action_id)
Ejemplo n.º 13
0
    def update(consumer_id, content_type, profile):
        """
        Update a unit profile.
        Created if not already exists.

        :param consumer_id:  uniquely identifies the consumer.
        :type  consumer_id:  str
        :param content_type: The profile (content) type ID.
        :type  content_type: str
        :param profile:      The unit profile
        :type  profile:      object
        """
        try:
            profiler, config = plugin_api.get_profiler_by_type(content_type)
        except plugin_exceptions.PluginNotFound:
            # Not all profile types have a type specific profiler, so let's use the baseclass
            # Profiler
            profiler, config = (Profiler(), {})
        consumer = factory.consumer_manager().get_consumer(consumer_id)
        # Allow the profiler a chance to update the profile before we save it
        profile = profiler.update_profile(consumer, content_type, profile,
                                          config)

        try:
            p = ProfileManager.get_profile(consumer_id, content_type)
            p['profile'] = profile
            # We store the profile's hash anytime the profile gets altered
            p['profile_hash'] = UnitProfile.calculate_hash(profile)
        except MissingResource:
            p = UnitProfile(consumer_id, content_type, profile)
        collection = UnitProfile.get_collection()
        collection.save(p, safe=True)
        return p
Ejemplo n.º 14
0
 def test_get_with_bindings(self):
     """
     Test consumer with bindings.
     """
     # Setup
     manager = factory.repo_manager()
     repo = manager.create_repo(self.REPO_ID)
     manager = factory.repo_distributor_manager()
     manager.add_distributor(self.REPO_ID, self.DISTRIBUTOR_TYPE_ID, {}, True, distributor_id=self.DISTRIBUTOR_ID)
     manager = factory.consumer_manager()
     manager.register(self.CONSUMER_ID)
     manager = factory.consumer_bind_manager()
     bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
     # Test
     params = {"bindings": True}
     path = "/v2/consumers/%s/" % self.CONSUMER_ID
     status, body = self.get(path, params=params)
     # Verify
     self.assertEqual(200, status)
     self.assertEqual(self.CONSUMER_ID, body["id"])
     self.assertTrue("_href" in body)
     self.assertTrue(body["_href"].endswith(path))
     self.assertTrue("bindings" in body)
     bindings = body["bindings"]
     self.assertEquals(len(bindings), 1)
     self.assertEquals(bindings[0], self.REPO_ID)
Ejemplo n.º 15
0
 def populate(self):
     consumer_manager = factory.consumer_manager()
     consumer_manager.register(self.CONSUMER_ID1)
     consumer_manager.register(self.CONSUMER_ID2)
     consumer_group_manager = factory.consumer_group_manager()
     consumer_group_manager.create_consumer_group(group_id=self.GROUP_ID, 
                                                  consumer_ids = [self.CONSUMER_ID1, self.CONSUMER_ID2])
Ejemplo n.º 16
0
 def populate(self):
     config = {"key1": "value1", "key2": None}
     manager = factory.repo_distributor_manager()
     manager.add_distributor(self.REPO_ID, "mock-distributor", config, True, distributor_id=self.DISTRIBUTOR_ID)
     manager = factory.consumer_manager()
     for consumer_id in self.ALL_CONSUMERS:
         manager.register(consumer_id)
Ejemplo n.º 17
0
    def POST(self, consumer_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        units = schedule_data.pop('units', None)
        uninstall_options = {'options': schedule_data.pop('options', {})}

        if not units:
            raise MissingValue(['units'])

        schedule_manager = managers.schedule_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                action_tag('create_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.create_unit_uninstall_schedule,
                                   [consumer_id, units, uninstall_options, schedule_data],
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(scheduled_obj['_href'], scheduled_obj)
Ejemplo n.º 18
0
    def populate(self, ssl=False):
        PluginTestBase.populate(self)
        # register downstream
        manager = managers.consumer_manager()
        manager.register(self.PULP_ID)
        manager = managers.repo_importer_manager()
        # add importer
        cfg = dict(manifest_url='http://apple.com', protocol='file')
        manager.set_importer(self.REPO_ID, CITRUS_IMPORTER, cfg)
        # add distributor
        if ssl:
            dist_conf = self.dist_conf_with_ssl()
        else:
            dist_conf = self.dist_conf()

        manager = managers.repo_distributor_manager()
        manager.add_distributor(
            self.REPO_ID,
            CITRUS_DISTRUBUTOR,
            dist_conf,
            False,
            CITRUS_DISTRUBUTOR)
        # bind
        manager = managers.consumer_bind_manager()
        manager.bind(self.PULP_ID, self.REPO_ID, CITRUS_DISTRUBUTOR)
Ejemplo n.º 19
0
    def bind(self, consumer_id, repo_id, distributor_id, options):
        """
        Request the agent to perform the specified bind. This method will be called
        after the server-side representation of the binding has been created.

        :param consumer_id: The consumer ID.
        :type consumer_id: str
        :param repo_id: A repository ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str
        :param options: The options are handler specific.
        :type options: dict
        """
        # agent request
        consumer_manager = managers.consumer_manager()
        binding_manager = managers.consumer_bind_manager()

        consumer = consumer_manager.get_consumer(consumer_id)
        binding = binding_manager.get_bind(consumer_id, repo_id,
                                           distributor_id)

        agent_bindings = self.__bindings([binding])
        agent = PulpAgent(consumer)
        agent.consumer.bind(agent_bindings, options)

        # request tracking
        action_id = factory.context().call_request_id
        consumer_manager = managers.consumer_bind_manager()
        consumer_manager.action_pending(consumer_id, repo_id, distributor_id,
                                        Bind.Action.BIND, action_id)
Ejemplo n.º 20
0
    def POST(self):
        body = self.params()
        consumer_id = body.get('id')
        display_name = body.get('display_name')
        description = body.get('description')
        notes = body.get('notes')
        rsa_pub = body.get('rsa_pub')

        manager = managers.consumer_manager()

        created, certificate = manager.register(
            consumer_id,
            display_name=display_name,
            description=description,
            notes=notes,
            rsa_pub=rsa_pub)

        link = serialization.link.child_link_obj(consumer_id)
        created.update({'_href': link})

        document = {
            'consumer': created,
            'certificate': certificate
        }

        return self.created(link['_href'], document)
Ejemplo n.º 21
0
    def POST(self):
        body = self.params()
        id = body.get('id')
        display_name = body.get('display_name')
        description = body.get('description')
        notes = body.get('notes')

        manager = managers.consumer_manager()
        args = [id, display_name, description, notes]
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id),
                action_tag('create')]

        call_request = CallRequest(manager.register,
                                   args,
                                   weight=weight,
                                   tags=tags)
        call_request.creates_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, id)

        call_report = CallReport.from_call_request(call_request)
        call_report.serialize_result = False

        consumer = execution.execute_sync(call_request, call_report)
        consumer.update({'_href': serialization.link.child_link_obj(consumer['id'])})
        return self.created(consumer['_href'], consumer)
Ejemplo n.º 22
0
 def populate(self, strategy=constants.DEFAULT_STRATEGY, ssl=False):
     PluginTestBase.populate(self)
     # register child
     manager = managers.consumer_manager()
     manager.register(self.PULP_ID, notes={constants.STRATEGY_NOTE_KEY: strategy})
     manager = managers.repo_importer_manager()
     # add importer
     importer_conf = {
         constants.MANIFEST_URL_KEYWORD: 'http://redhat.com',
         constants.STRATEGY_KEYWORD: constants.DEFAULT_STRATEGY,
         constants.PROTOCOL_KEYWORD: 'file',
     }
     manager.set_importer(self.REPO_ID, constants.HTTP_IMPORTER, importer_conf)
     # add distributors
     if ssl:
         dist_conf = self.dist_conf_with_ssl()
     else:
         dist_conf = self.dist_conf()
     manager = managers.repo_distributor_manager()
     manager.add_distributor(
         self.REPO_ID,
         constants.HTTP_DISTRIBUTOR,
         dist_conf,
         False,
         constants.HTTP_DISTRIBUTOR)
     manager.add_distributor(self.REPO_ID, FAKE_DISTRIBUTOR, {}, False, FAKE_DISTRIBUTOR)
     # bind
     conf = {constants.STRATEGY_KEYWORD: strategy}
     manager = managers.consumer_bind_manager()
     manager.bind(self.PULP_ID, self.REPO_ID, constants.HTTP_DISTRIBUTOR, False, conf)
Ejemplo n.º 23
0
    def update(self, consumer_id, content_type, profile):
        """
        Update a unit profile.
        Created if not already exists.
        @param consumer_id: uniquely identifies the consumer.
        @type consumer_id: str
        @param content_type: The profile (content) type ID.
        @type content_type: str
        @param profile: The unit profile
        @type profile: object
        """
        try:
            profiler, config = plugin_api.get_profiler_by_type(content_type)
        except plugin_exceptions.PluginNotFound:
            # Not all profile types have a type specific profiler, so let's use the baseclass
            # Profiler
            profiler, config = (Profiler(), {})
        consumer = factory.consumer_manager().get_consumer(consumer_id)
        # Allow the profiler a chance to update the profile before we save it
        profile = profiler.update_profile(consumer, content_type, profile, config)

        try:
            p = self.get_profile(consumer_id, content_type)
            p['profile'] = profile
            # We store the profile's hash anytime the profile gets altered
            p['profile_hash'] = UnitProfile.calculate_hash(profile)
        except MissingResource:
            p = UnitProfile(consumer_id, content_type, profile)
        collection = UnitProfile.get_collection()
        collection.save(p, safe=True)
        return p
Ejemplo n.º 24
0
 def unbind(self, consumer_id, repo_id, distributor_id, options):
     """
     Request the agent to perform the specified unbind.
     @param consumer_id: The consumer ID.
     @type consumer_id: str
     @param repo_id: A repository ID.
     @type repo_id: str
     @param distributor_id: A distributor ID.
     @type distributor_id: str
     @param options: The options are handler specific.
     @type options: dict
     """
     # agent request
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     binding = dict(repo_id=repo_id, distributor_id=distributor_id)
     bindings = self.__unbindings([binding])
     agent = PulpAgent(consumer)
     agent.consumer.unbind(bindings, options)
     # request tracking
     action_id = factory.context().call_request_id
     manager = managers.consumer_bind_manager()
     manager.action_pending(
         consumer_id,
         repo_id,
         distributor_id,
         Bind.Action.UNBIND,
         action_id)
Ejemplo n.º 25
0
    def test_syntactic_sugar_methods(self):
        """
        Tests the syntactic sugar methods for retrieving specific managers.
        """
        # Setup
        factory.initialize()

        # Test
        self.assertTrue(isinstance(factory.authentication_manager(), AuthenticationManager))
        self.assertTrue(isinstance(factory.cert_generation_manager(), CertGenerationManager))
        self.assertTrue(isinstance(factory.certificate_manager(), CertificateManager))
        self.assertTrue(isinstance(factory.password_manager(), PasswordManager))
        self.assertTrue(isinstance(factory.permission_manager(), PermissionManager))
        self.assertTrue(isinstance(factory.permission_query_manager(), PermissionQueryManager))
        self.assertTrue(isinstance(factory.role_manager(), RoleManager))
        self.assertTrue(isinstance(factory.role_query_manager(), RoleQueryManager))
        self.assertTrue(isinstance(factory.user_manager(), UserManager))
        self.assertTrue(isinstance(factory.user_query_manager(), UserQueryManager))
        self.assertTrue(isinstance(factory.repo_manager(), RepoManager))
        self.assertTrue(isinstance(factory.repo_unit_association_manager(),
                                   RepoUnitAssociationManager))
        self.assertTrue(isinstance(factory.repo_publish_manager(), RepoPublishManager))
        self.assertTrue(isinstance(factory.repo_query_manager(), RepoQueryManager))
        self.assertTrue(isinstance(factory.repo_sync_manager(), RepoSyncManager))
        self.assertTrue(isinstance(factory.content_manager(), ContentManager))
        self.assertTrue(isinstance(factory.content_query_manager(), ContentQueryManager))
        self.assertTrue(isinstance(factory.content_upload_manager(), ContentUploadManager))
        self.assertTrue(isinstance(factory.consumer_manager(), ConsumerManager))
        self.assertTrue(isinstance(factory.topic_publish_manager(), TopicPublishManager))
Ejemplo n.º 26
0
 def uninstall_content(self, consumer_id, units, options):
     """
     Uninstall content units on a consumer.
     @param consumer_id: The consumer ID.
     @type consumer_id: str
     @param units: A list of content units to be uninstalled.
     @type units: list of:
         { type_id:<str>, type_id:<dict> }
     @param options: Uninstall options; based on unit type.
     @type options: dict
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     conduit = ProfilerConduit()
     collated = Units(units)
     for typeid, units in collated.items():
         pc = self.__profiled_consumer(consumer_id)
         profiler, cfg = self.__profiler(typeid)
         units = self.__invoke_plugin(
             profiler.uninstall_units,
             pc,
             units,
             options,
             cfg,
             conduit)
         collated[typeid] = units
     units = collated.join()
     agent = PulpAgent(consumer)
     agent.content.uninstall(units, options)
Ejemplo n.º 27
0
    def PUT(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        install_options = None
        units = schedule_data.pop('units', None)

        if 'options' in schedule_data:
            install_options = {'options': schedule_data.pop('options')}

        schedule_manager = managers.schedule_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
                action_tag('update_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.update_unit_uninstall_schedule,
                                   [consumer_id, schedule_id, units, install_options, schedule_data],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.current_link_obj())
        return self.ok(scheduled_obj)
Ejemplo n.º 28
0
    def GET(self, consumer_id):
        """
        Get all profiles associated with a consumer.
        @param consumer_id: The consumer ID.
        @type consumer_id: str
        @return: A list of profiles:
          profile is: {consumer_id:<str>, content_type:<str>, profile:<dict>}
        @return: list
        """
        # Check that the consumer exists and raise a MissingResource exception, in case it doesn't.
        managers.consumer_manager().get_consumer(consumer_id)

        manager = managers.consumer_profile_manager()
        profiles = manager.get_profiles(consumer_id)
        profiles = [serialization.consumer.profile(p) for p in profiles]
        return self.ok(profiles)
Ejemplo n.º 29
0
 def bind(self, consumer_id, repo_id, distributor_id):
     """
     Bind consumer to a specific distributor associated with
     a repository.  This call is idempotent.
     @param consumer_id: uniquely identifies the consumer.
     @type consumer_id: str
     @param repo_id: uniquely identifies the repository.
     @type repo_id: str
     @param distributor_id: uniquely identifies a distributor.
     @type distributor_id: str
     @return: The Bind object
     @rtype: SON
     @raise MissingResource: when given consumer does not exist.
     """
     # ensure the consumer is valid
     manager = factory.consumer_manager()
     manager.get_consumer(consumer_id)
     # ensure the repository & distributor are valid
     manager = factory.repo_distributor_manager()
     manager.get_distributor(repo_id, distributor_id)
     # perform the bind
     collection = Bind.get_collection()
     try:
         bind = Bind(consumer_id, repo_id, distributor_id)
         collection.save(bind, safe=True)
     except DuplicateKeyError:
         self.__reset_bind(consumer_id, repo_id, distributor_id)
     # fetch the inserted/updated bind
     bind = self.get_bind(consumer_id, repo_id, distributor_id)
     # update history
     details = {'repo_id':repo_id, 'distributor_id':distributor_id}
     manager = factory.consumer_history_manager()
     manager.record_event(consumer_id, 'repo_bound', details)
     return bind
Ejemplo n.º 30
0
    def POST(self, consumer_id):
        """
        Create a bind association between the specified
        consumer by id included in the URL path and a repo-distributor
        specified in the POST body: {repo_id:<str>, distributor_id:<str>}.
        Designed to be idempotent so only MissingResource is expected to
        be raised by manager.
        @param consumer_id: The consumer to bind.
        @type consumer_id: str
        @return: The list of call_reports
        @rtype: list
        """
        # validate consumer
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        # get other options and validate them
        body = self.params()
        repo_id = body.get('repo_id')
        distributor_id = body.get('distributor_id')
        binding_config = body.get('binding_config', None)
        options = body.get('options', {})
        notify_agent = body.get('notify_agent', True)

        managers.repo_query_manager().get_repository(repo_id)
        managers.repo_distributor_manager().get_distributor(repo_id, distributor_id)

        # bind
        call_requests = bind_itinerary(consumer_id, repo_id, distributor_id, notify_agent, binding_config, options)
        execution.execute_multiple(call_requests)
Ejemplo n.º 31
0
 def test_get_with_bindings(self):
     """
     Test consumer with bindings.
     """
     # Setup
     manager = factory.repo_manager()
     repo = manager.create_repo(self.REPO_ID)
     manager = factory.repo_distributor_manager()
     manager.add_distributor(
         self.REPO_ID,
         self.DISTRIBUTOR_TYPE_ID,
         {},
         True,
         distributor_id=self.DISTRIBUTOR_ID)
     manager = factory.consumer_manager()
     manager.register(self.CONSUMER_ID)
     manager = factory.consumer_bind_manager()
     bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
     # Test
     params = {'bindings':True}
     path = '/v2/consumers/%s/' % self.CONSUMER_ID
     status, body = self.get(path, params=params)
     # Verify
     self.assertEqual(200, status)
     self.assertEqual(self.CONSUMER_ID, body['id'])
     self.assertTrue('_href' in body)
     self.assertTrue(body['_href'].endswith(path))
     self.assertTrue('bindings' in body)
     bindings = body['bindings']
     self.assertEquals(len(bindings), 1)
     self.assertEquals(bindings[0]['repo_id'], self.REPO_ID)
     self.assertEquals(bindings[0]['distributor_id'], self.DISTRIBUTOR_ID)
     self.assertEquals(bindings[0]['consumer_actions'], [])
Ejemplo n.º 32
0
 def bind(self, consumer_id, repo_id, distributor_id):
     """
     Bind consumer to a specific distributor associated with
     a repository.  This call is idempotent.
     @param consumer_id: uniquely identifies the consumer.
     @type consumer_id: str
     @param repo_id: uniquely identifies the repository.
     @type repo_id: str
     @param distributor_id: uniquely identifies a distributor.
     @type distributor_id: str
     @return: The Bind object
     @rtype: SON
     @raise MissingResource: when given consumer does not exist.
     """
     manager = factory.consumer_manager()
     manager.get_consumer(consumer_id)
     manager = factory.repo_distributor_manager()
     distributor = manager.get_distributor(repo_id, distributor_id)
     bind = Bind(consumer_id, repo_id, distributor_id)
     collection = Bind.get_collection()
     try:
         collection.save(bind, safe=True)
         bind = self.get_bind(consumer_id, repo_id, distributor_id)
     except DuplicateKeyError:
         # idempotent
         pass
     manager = factory.consumer_agent_manager()
     manager.bind(consumer_id, repo_id)
     consumer_event_details = {"repo_id": repo_id, "distributor_id": distributor_id}
     factory.consumer_history_manager().record_event(consumer_id, "repo_bound", consumer_event_details)
     return bind
Ejemplo n.º 33
0
 def populate(self):
     manager = factory.consumer_manager()
     for id in self.CONSUMER_IDS:
         manager.register(id)
     manager = factory.consumer_profile_manager()
     for id in self.CONSUMER_IDS:
         manager.create(id, 'rpm', self.PROFILE)
Ejemplo n.º 34
0
 def populate(self):
     manager = factory.consumer_manager()
     for id in self.CONSUMER_IDS:
         manager.register(id)
     manager = factory.consumer_profile_manager()
     for id in self.CONSUMER_IDS:
         manager.create(id, 'rpm', self.PROFILE)
 def populate(self):
     consumer_manager = factory.consumer_manager()
     consumer_manager.register(self.CONSUMER_ID1)
     consumer_manager.register(self.CONSUMER_ID2)
     consumer_group_manager = factory.consumer_group_manager()
     consumer_group_manager.create_consumer_group(
         group_id=self.GROUP_ID,
         consumer_ids=[self.CONSUMER_ID1, self.CONSUMER_ID2])
Ejemplo n.º 36
0
 def PUT(self, id):
     body = self.params()
     delta = body.get('delta')
     manager = managers.consumer_manager()
     consumer = manager.update(id, delta)
     href = serialization.link.current_link_obj()
     consumer.update(href)
     return self.ok(consumer)
Ejemplo n.º 37
0
 def populate_consumers(self, env):
     for i in range(0, env.consumers):
         id = 'consumer_%d' % i
         manager = managers.consumer_manager()
         manager.register(id)
         manager = managers.consumer_bind_manager()
         manager.bind(id, self.REPO_ID, FakeDistributor.ID, True, None)
         self.populate_profile(id, env)
Ejemplo n.º 38
0
 def populate(self):
     manager = factory.repo_manager()
     repo = manager.create_repo(self.REPO_ID)
     manager = factory.repo_distributor_manager()
     manager.add_distributor(self.REPO_ID, self.DISTRIBUTOR_TYPE_ID, {}, True, distributor_id=self.DISTRIBUTOR_ID)
     mock_plugins.MOCK_DISTRIBUTOR.create_consumer_payload.return_value = self.PAYLOAD
     manager = factory.consumer_manager()
     manager.register(self.CONSUMER_ID)
Ejemplo n.º 39
0
 def GET(self, id):
     params = web.input()
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(id)
     consumer = expand_consumers(params, [consumer])[0]
     href = serialization.link.current_link_obj()
     consumer.update(href)
     return self.ok(consumer)
Ejemplo n.º 40
0
 def setUp(self):
     super(ScheduledUnitInstallTests, self).setUp()
     plugin_api._create_manager()
     mock_plugins.install()
     mock_agent.install()
     self.consumer_id = 'test-consumer'
     self.consumer_manager = factory.consumer_manager()
     self.consumer_manager.register(self.consumer_id)
Ejemplo n.º 41
0
 def populate(self):
     manager = managers.consumer_manager()
     for consumer_id in CONSUMER_IDS:
         manager.register(consumer_id)
     manager = managers.consumer_group_manager()
     manager.create_consumer_group(GROUP_ID)
     for consumer_id in CONSUMER_IDS:
         criteria = Criteria(filters={'id': consumer_id}, fields=['id'])
         manager.associate(GROUP_ID, criteria)
Ejemplo n.º 42
0
 def populate(self):
     manager = managers.consumer_manager()
     for consumer_id in CONSUMER_IDS:
         manager.register(consumer_id)
     manager = managers.consumer_group_manager()
     manager.create_consumer_group(GROUP_ID)
     for consumer_id in CONSUMER_IDS:
         criteria = Criteria(filters={'id': consumer_id}, fields=['id'])
         manager.associate(GROUP_ID, criteria)
Ejemplo n.º 43
0
 def DELETE(self, id):
     manager = managers.consumer_manager()
     tags = [
         resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id),
         action_tag('delete'),
     ]
     call_request = CallRequest(manager.unregister, [id], tags=tags)
     call_request.deletes_resource(
         dispatch_constants.RESOURCE_CONSUMER_TYPE, id)
     return self.ok(execution.execute(call_request))
Ejemplo n.º 44
0
 def unbind(self, id, repo_id):
     """
     Apply a unbind to the agent.
     @param repo_id: A repository ID.
     @type repo_id: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(id)
     agent = PulpAgent(consumer)
     agent.consumer.unbind(repo_id)
Ejemplo n.º 45
0
 def populate(self):
     manager = factory.repo_manager()
     manager.create_repo(self.REPO_ID)
     manager = factory.repo_distributor_manager()
     manager.add_distributor(self.REPO_ID,
                             self.DISTRIBUTOR_TYPE_ID, {},
                             True,
                             distributor_id=self.DISTRIBUTOR_ID)
     mock_plugins.MOCK_DISTRIBUTOR.create_consumer_payload.return_value = self.PAYLOAD
     manager = factory.consumer_manager()
     manager.register(self.CONSUMER_ID)
Ejemplo n.º 46
0
 def populate(self):
     config = {'key1': 'value1', 'key2': None}
     dist_controller.add_distributor(
         self.REPO_ID,
         'mock-distributor',
         config,
         True,
         distributor_id=self.DISTRIBUTOR_ID)
     manager = factory.consumer_manager()
     for consumer_id in self.ALL_CONSUMERS:
         manager.register(consumer_id)
Ejemplo n.º 47
0
    def _validate_consumer(consumer_id):
        """
        Determines if a given consumer_id is valid by checking its existence
        in the database.

        :param consumer_id: a unique ID for a consumer
        :type  consumer_id: basestring

        """
        consumer_manager = managers_factory.consumer_manager()
        consumer_manager.get_consumer(consumer_id)
Ejemplo n.º 48
0
 def test_consumer_unregister_cleanup(self):
     # Setup
     self.test_create()
     # Test
     manager = factory.consumer_manager()
     manager.unregister(self.CONSUMER_ID)
     # Verify
     collection = UnitProfile.get_collection()
     cursor = collection.find({'consumer_id': self.CONSUMER_ID})
     profiles = list(cursor)
     self.assertEquals(len(profiles), 0)
Ejemplo n.º 49
0
 def cancel_request(self, consumer_id, task_id):
     """
     Cancel an agent request associated with the specified task ID.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     :param: task_id: The task ID associated with the request.
     :type: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     agent = PulpAgent(consumer)
     agent.cancel(task_id)
Ejemplo n.º 50
0
 def populate(self):
     config = {'key1': 'value1', 'key2': None}
     manager = factory.repo_manager()
     repo = manager.create_repo(self.REPO_ID)
     manager = factory.repo_distributor_manager()
     manager.add_distributor(self.REPO_ID,
                             'mock-distributor',
                             config,
                             True,
                             distributor_id=self.DISTRIBUTOR_ID)
     manager = factory.consumer_manager()
     manager.register(self.CONSUMER_ID)
Ejemplo n.º 51
0
 def _inject_strategy(consumer_id, options):
     """
     Inject the node-level synchronization strategy.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     :param options: The update options.
     :type options: dict
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     strategy = consumer['notes'].get(constants.STRATEGY_NOTE_KEY)
     options[constants.STRATEGY_KEYWORD] = strategy
Ejemplo n.º 52
0
    def get(self, request, consumer_id):
        """
        Get all profiles associated with a consumer.

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

        :return: Response representing list of profiles
        :rtype: django.http.HttpResponse
        """

        # Check that the consumer exists and raise a MissingResource exception, in case it doesn't.
        factory.consumer_manager().get_consumer(consumer_id)

        manager = factory.consumer_profile_manager()
        profiles = manager.get_profiles(consumer_id)
        for consumer_profile in profiles:
            add_link_profile(consumer_profile)
        return generate_json_response_with_pulp_encoder(profiles)
Ejemplo n.º 53
0
Archivo: auth.py Proyecto: omps/pulp
 def get_key(consumer_id):
     """
     Get the consumer's public RSA key.
     :return: The consumer's public RSA key.
     :rtype: RSA.RSA
     """
     rsa_pub = 'rsa_pub'
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id, fields=[rsa_pub])
     pem = consumer[rsa_pub]
     bfr = BIO.MemoryBuffer(str(pem))
     return RSA.load_pub_key_bio(bfr)
Ejemplo n.º 54
0
 def unregistered(self, consumer_id):
     """
     Notification that a consumer (agent) has
     been unregistered.  This ensure that all registration
     artifacts have been cleaned up.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     agent = PulpAgent(consumer)
     agent.consumer.unregistered()
Ejemplo n.º 55
0
    def _validate_consumer(consumer_id):
        """
        Determines if a given consumer_id is valid by checking its existence
        in the database.

        :param consumer_id: a unique ID for a consumer
        :type  consumer_id: basestring

        :raises:    pulp.server.exceptions.MissingResource
        """
        consumer_manager = managers_factory.consumer_manager()
        consumer_manager.get_consumer(consumer_id)