예제 #1
0
파일: address.py 프로젝트: osaddon/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env["PATH_INFO"] = concat(self.os_path, "/", parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get("server")

            body = {}
            body["id"] = concat(self.tenant_id, "/", self.entity_uri, "/", self.machine_id, "/", self.address_key)
            body["resourceURI"] = concat(self.uri_prefix, "/", self.entity_uri)
            body["entries"] = self._get_entry(data)

            if self.res_content_type == "application/xml":
                response_data = {"Collection": body}
            else:
                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
예제 #2
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['SERVER_PORT'] = self.conf.get('volume_endpoint_port')
        env['SCRIPT_NAME'] = '/v1'
        env['HTTP_HOST'] = '%s:%s' % \
            (self.conf.get('volume_endpoint_host'),
             self.conf.get('volume_endpoint_port'))
        env['CONTENT_LENGTH'] = 0

        status, headers, body, status_code = access_resource(env, 'GET',
            '/v1' + self.os_path, True, None, None)

        if status:
            data = json.loads(body).get('volume')

            body = {}
            body['id'] = '/'.join([self.tenant_id, 'Volume', parts[0]])
            match_up(body, data, 'name', 'display_name')
            match_up(body, data, 'description', 'display_description')
            match_up(body, data, 'created', 'created_at')
            match_up(body, data, 'capacity', 'size')
            body['capacity'] = int(body['capacity']) * 1000000
            body['state'] = map_volume_state(data['status'])
            body['bootable'] = 'false'
            body['type'] = 'http://schemas.dmtf.org/cimi/1/mapped'

            operations = []
            operations.append(self._create_op('delete',
                '/'.join([self.tenant_id, 'volume',
                          parts[0]])))
            body['operations'] = operations


            if self.res_content_type == 'application/xml':
                response_data = {'Volume': 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 = status_code
            resp.body = new_content
            return resp
        else:
            resp = Response()
            resp.status = status_code
            resp.body = 'Volume could not be found'
            return resp
예제 #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['resourceURI'] = concat(self.uri_prefix, self.entity_uri)
            body['id'] = concat(self.tenant_id,
                                '/', self.entity_uri)
            body['machineImages'] = []
            images = content.get('images',[])
            for image in images:
                entry = {}
                entry['resourceURI'] = concat(self.uri_prefix,
                                              'MachineImage')
                entry['id'] = '/'.join([self.tenant_id,
                                     'MachineImage',
                                     image['id']])

                body['machineImages'].append(entry)

            body['count'] = len(body['machineImages'])
            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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
예제 #4
0
파일: volume.py 프로젝트: zhexuan/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['SERVER_PORT'] = self.conf.get('volume_endpoint_port')
        env['SCRIPT_NAME'] = '/v1'
        env['HTTP_HOST'] = '%s:%s'%(self.conf.get('volume_endpoint_host'),
                                    self.conf.get('volume_endpoint_port'))

        status, headers, body = access_resource(env, 'GET',
                                               '/v1/' + self.os_path,
                                               True, None)
        if status:
            content = json.loads(body)
            body = {}
            body['resourceURI'] = '/'.join([self.uri_prefix.rstrip('/'),
                                            self.entity_uri])
            body['id'] = '/'.join([self.tenant_id, self.entity_uri])
            body['volumes'] = []
            volumes = content.get('volumes', [])
            for volume in volumes:
                entry = {}
                entry['resourceURI'] = '/'.join([self.uri_prefix.rstrip('/'),
                                                 'Volume'])
                entry['id'] = '/'.join([self.tenant_id, 'Volume',
                                        volume['id']])

                body['volumes'].append(entry)

            body['count'] = len(body['volumes'])
            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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:
            resp = Response()
            resp.status = 404
            return resp
예제 #5
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

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

        new_req = Request(env)
        res = new_req.get_response(self.app)
        if res.status_int == 200:
            flavor = json.loads(res.body).get('flavor')
            if flavor:
                body = {}
                body['resourceURI'] = concat(self.uri_prefix, self.entity_uri)
                body['id'] = concat(self.tenant_id,
                                '/', self.entity_uri,
                                '/', self.config_id)
                match_up(body, flavor, 'name', 'name')
                match_up(body, flavor, 'cpu', 'vcpus')
                match_up(body, flavor, 'memory', 'ram')
                body['disks'] = []
                body['disks'].append({'capacity': flavor.get('disk'),
                                      'units': 'gb'})

            if self.res_content_type == 'application/xml':
                body.pop('resourceURI')
                response_data = {self.entity_uri: body}
            else:
                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
예제 #6
0
파일: address.py 프로젝트: zhexuan/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path, '/', parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id, '/',
                                self.entity_uri, '/',
                                self.machine_id, '/',
                                self.address_key, '/',
                                self.machine_ip)
            adds = {}
            match_up(adds, data, 'addr', 'addresses/'+self.address_key)
            ips = adds.get('addr')
            if ips:
                for ip in ips:
                    if self.machine_ip == ip.get('addr'):
                        body['ip'] = self.machine_ip

            if self.res_content_type == 'application/xml':
                response_data = {'Address': body}
            else:
                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
예제 #7
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

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

        new_req = Request(env)
        res = new_req.get_response(self.app)
        if res.status_int == 200:
            flavor = json.loads(res.body).get('flavor')
            if flavor:
                body = {}
                body['resourceURI'] = '/'.join(
                    [self.uri_prefix, self.entity_uri])
                body['id'] = '/'.join(
                    [self.tenant_id, self.entity_uri, self.config_id])
                match_up(body, flavor, 'name', 'name')
                match_up(body, flavor, 'cpu', 'vcpus')
                body['memory'] = int(flavor.get('ram')) * 1000
                body['disks'] = [{
                    'capacity': int(flavor.get('disk')) * 1000,
                    'format': 'UNKNOWN'
                }]

            if self.res_content_type == 'application/xml':
                response_data = {self.entity_uri: body}
                remove_member(response_data, 'resourceURI')
            else:
                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
예제 #8
0
파일: machine.py 프로젝트: zhexuan/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        new_req = self._fresh_request(req)

        res = new_req.get_response(self.app)
        if res.status_int == 200:
            content = json.loads(res.body)
            body = {}
            body['resourceURI'] = concat(self.uri_prefix, self.entity_uri)
            body['id'] = concat(self.tenant_id,
                                '/', self.entity_uri)
            body['machines'] = []
            machines = content.get('servers',[])
            for machine in machines:
                entry = {}
                entry['resourceURI'] = concat(self.uri_prefix,
                                            'Machine')
                entry['id'] = concat(self.tenant_id, '/',
                                     'machine/',
                                     machine['id'])

                body['machines'].append(entry)

            body['count'] = len(body['machines'])
            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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
예제 #9
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
예제 #10
0
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path, '/', parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id, '/', self.entity_uri, '/',
                                self.machine_id, '/', self.address_key, '/',
                                self.machine_ip)
            adds = {}
            match_up(adds, data, 'addr', 'addresses/' + self.address_key)
            ips = adds.get('addr')
            if ips:
                for ip in ips:
                    if self.machine_ip == ip.get('addr'):
                        body['ip'] = self.machine_ip

            if self.res_content_type == 'application/xml':
                response_data = {'Address': body}
            else:
                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
