Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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'
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
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
Esempio n. 10
0
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
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
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
Esempio n. 14
0
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
Esempio n. 15
0
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
Esempio n. 16
0
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
Esempio n. 17
0
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
Esempio n. 18
0
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
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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
Esempio n. 23
0
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
Esempio n. 24
0
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
Esempio n. 25
0
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
Esempio n. 26
0
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
Esempio n. 27
0
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
Esempio n. 28
0
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
Esempio n. 29
0
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
Esempio n. 30
0
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