def test_vswitch_update(self, mock_update, mock_name): mock_name.return_value = 'vsw1' body_str = '{"vswitch": {"grant_userid": "user1"}}' mock_update.return_value = {} self.req.body = body_str vswitch.vswitch_update(self.req) body = util.extract_json(body_str) mock_update.assert_called_once_with('vsw1', body=body)
def test_vswitch_create_with_userid_controller(self, mock_create): mock_create.return_value = {} body_str = """{"vswitch": {"name": "name1", "rdev": "1234 abcd 123F", "port_type": 1, "controller": "userid01"}}""" self.req.body = body_str vswitch.vswitch_create(self.req) body = util.extract_json(body_str) mock_create.assert_called_once_with(body=body)
def edit_fcp_template(req): def _edit_fcp_template(req_body): action = get_action() return action.edit_fcp_template(body=req_body) body = util.extract_json(req.body) body['fcp_template_id'] = util.wsgi_path_item(req.environ, 'template_id') ret = _edit_fcp_template(body) ret_json = json.dumps(ret) req.response.body = utils.to_utf8(ret_json) req.response.status = util.get_http_code_from_sdk_return(ret) req.response.content_type = 'application/json'
def volume_refresh_bootmap(req): def _volume_refresh_bootmap(req, fcpchannel, wwpn, lun, skipzipl): action = get_action() return action.volume_refresh_bootmap(fcpchannel, wwpn, lun, skipzipl) body = util.extract_json(req.body) info = _volume_refresh_bootmap(req, body['info']['fcpchannel'], body['info']['wwpn'], body['info']['lun'], body['info'].get('skipzipl', False)) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' req.response.status = util.get_http_code_from_sdk_return(info, default=200) return req.response
def guest_update(req): def _guest_update(userid, body): action = get_handler() action.update(userid, body) userid = util.wsgi_path_item(req.environ, 'userid') body = util.extract_json(req.body) _guest_update(userid, body) req.response.status = 200 req.response.content_type = None return req.response
def _guest_action(userid, req): action = get_action() body = util.extract_json(req.body) if len(body) == 0 or 'action' not in body: msg = 'action not exist or is empty' LOG.info(msg) raise webob.exc.HTTPBadRequest(explanation=msg) method = body['action'] func = getattr(action, method, None) if func: body.pop('action') return func(userid, body=body) else: msg = 'action %s is invalid' % method raise webob.exc.HTTPBadRequest(msg)
def get_volume_connector(req): def _get_volume_conn(req, userid, reserve): action = get_action() return action.get_volume_connector(req, userid, reserve) userid = util.wsgi_path_item(req.environ, 'userid') body = util.extract_json(req.body) reserve = body['info']['reserve'] conn = _get_volume_conn(req, userid, reserve) conn_json = json.dumps(conn) req.response.content_type = 'application/json' req.response.body = utils.to_utf8(conn_json) req.response.status = util.get_http_code_from_sdk_return(conn, default=200) return req.response
def volume_refresh_bootmap(req): def _volume_refresh_bootmap(req, fcpchannel, wwpn, lun, transportfiles, guest_networks): action = get_action() return action.volume_refresh_bootmap(fcpchannel, wwpn, lun, transportfiles, guest_networks) body = util.extract_json(req.body) info = _volume_refresh_bootmap(req, body['info']['fcpchannel'], body['info']['wwpn'], body['info']['lun'], body['info'].get('transportfiles', ""), body['info'].get('guest_networks', [])) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' req.response.status = util.get_http_code_from_sdk_return(info, default=200) return req.response
def file_export(request): def _export(fpath): action = get_action() return action.file_export(fpath) body = util.extract_json(request.body) fpath = body['source_file'] results = _export(fpath) # if results is dict, means error happened. if isinstance(results, dict): info_json = json.dumps(results) request.response.body = utils.to_utf8(info_json) request.response.status = util.get_http_code_from_sdk_return(results) request.response.content_type = 'application/json' return request.response # Result contains (image_iter, md5sum, image_size) else: request.response.headers['Content-Type'] = 'application/octet-stream' request.response.app_iter = results request.response.status_int = 200 return request.response
def _volume_detach(req): action = get_action() body = util.extract_json(req.body) return action.detach(body=body)
def _vswitch_update(name, req): body = util.extract_json(req.body) action = get_action() return action.update(name, body=body)
def _vswitch_create(req): action = get_action() body = util.extract_json(req.body) return action.create(body=body)
def _guest_delete_disks(userid, req): action = get_handler() body = util.extract_json(req.body) return action.delete_disks(userid, body=body)
def _guest_config_minidisks(userid, req): action = get_handler() body = util.extract_json(req.body) return action.config_minidisks(userid, body=body)
def _guest_delete_network_interface(userid, req): action = get_handler() body = util.extract_json(req.body) return action.delete_network_interface(userid, body=body)
def _guest_couple_uncouple_nic(userid, vdev, req): action = get_handler() body = util.extract_json(req.body) return action.nic_couple_uncouple(userid, vdev, body=body)
def _guest_create_nic(userid, req): action = get_handler() body = util.extract_json(req.body) return action.create_nic(userid, body=body)
def _guest_delete_nic(userid, vdev, req): action = get_handler() body = util.extract_json(req.body) return action.delete_nic(userid, vdev, body)
def _guest_create(req): action = get_handler() body = util.extract_json(req.body) return action.create(body=body)
def _image_create(req): action = get_action() body = util.extract_json(req.body) action.create(body=body)
def _image_export(name, req): action = get_action() body = util.extract_json(req.body) return action.export(name, body=body)
def _set_fcp_usage(req, fcp): action = get_action() body = util.extract_json(req.body) return action.set_fcp_usage(fcp, body=body)
def _create_fcp_template(req): action = get_action() body = util.extract_json(req.body) return action.create_fcp_template(body=body)
def _volume_attach(userid, req): action = get_action() body = util.extract_json(req.body) return action.attach(userid, body)