예제 #11
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
예제 #12
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """
        body = {}
        body['id'] = concat(self.tenant_id, '/', self.entity_uri)
        body['name'] = self.entity_uri
        body['description'] = 'Cloud Entry Point'
        body['baseURI'] = concat(req.host_url, self.request_prefix, '/')

        body['machineConfigs'] = {
            'href':
            '/'.join([self.tenant_id, 'MachineConfigurationCollection'])
        }

        body['machines'] = {
            'href': '/'.join([self.tenant_id, 'MachineCollection'])
        }

        body['machineImages'] = {
            'href': '/'.join([self.tenant_id, 'MachineImageCollection'])
        }

        body['volumes'] = {
            'href': '/'.join([self.tenant_id, 'VolumeCollection'])
        }

        if self.res_content_type == 'application/xml':
            response_data = {'CloudEntryPoint': 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
예제 #13
0
파일: address.py 프로젝트: osaddon/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env["PATH_INFO"] = concat(self.os_path, "/", parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get("server")

            body = {}
            body["id"] = concat(
                self.tenant_id, "/", self.entity_uri, "/", self.machine_id, "/", self.address_key, "/", self.machine_ip
            )
            adds = {}
            match_up(adds, data, "addr", "addresses/" + self.address_key)
            ips = adds.get("addr")
            if ips:
                for ip in ips:
                    if self.machine_ip == ip.get("addr"):
                        body["ip"] = self.machine_ip

            if self.res_content_type == "application/xml":
                response_data = {"Address": body}
            else:
                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
예제 #14
0
파일: address.py 프로젝트: zhexuan/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path, '/', parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id, '/',
                                self.entity_uri, '/',
                                self.machine_id, '/',
                                self.address_key)
            body['resourceURI'] = concat(self.uri_prefix, self.entity_uri)
            body['entries'] = self._get_entry(data)

            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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
예제 #15
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """
        body = {}
        body['id'] = concat(self.tenant_id,
                            '/', self.entity_uri)
        body['name'] = self.entity_uri
        body['description'] = 'Cloud Entry Point'
        body['baseURI'] = concat(req.host_url, self.request_prefix, '/')

        body['machineConfigs'] = {'href':
                '/'.join([self.tenant_id, 'MachineConfigurationCollection'])}

        body['machines'] = {'href':
                '/'.join([self.tenant_id, 'MachineCollection'])}

        body['machineImages'] = {'href':
                '/'.join([self.tenant_id, 'MachineImageCollection'])}

        body['volumes'] = {'href':
                '/'.join([self.tenant_id, 'VolumeCollection'])}

        if self.res_content_type == 'application/xml':
            response_data = {'CloudEntryPoint': body}
        else:
            body['resourceURI'] = concat(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
예제 #16
0
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path, '/', parts[0])

        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id,
                                '/networkInterfacesCollection/', parts[0])
            body['resourceURI'] = concat(self.uri_prefix, '/', self.entity_uri)
            body['entries'] = self._get_entry(data, parts[0])

            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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
