def test4(): url4 = 'http://127.0.0.1:8001/list' r4 = requests.get(url4) print r4.headers, '\n', r4.content url5 = 'http://127.0.0.1:8001/create' body = { 'image_id':'123456', 'vm_name':'vm6', 'connections':[], 'snapshot_dev':'/dev/loop8' } kwargs = {} kwargs.setdefault('headers', kwargs.get('headers', {})) kwargs['headers']['Accept'] = 'application/json' kwargs['headers']['Content-Type'] = 'application/json' kwargs['body'] = jsonutils.dumps(body) r5 = requests.request('POST', url5, kwargs) print r5.headers, '\n', r5.content url6 = 'http://127.0.0.1:8001/destroy' body = { 'vm_name': 'vm6' } kwargs = {} kwargs.setdefault('headers', kwargs.get('headers', {})) kwargs['headers']['Accept'] = 'application/json' kwargs['headers']['Content-Type'] = 'application/json' kwargs['body'] = jsonutils.dumps(body) r6 = requests.request('POST', url6, kwargs) print r6.headers, '\n', r6.content
def format(self, record): message = { 'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None } if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def format(self, record): message = {'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None} if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def create(self, req, **kwargs): #TODO:use policy.enforce #instance = self._get_body(req) LOG.debug("In computeapi create, req = ") LOG.debug(req) instance = kwargs['body'] image_id = instance['image_id'] vm_name = instance['vm_name'] connections = instance['connections'] #TODO: snapshot_dev should be a link to snapshot snapshot_connection = instance['snapshot_dev'] #try: snapshot_path = self.compute_instance.create(image_id, vm_name, connections, snapshot_connection) #except: # raise 'Failed to create %s' % vm_name #else: res_body = jsonutils.dumps(snapshot_path) LOG.debug(res_body) return snapshot_path
def list(self, req): #self._enforce(req, 'list') #TODO:use policy.enforce instances = self.compute_instance.list() res_body = jsonutils.dumps(instances) return Response(body=res_body, status=200)