Beispiel #1
0
def asset_update():
    perams = request.args if request.method == 'GET' else request.form
    sn = perams.get('sn')
    asset = assets.get_asset_by_sn(sn)
    idcs = assets.get_idc()
    for idc in idcs:
        if idc[0] == asset['idc_id']:
            selected = asset['idc_id']
    if request.method == 'GET':
        return render_template('asset/asset_update.html',
                               asset=asset,
                               idcs=idcs,
                               selected=selected)
    else:
        lists = [
            'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty', 'vendor',
            'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
        ]
        asset_dict = {}
        for i in lists:
            asset_dict['_' + i] = perams.get(i)
        _is_ok, error = assets.vilidate_update_asset(asset_dict)
        if _is_ok:
            assets.update_asset(sn, asset_dict)
            return json.dumps({'is_ok': _is_ok, 'error': u'资产更新成功'})
        else:
            return json.dumps({'is_ok': _is_ok, 'error': error})
Beispiel #2
0
def asset_create():
    perams = request.args if request.method == 'GET' else request.form
    lists = [
        'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty',
        'vendor', 'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
    ]
    asset_dict = {}
    for i in lists:
        asset_dict['_' + i] = perams.get(i)
    if request.method == 'GET':
        return render_template('asset/asset_create.html',
                               idcs=assets.get_idc())
    else:
        # 1、验证用户数据合法性;
        _is_ok, msg = assets.vilidate_create_asset(asset_dict)
        # 2、如果合法,入库;
        if _is_ok:
            # 数据入库
            _is_ok, msg = assets.create_asset(asset_dict)
        return json.dumps({'is_ok': _is_ok, 'msg': msg})
Beispiel #3
0
def asset_update():
    perams = request.args if request.method == 'GET' else request.form
    aid = perams.get('aid', '')
    if request.method == 'GET':
        return render_template('asset/asset_update.html',
                               assets=assets.update_select(aid),
                               idcs=assets.get_idc())
    if request.method == 'POST':
        lists = [
            'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty', 'vendor',
            'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os', 'id'
        ]
        asset_dict = {}
        for i in lists:
            asset_dict['__' + i] = perams.get(i)
        # 1.验证合法性
        _is_ok, msg = assets.vilidate_update_asset(asset_dict)
        # 2、如果合法,更新;
        if _is_ok:
            # 数据入库
            _is_ok, msg = assets.update_asset(asset_dict)
        return json.dumps({'is_ok': _is_ok, 'msg': msg})
Beispiel #4
0
def asset_list():
    asset_list = assets.get_list()
    idcs = dict(assets.get_idc())
    for asset in asset_list:
        asset['idc_name'] = idcs[asset['idc_id']]
    return render_template('/asset/asset_list.html', asset_list=asset_list)