예제 #17
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['machineConfigurations'] = []
            flavors = content.get('flavors', [])
            for flavor in flavors:
                entry = {}
                if self.res_content_type != 'application/xml':
                    entry['resourceURI'] = '/'.join(
                        [self.uri_prefix, 'MachineConfiguration'])
                entry['id'] = '/'.join(
                    [self.tenant_id, 'MachineConfiguration', flavor['id']])
                entry['name'] = flavor['name']
                entry['cpu'] = flavor['vcpus']
                entry['memory'] = int(flavor['ram']) * 1000
                entry['disks'] = [{
                    'capacity': int(flavor['disk']) * 1000,
                    'format': 'UNKNOWN'
                }]

                body['machineConfigurations'].append(entry)

            body['count'] = len(body['machineConfigurations'])

            if self.res_content_type == 'application/xml':
                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
예제 #18
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
예제 #19
0
    def POST(self, req, *parts):
        """
        Handle POST machine request which will create a machine
        """

        try:
            request_data = get_request_data(req.body, self.req_content_type)
        except Exception as error:
            return get_err_response('MalformedBody')

        if request_data:
            data = request_data.get('body').get('VolumeCreate')
            if not data:
                data = request_data.get('body')
                if data:
                    action = data.get('resourceURI')
                    # this is to ensure that the json format contains
                    # the right indicator for volume create
                    if not action or action != '/'.join([self.uri_prefix,
                                          'VolumeCreate']):
                        data = None
            if data:
                new_body = {}
                match_up(new_body, data, 'display_name', 'name')
                match_up(new_body, data, 'display_description', 'description')
                match_up(new_body, data, 'size',
                         'volumeTemplate/volumeConfig/capacity')
                # map the properties to metadata
                match_up(new_body, data, 'metadata', 'properties')
                # check if there are some extra things
                """
                if has_extra(data, {'resourceURI': None, 'xmlns': None,
                                    'name': None, 'description': None,
                                    'properties': None,
                                    'volumeTemplate': {'volumeConfig':
                                                       {'capacity': None}}}):
                    return get_err_response('BadRequest')
                """
                self.os_path = '/%s/volumes' % (self.tenant_id)
                env = self._fresh_env(req)
                env['SERVER_PORT'] = self.conf.get('volume_endpoint_port')
                env['SCRIPT_NAME'] = '/v1'
                env['HTTP_HOST'] = '%s:%s' % \
                    (self.conf.get('volume_endpoint_host'),
                     self.conf.get('volume_endpoint_port'))
                new_body_json = json.dumps({'volume': new_body})
                env['CONTENT_LENGTH'] = len(new_body_json)

                status, headers, body, status_code = access_resource(env,
                    'POST', '/v1' + self.os_path, True, None, new_body_json)

                if status:
                    # resource created successfully, we redirect the request
                    # to query machine
                    resp_data = json.loads(body)
                    data = resp_data.get('volume')
                    resp_data = {}
                    match_up(resp_data, data, 'name', 'display_name')
                    match_up(resp_data, data, 'description',
                             'display_description')
                    match_up(resp_data, data, 'capacity', 'size')
                    match_up(resp_data, data, 'created', 'created_at')
                    resp_data['id'] = ''.join([self.tenant_id,
                                               '/volume/',
                                               data.get('id')])
                    location = resp_data['id']
                    if self.res_content_type == 'application/xml':
                        response_data = {'Volume': resp_data}
                    else:
                        resp_data['resourceURI'] = '/'.join([self.uri_prefix,
                                                            'Volume'])
                        response_data = resp_data

                    new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.volume_metadata,
                                             self.uri_prefix)
                    resp = Response()
                    self._fixup_cimi_header(resp)
                    resp.headers['Content-Type'] = self.res_content_type
                    resp.headers['Location'] = \
                        '/'.join([self.request_prefix,
                                  location])
                    resp.status = 201
                    resp.body = new_content
                    return resp
                else:
                    return get_err_response('BadRequest')
            else:
                return get_err_response('BadRequest')
        else:
            return get_err_response('BadRequest')
