Esempio n. 1
0
def _checkvalue(session, req, schema):
    user = session['user']

    if not 'key' in req:
        return (json.dumps({
            'success': False,
            'error-msg': 'Missing session key.'
        }))
    if not 'path' in req:
        return (json.dumps({
            'success': False,
            'error-msg': 'Missing path to validate value.'
        }))
    if not 'value' in req:
        return (json.dumps({
            'success': False,
            'error-msg': 'Missing value to validate.'
        }))

    key = req['key']
    if not key in sessions[user.username]:
        return (json.dumps({
            'success': False,
            'error-msg': 'Invalid session key.'
        }))

    ctx = sessions[user.username][key]['session'].context
    if schema:
        search = ctx.find_path(req['path'])
    else:
        search = sessions[user.username][key]['data'].find_path(req['path'])

    if search.number() != 1:
        return (json.dumps({
            'success': False,
            'error-msg': 'Invalid data path.'
        }))

    if schema:
        node = search.schema()[0]
    else:
        node = search.data()[0]

    if node.validate_value(req['value']):
        errors = yang.get_ly_errors(ctx)
        if errors.size():
            return (json.dumps({
                'success': False,
                'error-msg': errors[errors.size() - 1].errmsg()
            }))
        else:
            return (json.dumps({
                'success': False,
                'error-msg': 'unknown error'
            }))

    return (json.dumps({'success': True}))
Esempio n. 2
0
    module = ctx.load_module("turing-machine", None)
    if module is None:
        print("module not loaded")
        sys.exit()

    node = ctx.parse_data_path("/etc/sysrepo/data/turing-machine.startup",
                               ly.LYD_XML, ly.LYD_OPT_CONFIG)

    node_set = node.find_path(
        "/turing-machine:turing-machine/transition-function/delta[label='left summand']/*"
    )
    if node_set is None:
        print("could not find data for xpath")
        sys.exit()

    for data_set in node_set.data():
        schema = data_set.schema()
        print("name: " + schema.name() + " type: " + str(schema.nodetype()) +
              " path: " + data_set.path())

except Exception as e:
    print(e)
    errors = ly.get_ly_errors(ctx)
    for err in errors:
        print("err: %d" % err.err())
        print("vecode: %d" % err.vecode())
        print("errmsg: " + err.errmsg())
        print("errpath:" + err.errpath())
        print("errapptag:" + err.errapptag())
Esempio n. 3
0
ctx = None
try:
    ctx = ly.Context("/etc/sysrepo/yang")

    module = ctx.load_module("turing-machine", None)
    if module is None:
        print("module not loaded")
        sys.exit()

    node = ctx.parse_data_path("/etc/sysrepo/data/turing-machine.startup", ly.LYD_XML, ly.LYD_OPT_CONFIG)

    node_set = node.find_path("/turing-machine:turing-machine/transition-function/delta[label='left summand']/*")
    if node_set is None:
        print("could not find data for xpath")
        sys.exit()

    for data_set in node_set.data():
        schema = data_set.schema()
        print("name: " + schema.name() + " type: " + str(schema.nodetype()) + " path: " + data_set.path())

except Exception as e:
    print(e)
    errors = ly.get_ly_errors(ctx)
    for err in errors:
        print("err: %d" % err.err())
        print("vecode: %d" % err.vecode())
        print("errmsg: " + err.errmsg())
        print("errpath:" + err.errpath())
        print("errapptag:" + err.errapptag())