def guest_list(req): def _guest_list(): action = get_handler() return action.list() info = _guest_list() info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' req.response.status = 200 return req.response
def host_get_guest_list(req): def _host_get_guest_list(): action = get_action() return action.get_guest_list() info = _host_get_guest_list() 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) return req.response
def image_get_root_disk_size(req): def _image_get_root_disk_size(name): action = get_action() return action.get_root_disk_size(name) name = util.wsgi_path_item(req.environ, 'name') info = _image_get_root_disk_size(name) info_json = json.dumps({'size': info}) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def guest_get_nic_info(req): def _guest_get_nic_info(userid): action = get_handler() return action.get_nic(userid) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_get_nic_info(userid) info_json = json.dumps({'nic': info}) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def host_get_disk_info(req): def _host_get_disk_info(diskname): action = get_action() return action.get_disk_info(diskname) diskname = util.wsgi_path_item(req.environ, 'disk') info = _host_get_disk_info(diskname) info_json = json.dumps({'disk_info': info}) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
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 guest_get_vnics_info(req): userid_list = _get_userid_list(req) def _guest_get_vnics_info(req, userid_list): action = get_handler() return action.get_vnics_info(req, userid_list) info = _guest_get_vnics_info(req, userid_list) info_json = json.dumps({'vnics': info}) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def image_delete(req): def _image_delete(name): action = get_action() return action.delete(name) name = util.wsgi_path_item(req.environ, 'name') info = _image_delete(name) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return(info, default=200) req.response.content_type = 'application/json' return req.response
def get_volume_connector(req): def _get_volume_conn(req, userid): action = get_action() return action.get_volume_connector(req, userid) userid = util.wsgi_path_item(req.environ, 'userid') conn = _get_volume_conn(req, userid) 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_detach(req): def _volume_detach(req): action = get_action() body = util.extract_json(req.body) return action.detach(body=body) info = _volume_detach(req) 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_delete(req): def _guest_delete(userid): action = get_handler() return action.delete(userid) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_delete(userid) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return(info, default=200) req.response.content_type = 'application/json' return req.response
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 set_fcp_usage(req): def _set_fcp_usage(req, fcp): action = get_action() body = util.extract_json(req.body) return action.set_fcp_usage(fcp, body=body) fcp = util.wsgi_path_item(req.environ, 'fcp_id') ret = _set_fcp_usage(req, fcp) ret_json = json.dumps(ret) req.response.body = utils.to_utf8(ret_json) req.response.content_type = 'application/json' req.response.status = 200 return req.response
def volume_detach(req): def _volume_detach(userid, req): action = get_action() body = util.extract_json(req.body) return action.detach(userid, body) userid = util.wsgi_path_item(req.environ, 'userid') info = _volume_detach(userid, req) 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 host_get_volume_info(req): def _host_get_volume_info(req, volumename): action = get_action() return action.get_volume_info(req, volumename) volumename = None if 'volumename' in req.GET: volumename = req.GET['volumename'] info = _host_get_volume_info(req, volumename) 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) return req.response
def get_fcp_usage(req): def _get_fcp_usage(req, fcp): action = get_action() return action.get_fcp_usage(req, fcp) fcp = util.wsgi_path_item(req.environ, 'fcp_id') ret = _get_fcp_usage(req, fcp) ret_json = json.dumps(ret) req.response.status = util.get_http_code_from_sdk_return( ret, additional_handler=util.handle_not_found) req.response.content_type = 'application/json' req.response.body = utils.to_utf8(ret_json) return req.response
def image_query(req): def _image_query(imagename): action = get_action() return action.query(imagename) imagename = None if 'imagename' in req.GET: imagename = req.GET['imagename'] info = _image_query(imagename) info_json = json.dumps({'images': info}) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def image_create(req): def _image_create(req): action = get_action() body = util.extract_json(req.body) return action.create(body=body) info = _image_create(req) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_already_exists) req.response.content_type = 'application/json' return req.response
def guest_get_power_state(req): def _guest_get_power_state(req, userid): action = get_handler() return action.get_power_state(req, userid) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_get_power_state(req, userid) info_json = json.dumps(info) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def home(req): min_version = microversion.min_version_string() max_version = microversion.max_version_string() version_data = { 'version': '%s' % min_version, 'max_version': max_version, 'min_version': min_version, } version_json = json.dumps({'versions': [version_data]}) req.response.body = utils.to_utf8(version_json) req.response.content_type = 'application/json' return req.response
def delete_fcp_template(req): def _delete_fcp_template(template_id): action = get_action() return action.delete_fcp_template(template_id) template_id = util.wsgi_path_item(req.environ, 'template_id') info = _delete_fcp_template(template_id) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.content_type = 'application/json' return req.response
def image_export(req): def _image_export(name, req): action = get_action() body = util.extract_json(req.body) return action.export(name, body=body) name = util.wsgi_path_item(req.environ, 'name') info = _image_export(name, req) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.content_type = 'application/json' return req.response
def vswitch_query(req): def _vswitch_query(name): action = get_action() return action.query(name) name = util.wsgi_path_item(req.environ, 'name') info = _vswitch_query(name) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.content_type = 'application/json' return req.response
def host_get_disk_info(req): def _host_get_disk_info(req, poolname): action = get_action() return action.diskpool_get_info(req, poolname) poolname = None if 'poolname' in req.GET: poolname = req.GET['poolname'] info = _host_get_disk_info(req, poolname) info_json = json.dumps(info) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def guest_create_disks(req): def _guest_create_disks(userid, req): action = get_handler() body = util.extract_json(req.body) return action.create_disks(userid, body=body) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_create_disks(userid, req) info_json = json.dumps(info) req.response.status = util.get_http_code_from_sdk_return(info) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def guest_get(req): def _guest_get(userid): action = get_handler() return action.get(userid) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_get(userid) # info we got looks like: # {'user_direct': [u'USER RESTT305 PASSW0RD 1024m 1024m G', # u'INCLUDE OSDFLT']} info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def guest_get_interface_stats(req): userid_list = _get_userid_list(req) def _guest_get_interface_stats(req, userid_list): action = get_handler() return action.inspect_vnics(req, userid_list) info = _guest_get_interface_stats(req, userid_list) info_json = json.dumps(info) req.response.status = util.get_http_code_from_sdk_return(info, additional_handler=util.handle_not_found) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response
def image_query(req): def _image_query(imagename, req): action = get_action() return action.query(req, imagename) imagename = None if 'imagename' in req.GET: imagename = req.GET['imagename'] info = _image_query(imagename, req) info_json = json.dumps(info) req.response.body = utils.to_utf8(info_json) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.content_type = 'application/json' return req.response
def file_import(request): def _import(file_obj): action = get_action() return action.file_import(file_obj) # Check if the request content type is valid content_type = request.content_type info = _content_type_validation(content_type) if not info: file_obj = request.body_file info = _import(file_obj) info_json = json.dumps(info) request.response.body = utils.to_utf8(info_json) request.response.status = util.get_http_code_from_sdk_return(info) request.response.content_type = 'application/json' return request.response
def guest_get(req): def _guest_get(req, userid): action = get_handler() return action.get_definition_info(req, userid) userid = util.wsgi_path_item(req.environ, 'userid') info = _guest_get(req, userid) # info we got looks like: # {'user_direct': [u'USER RESTT305 PASSW0RD 1024m 1024m G', # u'INCLUDE OSDFLT']} info_json = json.dumps(info) req.response.status = util.get_http_code_from_sdk_return( info, additional_handler=util.handle_not_found) req.response.body = utils.to_utf8(info_json) req.response.content_type = 'application/json' return req.response