예제 #20
0
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        env = self._fresh_env(req)
        env['SERVER_PORT'] = self.conf.get('volume_endpoint_port')
        env['SCRIPT_NAME'] = '/v1'
        env['HTTP_HOST'] = '%s:%s' % (self.conf.get('volume_endpoint_host'),
                                    self.conf.get('volume_endpoint_port'))

        status, headers, body, status_code = access_resource(env, 'GET',
                                               '/v1/' + self.os_path,
                                               True, None)
        if status:
            content = json.loads(body)
            body = {}
            body['resourceURI'] = '/'.join([self.uri_prefix,
                                            self.entity_uri])
            body['id'] = '/'.join([self.tenant_id, self.entity_uri])
            body['volumes'] = []
            volumes = content.get('volumes', [])
            for volume in volumes:
                entry = {}
                if self.res_content_type != 'application/xml':
                    entry['resourceURI'] = '/'.join([self.uri_prefix,
                                                 'Volume'])
                entry['id'] = '/'.join([self.tenant_id, 'Volume',
                                        volume['id']])
                entry['name'] = volume['display_name']
                entry['description'] = volume['display_description']
                entry['created'] = volume['created_at']
                entry['state'] = map_volume_state(volume['status'])
                entry['capacity'] = int(volume['size']) * 1000000
                entry['bootable'] = 'false'
                entry['type'] = 'http://schemas.dmtf.org/cimi/1/mapped'

                body['volumes'].append(entry)
            
            operations = []
            operations.append(self._create_op('add',
                '/'.join([self.tenant_id, 'volumeCollection'])))
            body['operations'] = operations

            body['count'] = len(body['volumes'])
            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
            else:
                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:
            resp = Response()
            resp.status = 404
            return resp
