Ejemplo n.º 1
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = '/'.join([self.os_path, self.image_id])

        new_req = Request(env)
        res = new_req.get_response(self.app)
        if res.status_int == 200:
            image = json.loads(res.body).get('image')
            if image:
                body = {}
                body['type'] = 'IMAGE'
                body['id'] = '/'.join([self.tenant_id, self.entity_uri,
                                       self.image_id])
                match_up(body, image, 'name', 'name')
                match_up(body, image, 'created', 'created')
                match_up(body, image, 'updated', 'updated')
                body['state'] = map_image_state(image['status'])
                body['imageLocation'] = body['id']

            if self.res_content_type == 'application/xml':
                response_data = {self.entity_uri: body}
            else:
                body['resourceURI'] = '/'.join([self.uri_prefix,
                                                self.entity_uri])
                response_data = body

            new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.metadata,
                                             self.uri_prefix)
            resp = Response()
            self._fixup_cimi_header(resp)
            resp.headers['Content-Type'] = self.res_content_type
            resp.status = 200
            resp.body = new_content
            return resp
        else:
            return res

        return res
Ejemplo n.º 2
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = '/'.join([self.os_path, self.image_id])

        new_req = Request(env)
        res = new_req.get_response(self.app)
        if res.status_int == 200:
            image = json.loads(res.body).get('image')
            if image:
                body = {}
                body['type'] = 'IMAGE'
                body['id'] = '/'.join(
                    [self.tenant_id, self.entity_uri, self.image_id])
                match_up(body, image, 'name', 'name')
                match_up(body, image, 'created', 'created')
                match_up(body, image, 'updated', 'updated')
                body['state'] = map_image_state(image['status'])
                body['imageLocation'] = body['id']

            if self.res_content_type == 'application/xml':
                response_data = {self.entity_uri: body}
            else:
                body['resourceURI'] = '/'.join(
                    [self.uri_prefix, self.entity_uri])
                response_data = body

            new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.metadata, self.uri_prefix)
            resp = Response()
            self._fixup_cimi_header(resp)
            resp.headers['Content-Type'] = self.res_content_type
            resp.status = 200
            resp.body = new_content
            return resp
        else:
            return res

        return res
Ejemplo n.º 3
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = copy.copy(req.environ)

        env['SCRIPT_NAME'] = self.os_version
        env['PATH_INFO'] = self.os_path
        # we will always use json format to get Nova information
        env['HTTP_ACCEPT'] = 'application/json'

        # need to remove this header, otherwise, it will always take the
        # original request accept content type
        if env.has_key('nova.best_content_type'):
            env.pop('nova.best_content_type')
        new_req = Request(env)

        res = new_req.get_response(self.app)
        if res.status_int == 200:
            content = json.loads(res.body)
            body = {}
            body['id'] = '/'.join([self.tenant_id, self.entity_uri])
            body['machineImages'] = []
            images = content.get('images', [])
            for image in images:
                entry = {}
                entry['resourceURI'] = '/'.join([self.uri_prefix,
                                                 'MachineImage'])
                entry['id'] = '/'.join([self.tenant_id,
                                     'MachineImage',
                                     image['id']])
                entry['type'] = 'IMAGE'
                entry['name'] = image['name']
                entry['created'] = image['created']
                entry['updated'] = image['updated']
                entry['state'] = map_image_state(image['status'])
                entry['imageLocation'] = entry['id']

                body['machineImages'].append(entry)

            body['count'] = len(body['machineImages'])
            if self.res_content_type == 'application/xml':
                remove_member(body, 'resourceURI')
                body['resourceURI'] = '/'.join([self.uri_prefix,
                                                self.entity_uri])
                response_data = {'Collection': body}
            else:
                body['resourceURI'] = '/'.join([self.uri_prefix,
                                                self.entity_uri])
                response_data = body

            new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.metadata,
                                             self.uri_prefix)

            resp = Response()
            self._fixup_cimi_header(resp)
            resp.headers['Content-Type'] = self.res_content_type
            resp.status = 200
            resp.body = new_content
            return resp
        else:
            return res
Ejemplo n.º 4
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = copy.copy(req.environ)

        env['SCRIPT_NAME'] = self.os_version
        env['PATH_INFO'] = self.os_path
        # we will always use json format to get Nova information
        env['HTTP_ACCEPT'] = 'application/json'

        # need to remove this header, otherwise, it will always take the
        # original request accept content type
        if env.has_key('nova.best_content_type'):
            env.pop('nova.best_content_type')
        new_req = Request(env)

        res = new_req.get_response(self.app)
        if res.status_int == 200:
            content = json.loads(res.body)
            body = {}
            body['id'] = '/'.join([self.tenant_id, self.entity_uri])
            body['machineImages'] = []
            images = content.get('images', [])
            for image in images:
                entry = {}
                entry['resourceURI'] = '/'.join(
                    [self.uri_prefix, 'MachineImage'])
                entry['id'] = '/'.join(
                    [self.tenant_id, 'MachineImage', image['id']])
                entry['type'] = 'IMAGE'
                entry['name'] = image['name']
                entry['created'] = image['created']
                entry['updated'] = image['updated']
                entry['state'] = map_image_state(image['status'])
                entry['imageLocation'] = entry['id']

                body['machineImages'].append(entry)

            body['count'] = len(body['machineImages'])
            if self.res_content_type == 'application/xml':
                remove_member(body, 'resourceURI')
                body['resourceURI'] = '/'.join(
                    [self.uri_prefix, self.entity_uri])
                response_data = {'Collection': body}
            else:
                body['resourceURI'] = '/'.join(
                    [self.uri_prefix, self.entity_uri])
                response_data = body

            new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.metadata, self.uri_prefix)

            resp = Response()
            self._fixup_cimi_header(resp)
            resp.headers['Content-Type'] = self.res_content_type
            resp.status = 200
            resp.body = new_content
            return resp
        else:
            return res