Ejemplo n.º 1
0
 def get_one(self, service_id):
     services_controller = self._driver.manager.services_controller
     try:
         service_obj = services_controller.get(self.project_id, service_id)
     except ValueError:
         pecan.abort(404,
                     detail='service %s could not be found' % service_id)
     # convert a service model into a response service model
     return resp_service_model.Model(service_obj, self)
Ejemplo n.º 2
0
 def get_one(self, domain_name):
     services_controller = self._driver.manager.services_controller
     try:
         service_obj = services_controller.get_service_by_domain_name(
             domain_name)
     except LookupError:
         pecan.abort(404, detail='Domain %s cannot be found' % domain_name)
     # convert a service model into a response service model
     return resp_service_model.Model(service_obj, self)
Ejemplo n.º 3
0
    def get_all(self):
        marker = pecan.request.GET.get('marker', None)
        limit = pecan.request.GET.get('limit', 10)
        try:
            limit = int(limit)
            if limit <= 0:
                pecan.abort(400, detail=u'Limit should be greater than 0')
            if limit > self.max_services_per_page:
                error = u'Limit should be less than or equal to {0}'.format(
                    self.max_services_per_page)
                pecan.abort(400, detail=error)
        except ValueError:
            error = (u'Limit should be an integer greater than 0 and less'
                     u' or equal to {0}'.format(self.max_services_per_page))
            pecan.abort(400, detail=error)

        try:
            if marker is not None:
                marker = str(uuid.UUID(marker))
        except ValueError:
            pecan.abort(400, detail="Marker must be a valid UUID")

        services_controller = self._driver.manager.services_controller
        service_resultset = services_controller.list(self.project_id, marker,
                                                     limit)
        results = [
            resp_service_model.Model(s, self) for s in service_resultset
        ]

        links = []
        if len(results) >= limit:
            links.append(
                link.Model(
                    u'{0}/services?marker={1}&limit={2}'.format(
                        self.base_url, results[-1]['id'], limit), 'next'))

        return {'links': links, 'services': results}
Ejemplo n.º 4
0
    def test_service_response_model(self, service_json):
        service_obj = model_service.Service.init_from_dict('000', service_json)

        service_model = resp_model.Model(service_obj, self.controller)
        self.assertEqual(service_json["name"], service_model['name'])