示例#1
0
def guest_couple_uncouple_nic(req):

    def _guest_couple_uncouple_nic(userid, vdev, req):
        action = get_handler()
        body = util.extract_json(req.body)

        action.couple_uncouple_nic(userid, vdev, body=body)

    userid = util.wsgi_path_item(req.environ, 'userid')
    vdev = util.wsgi_path_item(req.environ, 'vdev')

    _guest_couple_uncouple_nic(userid, vdev, req)
示例#2
0
def guest_delete_nic(req):
    def _guest_delete_nic(userid, vdev, req):
        action = get_handler()
        body = util.extract_json(req.body)

        action.delete_nic(userid, vdev, body)

    userid = util.wsgi_path_item(req.environ, 'userid')
    vdev = util.wsgi_path_item(req.environ, 'vdev')

    _guest_delete_nic(userid, vdev, req)
    req.response.status = 204
    req.response.content_type = None
    return req.response
示例#3
0
def guest_action(req):

    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)

    userid = util.wsgi_path_item(req.environ, 'userid')
    info = _guest_action(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,
        additional_handler=util.handle_not_found_and_conflict)
    return req.response
示例#4
0
def guest_action(req):

    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)

    userid = util.wsgi_path_item(req.environ, 'userid')
    info = _guest_action(userid, req)

    if info is not None:
        info_json = json.dumps({'result': info})
        req.response.body = utils.to_utf8(info_json)
        req.response.content_type = 'application/json'
    else:
        req.response.content_type = None

    return req.response
示例#5
0
def guest_delete_nic(req):
    def _guest_delete_nic(userid, vdev, req):
        action = get_handler()
        body = util.extract_json(req.body)

        return action.delete_nic(userid, vdev, body)

    userid = util.wsgi_path_item(req.environ, 'userid')
    vdev = util.wsgi_path_item(req.environ, 'vdev')

    info = _guest_delete_nic(userid, vdev, 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, default=200)
    req.response.content_type = 'application/json'
    return req.response
示例#6
0
def guest_create_nic(req):

    def _guest_create_nic(userid, req):
        action = get_handler()
        body = util.extract_json(req.body)

        action.create_nic(userid, body=body)

    userid = util.wsgi_path_item(req.environ, 'userid')
    _guest_create_nic(userid, req)
示例#7
0
def image_delete(req):
    def _image_delete(name):
        action = get_action()
        action.delete(name)

    name = util.wsgi_path_item(req.environ, 'name')
    _image_delete(name)

    req.response.status = 204
    req.response.content_type = None
    return req.response
示例#8
0
def guest_delete(req):

    def _guest_delete(userid):
        action = get_handler()
        action.delete(userid)

    userid = util.wsgi_path_item(req.environ, 'userid')
    _guest_delete(userid)
    req.response.status = 204
    req.response.content_type = None
    return req.response
示例#9
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'
示例#10
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
示例#11
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
示例#12
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
示例#13
0
def handle_not_allowed(environ, start_response):
    """Return a 405 response when method is not allowed.

    If _methods are in routing_args, send an allow header listing
    the methods that are possible on the provided URL.
    """
    _methods = util.wsgi_path_item(environ, '_methods')
    headers = {}
    if _methods:
        headers['allow'] = str(_methods)
    raise webob.exc.HTTPMethodNotAllowed(
        ('The method specified is not allowed for this resource.'),
        headers=headers, json_formatter=util.json_error_formatter)
示例#14
0
文件: image.py 项目: wngzhe/feilong
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
示例#15
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
示例#16
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
示例#17
0
def vswitch_update(req):
    def _vswitch_update(name, req):
        body = util.extract_json(req.body)
        action = get_action()

        action.update(name, body=body)

    name = util.wsgi_path_item(req.environ, 'name')

    _vswitch_update(name, req)

    req.response.status = 200
    req.response.content_type = None
    return req.response
示例#18
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
示例#19
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
示例#20
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
示例#21
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
示例#22
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
示例#23
0
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
示例#24
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
示例#25
0
文件: image.py 项目: wngzhe/feilong
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
示例#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
示例#27
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
示例#28
0
def get_volume_connector(req):
    def _get_volume_conn(req, userid, reserve, fcp_template_id, sp_name):
        action = get_action()
        return action.get_volume_connector(req, userid, reserve,
                                           fcp_template_id, sp_name)

    userid = util.wsgi_path_item(req.environ, 'userid')
    body = util.extract_json(req.body)
    reserve = body['info']['reserve']
    fcp_template_id = body['info'].get('fcp_template_id', None)
    sp_name = body['info'].get('storage_provider', None)
    conn = _get_volume_conn(req, userid, reserve, fcp_template_id, sp_name)
    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
示例#29
0
def handle_405(environ, start_response):
    """Return a 405 response when method is not allowed.

    If _methods are in routing_args, send an allow header listing
    the methods that are possible on the provided URL.
    """
    _methods = util.wsgi_path_item(environ, '_methods')
    headers = {}
    if _methods:
        # Ensure allow header is a python 2 or 3 native string (thus
        # not unicode in python 2 but stay a string in python 3)
        # In the process done by Routes to save the allowed methods
        # to its routing table they become unicode in py2.
        headers['allow'] = str(_methods)
    raise webob.exc.HTTPMethodNotAllowed(
        ('The method specified is not allowed for this resource.'),
        headers=headers,
        json_formatter=util.json_error_formatter)