예제 #21
0
파일: volume.py 프로젝트: zhexuan/cimi
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path,
                                  '/', '/'.join(parts))
        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id, '/machine/',
                                parts[0])
            match_up(body, data, 'name', 'name')
            match_up(body, data, 'created', 'created')
            match_up(body, data, 'updated', 'updated')
            match_up(body, data, 'state', 'status')
            body['networkInterfaces'] = {'href': concat(self.tenant_id,
                    '/networkInterfacesCollection/', parts[0])}

            # Send a request to get the details on flavor
            env = self._fresh_env(req)
            env['PATH_INFO'] = '/%s/flavors/%s' % (self.tenant_id, 
                                                   data['flavor']['id'])
            new_req = Request(env)
            res = new_req.get_response(self.app)
            if res.status_int == 200:
                flavor = json.loads(res.body).get('flavor')
                match_up(body, flavor, 'cpu', 'vcpus')
                ram = {}
                match_up(ram, flavor, 'quantity', 'ram')
                ram['units'] = 'MB'
                body['memory'] = ram
                disks = []
                disks.append({'capacity': int(flavor.get('disk')) * 1000})
                body['disks'] = disks

            # deal with machine operations
            operations = []
            name = concat(self.uri_prefix, 'action/stop')
            operations.append(self._create_op(name, parts[0]))
            name = concat(self.uri_prefix, 'action/restart')
            operations.append(self._create_op(name, parts[0]))
            body['operations'] = operations

            if self.res_content_type == 'application/xml':
                response_data = {'Machine': body}
            else:
                body['resourceURI'] = concat(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
예제 #22
0
    def POST(self, req, *parts):
        """
        Handle POST machineVolumeCollection request which will attach an volume
        """
        try:
            request_data = get_request_data(req.body, self.req_content_type)
        except Exception as error:
            return get_err_response('MalformedBody')

        if request_data:
            data = request_data.get('body').get('MachineVolume')
            if not data:
                data = request_data.get('body')
            if data:

                volume_url = data.get('volume', {}).get('href')
                if volume_url:
                    volume_id = volume_url.strip('/').split('/')[-1]
                else:
                    return get_err_response('MalformedBody')

                device = data.get('initialLocation')
                if not device:
                    return get_err_response('MalformedBody')

                reqdata = {}
                reqdata['volumeAttachment'] = {'volumeId': volume_id,
                                            'device': device}
                env = self._fresh_env(req)
                env['PATH_INFO'] = concat(self.os_path, '/', parts[0],
                                          '/os-volume_attachments')
                env['CONTENT_TYPE'] = 'application/json'
                new_req = Request(env)
                new_req.body = json.dumps(reqdata)
                res = new_req.get_response(self.app)
                if res.status_int == 200:
                    data = json.loads(res.body).get('volumeAttachment')
                    attach_id = data.get('id')
                    server_id = data.get('serverId')
                    volume_id = data.get('volumeId')

                    body = {}
                    match_up(body, data, 'initialLocation', 'device')

                    body['id'] = concat(self.tenant_id, '/machinevolume/',
                                        server_id, '/', attach_id)
                    location = '/'.join([self.request_prefix, body['id']])

                    body['volume'] = {'href': concat(self.tenant_id,
                                                    '/volume/', volume_id)}

                    # deal with volume attach operations
                    operations = []
                    operations.append(self._create_op('edit', body['id']))

                    operations.append(self._create_op('delete', body['id']))
                    body['operations'] = operations
                    body['state'] = 'ATTACHING'

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

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

            else:
                return get_err_response('BadRequest')
        else:
            return get_err_response('BadRequest')
예제 #23
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['machineConfigurations'] = []
            flavors = content.get('flavors', [])
            for flavor in flavors:
                entry = {}
                if self.res_content_type != 'application/xml':
                    entry['resourceURI'] = '/'.join([self.uri_prefix,
                        'MachineConfiguration'])
                entry['id'] = '/'.join([self.tenant_id,
                                        'MachineConfiguration',
                                        flavor['id']])
                entry['name'] = flavor['name']
                entry['cpu'] = flavor['vcpus']
                entry['memory'] = int(flavor['ram']) * 1000
                entry['disks'] = [{'capacity': int(flavor['disk']) * 1000,
                                   'format':'UNKNOWN'}]

                body['machineConfigurations'].append(entry)

            body['count'] = len(body['machineConfigurations'])

            if self.res_content_type == 'application/xml':
                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
예제 #24
0
파일: machine.py 프로젝트: chrrrles/cimi
    def GET(self, req, *parts):
        """
        Handle GET machine request
        """

        new_req = self._fresh_request(req)

        res = new_req.get_response(self.app)
        if res.status_int == 200:
            content = json.loads(res.body)
            body = {}
            body['id'] = concat(self.tenant_id,
                                '/', self.entity_uri)
            body['resourceURI'] = '/'.join([self.uri_prefix,
                                            self.entity_uri])

            env = self._fresh_env(req)
            env['PATH_INFO'] = '/%s/flavors/detail' % (self.tenant_id)
            new_req = Request(env)
            res = new_req.get_response(self.app)
            if res.status_int == 200:
                flavors = json.loads(res.body).get('flavors')
            else:
                flavors = []

            keyed_flavors = {}
            for flavor in flavors:
                keyed_flavors[flavor['id']] = flavor

            body['machines'] = []
            machines = content.get('servers', [])
            for machine in machines:
                entry = {}
                if self.res_content_type != 'application/xml':
                    entry['resourceURI'] = '/'.join([self.uri_prefix,
                                                 'Machine'])
                entry['id'] = concat(self.tenant_id, '/',
                                     'machine/',
                                     machine['id'])
                entry['name'] = machine['name']
                #entry['property'] = machine['metadata']
                entry['created'] = machine['created']
                entry['updated'] = machine['updated']
                entry['state'] = map_machine_state(machine['status'])
                flavor = keyed_flavors[machine['flavor']['id']]
                entry['cpu'] = flavor['vcpus']
                entry['memory'] = int(flavor['ram']) * 1000

                entry['volumes'] = {'href': '/'.join([self.tenant_id,
                    'MachineVolumeCollection', machine['id']])}
                entry['networkInterfaces'] = {'href': '/'.join([self.tenant_id,
                    'NetworkInterfacesCollection', machine['id']])}
                entry['disks'] = {'href': '/'.join([self.tenant_id,
                    'MachineDiskCollection', machine['id']])}

                body['machines'].append(entry)

            body['count'] = len(body['machines'])
            # deal with machine operations
            operations = []
            operations.append(self._create_op('add',
                                              '/'.join([self.tenant_id,
                                                       'machineCollection'])))
            body['operations'] = operations

            if self.res_content_type == 'application/xml':
                body['resourceURI'] = '/'.join([self.uri_prefix,
                                                'MachineCollection'])
                response_data = {'Collection': body}
            else:
                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
예제 #25
0
    def GET(self, req, *parts):
        """
        Handle GET machineVolumeCollection request
        """

        env = self._fresh_env(req)

        env['PATH_INFO'] = concat(self.os_path, '/',
                                  parts[0], '/os-volume_attachments')
        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            content = json.loads(res.body)
            body = {}
            body['id'] = concat(self.tenant_id,
                                '/', self.entity_uri, '/', parts[0])
            body['resourceURI'] = concat(self.uri_prefix, '/',
                                            self.entity_uri)

            body['machineVolumes'] = []
            volumeAttachments = content.get('volumeAttachments', [])
            for data in volumeAttachments:
                entry = {}
                if self.res_content_type == 'application/json':
                    entry['resourceURI'] = concat(self.uri_prefix,
                                            '/MachineVolume')
                entry['id'] = concat(self.tenant_id, '/',
                                     'machineVolume/',
                                     data['serverId'], '/',
                                     data['id'])
                entry['initialLocation'] = data['device']
                entry['volume'] = {'href': concat(self.tenant_id,
                    '/Volume/', data['volumeId'])}

                operations = []
                operations.append(self._create_op('edit', entry['id']))
                operations.append(self._create_op('delete', entry['id']))
                entry['operations'] = operations

                body['machineVolumes'].append(entry)

            body['count'] = len(body['machineVolumes'])
            # deal with machinevolume operations
            operations = []
            operations.append(self._create_op('add', body['id']))
            body['operations'] = operations

            if self.res_content_type == 'application/xml':
                response_data = {'Collection': body}
                remove_member(response_data, 'resourceURI')
            else:
                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
예제 #26
0
파일: machine.py 프로젝트: chrrrles/cimi
    def POST(self, req, *parts):
        """
        Handle POST machine request which will create a machine
        """

        try:
            request_data = get_request_data(req.body, self.req_content_type)
        except Exception as error:
            return get_err_response('MalformedBody')

        if request_data:
            data = request_data.get('body').get('MachineCreate')
            if not data:
                data = request_data.get('body')
            if data:
                new_body = {}
                match_up(new_body, data, 'name', 'name')

                if (data.get('machineTemplate') is None or
                    data.get('machineTemplate').get('machineImage') is None or
                    data.get('machineTemplate').get('machineConfig') is None):
                    return get_err_response('BadRequest')

                match_up(new_body, data, 'imageRef',
                         'machineTemplate/machineImage/href')

                match_up(new_body, data, 'flavorRef',
                         'machineTemplate/machineConfig/href')

                if (new_body.get('flavorRef') is None or
                    new_body.get('imageRef') is None):
                    return get_err_response('BadRequest')

                new_body['imageRef'] = new_body.get('imageRef').split('/')[-1]
                new_body['flavorRef'] = \
                    new_body.get('flavorRef').split('/')[-1]

                adminPass = data.get('credentials', {}).get('password')
                if adminPass:
                    new_body['adminPass'] = adminPass

                self.os_path = '/%s/servers' % (self.tenant_id)
                new_req = self._fresh_request(req)

                new_req.body = json.dumps({'server': new_body})
                resp = new_req.get_response(self.app)
                if resp.status_int == 201:
                    # resource created successfully, we redirect the request
                    # to query machine
                    resp_data = json.loads(resp.body)
                    id = resp_data.get('server').get('id')
                    env = self._fresh_env(req)
                    env['PATH_INFO'] = concat(self.request_prefix,
                                              '/', self.tenant_id,
                                              '/servers/', id)
                    env['REQUEST_METHOD'] = 'GET'
                    new_req = Request(env)
                    resp = new_req.get_response(self.app)
                    resp_data = {}
                    resp.headers['Location'] = \
                        '/'.join([self.request_prefix, self.tenant_id,
                                  'Machine', id])
                    resp.status = 201
                elif resp.status_int == 202:
                    resp_body_data = json.loads(resp.body).get('server')
                    id = resp_body_data.get('id')
                    resp_data = {}
                    resp_data['resourceURI'] = '/'.join([self.uri_prefix,
                                            'Machine'])
                    match_up(resp_data, data, 'name', 'name')
                    resp_data['id'] = concat(self.tenant_id, '/Machine/', id)
                    resp_data['credentials'] = {'userName': '******',
                        'password': resp_body_data.get('adminPass')}
                    if self.res_content_type == 'application/xml':
                        response_data = {'Machine': resp_data}
                        remove_member(response_data, 'resourceURI')
                    else:
                        response_data = resp_data

                    new_content = make_response_data(response_data,
                                             self.res_content_type,
                                             self.machine_metadata,
                                             self.uri_prefix)
                    resp = Response()
                    self._fixup_cimi_header(resp)
                    resp.headers['Content-Type'] = self.res_content_type
                    resp.headers['Location'] = \
                        '/'.join([self.request_prefix, self.tenant_id,
                                  'Machine', id])
                    resp.status = 202
                    resp.body = new_content
                return resp
            else:
                return get_err_response('BadRequest')
        else:
            return get_err_response('BadRequest')
예제 #27
0
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path, '/',
                                  parts[0], '/os-volume_attachments/',
                                  parts[1])
        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('volumeAttachment')

            body = {}
            body['id'] = concat(self.tenant_id, '/MachineVolume/',
                                data['serverId'], '/', data['id'])
            match_up(body, data, 'initialLocation', 'device')

            body['volume'] = {'href': concat(self.tenant_id,
                    '/Volume/', data['volumeId'])}

            # deal with machinevolume operations
            operations = []
            operations.append(self._create_op('edit', body['id']))
            operations.append(self._create_op('delete', body['id']))
            body['operations'] = operations

            # Try to get the volume state
            env = self._fresh_env(req)
            env['SERVER_PORT'] = self.conf.get('volume_endpoint_port')
            env['SCRIPT_NAME'] = '/v1'
            env['HTTP_HOST'] = '%s:%s' % \
                (self.conf.get('volume_endpoint_host'),
                 self.conf.get('volume_endpoint_port'))
            env['CONTENT_LENGTH'] = 0

            volume_path = '/'.join(['/v1', self.tenant_id, 'volumes',
                                    data['volumeId']])
            status, headers, volume_body, status_code = \
                access_resource(env, 'GET',
                                volume_path, True, None, None)

            if status:
                volume_data = json.loads(volume_body).get('volume')
                body['state'] = map_volume_state(volume_data['status'])

            if self.res_content_type == 'application/xml':
                response_data = {'MachineVolume': body}
            else:
                body['resourceURI'] = concat(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
예제 #28
0
파일: machine.py 프로젝트: chrrrles/cimi
    def GET(self, req, *parts):
        """
        Handle GET Container (List Objects) request
        """

        env = self._fresh_env(req)
        env['PATH_INFO'] = concat(self.os_path,
                                  '/', '/'.join(parts))
        new_req = Request(env)
        res = new_req.get_response(self.app)

        if res.status_int == 200:
            data = json.loads(res.body).get('server')

            body = {}
            body['id'] = concat(self.tenant_id, '/Machine/',
                                parts[0])
            match_up(body, data, 'name', 'name')
            match_up(body, data, 'created', 'created')
            match_up(body, data, 'updated', 'updated')
            body['state'] = map_machine_state(data['status'])

            body['networkInterfaces'] = {'href': '/'.join([self.tenant_id,
                'NetworkInterfacesCollection', parts[0]])}

            body['volumes'] = {'href': '/'.join([self.tenant_id,
                'MachineVolumeCollection', parts[0]])}
            body['disks'] = {'href': '/'.join([self.tenant_id,
                'MachineDiskCollection', parts[0]])}


            # Send a request to get the details on flavor
            env = self._fresh_env(req)
            env['PATH_INFO'] = '/%s/flavors/%s' % (self.tenant_id,
                                                   data['flavor']['id'])
            new_req = Request(env)
            res = new_req.get_response(self.app)
            if res.status_int == 200:
                flavor = json.loads(res.body).get('flavor')
                match_up(body, flavor, 'cpu', 'vcpus')
                body['memory'] = int(flavor.get('ram')) * 1000

            # deal with machine operations
            operations = []
            action_url = '/'.join([self.tenant_id, 'Machine', parts[0]])

            action_name = '/'.join([self.uri_prefix, 'action/start'])
            operations.append(self._create_op(action_name, action_url))

            action_name = '/'.join([self.uri_prefix, 'action/stop'])
            operations.append(self._create_op(action_name, action_url))

            action_name = '/'.join([self.uri_prefix, 'action/restart'])
            operations.append(self._create_op(action_name, action_url))

            action_name = '/'.join([self.uri_prefix, 'action/pause'])
            operations.append(self._create_op(action_name, action_url))

            action_name = '/'.join([self.uri_prefix, 'action/suspend'])
            operations.append(self._create_op(action_name, action_url))

            action_name = 'delete'
            operations.append(self._create_op(action_name, action_url))

            body['operations'] = operations

            if self.res_content_type == 'application/xml':
                response_data = {'Machine': body}
                remove_member(response_data, 'resourceURI')
            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