Example #1
0
    def test_get_http_code_from_sdk_return_with_already_exist(self):
        msg = {}
        msg['overallRC'] = 8
        msg['rc'] = 212
        msg['rs'] = 36

        ret = util.get_http_code_from_sdk_return(
            msg, additional_handler=util.handle_already_exists)
        self.assertEqual(409, ret)

        msg['rc'] = 100
        ret = util.get_http_code_from_sdk_return(
            msg, additional_handler=util.handle_already_exists)
        self.assertEqual(500, ret)
Example #2
0
def get_fcp_templates_details(req):
    def _get_fcp_templates_details(req, template_id_list, raw, statistics,
                                   sync_with_zvm):
        action = get_action()
        return action.get_fcp_templates_details(req, template_id_list, raw,
                                                statistics, sync_with_zvm)

    template_id_list = req.GET.get('template_id_list', None)

    raw = req.GET.get('raw', 'false')
    if raw.lower() == 'true':
        raw = True
    else:
        raw = False

    statistics = req.GET.get('statistics', 'true')
    if statistics.lower() == 'true':
        statistics = True
    else:
        statistics = False

    sync_with_zvm = req.GET.get('sync_with_zvm', 'false')
    if sync_with_zvm.lower() == 'true':
        sync_with_zvm = True
    else:
        sync_with_zvm = False
    ret = _get_fcp_templates_details(req, template_id_list, raw, statistics,
                                     sync_with_zvm)

    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
Example #3
0
def get_fcp_templates(req):
    def _get_fcp_templates(req, template_id_list, assigner_id, default_sp_list,
                           host_default):
        action = get_action()
        return action.get_fcp_templates(req, template_id_list, assigner_id,
                                        default_sp_list, host_default)

    template_id_list = req.GET.get('template_id_list', None)
    assigner_id = req.GET.get('assigner_id', None)
    default_sp_list = req.GET.get('storage_providers', None)
    host_default = req.GET.get('host_default', None)

    valid_true_values = [
        True, 'True', 'TRUE', 'true', '1', 'ON', 'On', 'on', 'YES', 'Yes',
        'yes'
    ]
    if host_default:
        if host_default in valid_true_values:
            host_default = True
        else:
            host_default = False

    ret = _get_fcp_templates(req, template_id_list, assigner_id,
                             default_sp_list, host_default)

    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
Example #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)

    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
Example #5
0
def create_fcp_template(req):
    def _create_fcp_template(req):
        action = get_action()
        body = util.extract_json(req.body)
        return action.create_fcp_template(body=body)

    ret = _create_fcp_template(req)
    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'
Example #6
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
Example #7
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'
Example #8
0
    def test_get_http_code_from_sdk_return(self):
        msg = {}
        msg['overallRC'] = 404
        ret = util.get_http_code_from_sdk_return(msg, default=201)
        self.assertEqual(404, ret)

        msg['overallRC'] = 400
        ret = util.get_http_code_from_sdk_return(msg)
        self.assertEqual(400, ret)

        msg['overallRC'] = 100
        ret = util.get_http_code_from_sdk_return(msg, default=200)
        self.assertEqual(400, ret)

        msg['overallRC'] = 0
        ret = util.get_http_code_from_sdk_return(msg, default=204)
        self.assertEqual(204, ret)

        msg['overallRC'] = 300
        ret = util.get_http_code_from_sdk_return(msg, default=201)
        self.assertEqual(500, ret)
Example #9
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
Example #10
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
Example #11
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
Example #12
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
Example #13
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
Example #14
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
Example #15
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
Example #16
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
Example #17
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
Example #18
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
Example #19
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
Example #20
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
Example #21
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
Example #22
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
Example #23
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
Example #24
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
Example #25
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
Example #26
0
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
Example #27
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
Example #28
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
Example #29
0
def get_all_fcp_usage(req):
    def _get_all_fcp_usage(req, userid):
        action = get_action()
        return action.get_all_fcp_usage(req, userid)

    if 'userid' in req.GET.keys():
        userid = req.GET['userid']
    else:
        userid = None
    ret = _get_all_fcp_usage(req, userid)

    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
Example #30
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