示例#1
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
示例#2
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
示例#3
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