예제 #1
0
def registerkey():
    # Handling form submitted by POST
    if request.method == 'POST':
        key = request.form['key']
        val = request.form['val']
        if not key or not val:
            return "Missing arguments 'key' or 'val'"
        else:
            url = request.host_url + "setval?key=" + key + "&val=" + val
            consul.set_consul_val(host + prefix_key + key, val)
            userdb.insert_into_kv(con, "KV", "Setval(Form)", key, val, url)
            return "key: " + key + " val: " + val

    # form to be displayed (GET method)
    else:
        print("Base url with port", request.host_url)
        return render_template('registerkey.html', host=host)
예제 #2
0
def getval():
    key = request.args.get('key')
    if not key:
        msg = "ERROR! Missing parameter 'key' in function calls"
        print(msg)
        return msg
    key = host + prefix_key + key
    print("/getval requested on ", key)
    val0 = str(consul.get_consul_val(key, proxies))
    operation = "Getval"
    keytext = "{}".format(key)
    valtext = "{}".format(val0)
    print("\tkeytext is '{}' ".format(keytext))
    print("\tvaltext is '{}' ".format(valtext))
    userdb.insert_into_kv(con, "KV", operation, keytext, valtext, request.url)
    print("\tValue to provide to Client: ", val0)
    return val0
예제 #3
0
def decval():
    key = request.args.get('key')
    if not key:
        msg = "ERROR! Missing parameter 'key' in function calls"
        print(msg)
        return msg
    key = host + prefix_key + key
    print("/decval requested on ", key)
    val1 = consul.get_consul_val(key, proxies)
    val2 = consul.dec_string_val(val1)
    consul.set_consul_val(key, val2)
    operation = "Decval"
    keytext = "{}".format(key)
    valtext = "{} => {}".format(val1, val2)
    print("\tkeytext is '{}' ".format(keytext))
    print("\tvaltext is '{}' ".format(valtext))
    userdb.insert_into_kv(con, "KV", operation, keytext, valtext, request.url)
    print("\tinitial value was %s, new value is : %s " % (val1, val2))
    return val2
예제 #4
0
def setval():
    val = request.args.get('val')
    key = request.args.get('key')
    if not key:
        msg = "ERROR! Missing parameter 'key' in function calls"
        print(msg)
        return msg
    if not val:
        msg = "ERROR! Missing parameter 'val' in function calls"
        print(msg)
        return msg
    key = host + prefix_key + key
    print("/setval requested on '{}' with value {}".format(key, val))
    consul.set_consul_val(key, val)
    operation = "Setval"
    keytext = "{}".format(key)
    valtext = "{}".format(val)
    print("\tkeytext is '{}' ".format(keytext))
    print("\tvaltext is '{}' ".format(valtext))
    userdb.insert_into_kv(con, "KV", operation, keytext, valtext, request.url)
    return str("\t" + keytext + valtext + "\n")