Esempio n. 1
0
std::string AdminPortalProtocol::admin_view_get_prop(const std::string& view, const std::string& name) throw (P4PProtocolError)
{
    check_txn();
    p4p::protocol::detail::ResponseSingleTokenReader reader;
    make_request("GET", "admin/" + admin_token_ + '/' + url_escape(view) + "/prop/" + url_escape(name), reader);
    return reader.get_token();
}
Esempio n. 2
0
static void
fetch_dbs(struct jsonrpc *rpc, struct svec *dbs)
{
    struct jsonrpc_msg *request, *reply;
    size_t i;

    request = jsonrpc_create_request("list_dbs", json_array_create_empty(),
                                     NULL);

    check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
    if (reply->result->type != JSON_ARRAY) {
        ovs_fatal(0, "list_dbs response is not array");
    }

    for (i = 0; i < reply->result->u.array.n; i++) {
        const struct json *name = reply->result->u.array.elems[i];

        if (name->type != JSON_STRING) {
            ovs_fatal(0, "list_dbs response %"PRIuSIZE" is not string", i);
        }
        svec_add(dbs, name->u.string);
    }
    jsonrpc_msg_destroy(reply);
    svec_sort(dbs);
}
Esempio n. 3
0
static int txn_op_getId(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    lua_Number id = tx->id(tx);
    lua_pushnumber(L, id);
    return 1;
}
Esempio n. 4
0
DB_TXN *luabdb_totxn(lua_State *L, int narg)
{
    DB_TXN** ptx = check_txn(L, narg);
    if (ptx != NULL)
    {
        return *ptx;
    }
    return NULL;
}
Esempio n. 5
0
static int tester__gc(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    if (tx != NULL)
    {
        dbgprint("aborting a transaction 0x%x\n", tx);
        int status = tx->abort(tx);
        *ptx = NULL;
        handle_dbexception(L, status);
    }
    return 0;
}
Esempio n. 6
0
double AdminPortalProtocol::admin_view_get_pidlink_weight(const std::string& view, const std::string& link) throw (P4PProtocolError)
{
    check_txn();
    p4p::protocol::detail::ResponseSingleTokenReader reader;
    make_request("GET", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(link) + "/weight", reader);
    try
    {
        return p4p::protocol::detail::to_double(reader.get_token());
    }
    catch (std::invalid_argument& e)
    {
        throw P4PProtocolParseError(e.what());
    }
}
Esempio n. 7
0
static int txn_op_setName(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    u_int32_t flags = 0;
    int status;
    const char* name = lua_tostring(L, 2);
    if (tx != NULL)
    {
        status = tx->set_name(tx, name);
        handle_dbexception(L, status);
    }
    return 0;
}
Esempio n. 8
0
static int txn_op_abort(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    int status;
    if (tx != NULL)
    {
        dbgprint("aborting tran 0x%x\n", tx);
        status = tx->abort(tx);
        handle_dbexception(L, status);
        *ptx = NULL;
    }
    return 0;
}
Esempio n. 9
0
static struct ovsdb_schema *
fetch_schema(struct jsonrpc *rpc, const char *database)
{
    struct jsonrpc_msg *request, *reply;
    struct ovsdb_schema *schema;

    request = jsonrpc_create_request("get_schema",
                                     json_array_create_1(
                                         json_string_create(database)),
                                     NULL);
    check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
    check_ovsdb_error(ovsdb_schema_from_json(reply->result, &schema));
    jsonrpc_msg_destroy(reply);

    return schema;
}
Esempio n. 10
0
static int txn_op_getName(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    u_int32_t flags = 0;
    int status;
    const char* name;
    if (tx != NULL)
    {
        status = tx->get_name(tx, &name);
        handle_dbexception(L, status);
        lua_pushstring(L, name);
        return 1;
    }
    return 0;
}
Esempio n. 11
0
void AdminPortalProtocol::admin_view_set_pidlink_pdistance(const std::string& view, const std::string& link, const PDistanceBase& value) throw (P4PProtocolError)
{
    check_txn();
    std::string value_str;
    switch (value.get_type())
    {
    case PDT_STATIC:
        value_str = value.get_value();
        break;
    case PDT_DYNAMIC:
        value_str = "dynamic";
        break;
    default:
        throw P4PProtocolError("Invalid PDistance type");
    }

    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(link) + "/pdistance?v=" + value_str);
}
Esempio n. 12
0
static int txn_op_commit(lua_State *L)
{
    DB_TXN** ptx = check_txn(L, 1);
    DB_TXN* tx = *ptx;
    u_int32_t flags = 0;
    int status;
    if (lua_gettop(L) > 1)
    {
        flags = luabdb_getflags(L, 2);
    }
    if (tx != NULL)
    {
        dbgprint("commit tran 0x%x\n", tx);
        status = tx->commit(tx, flags);
        handle_dbexception(L, status);
        *ptx = NULL;
    }
    return 0;
}
Esempio n. 13
0
PDistanceBase* AdminPortalProtocol::admin_view_get_pidlink_pdistance(const std::string& view, const std::string& link) throw (P4PProtocolError)
{
    check_txn();
    p4p::protocol::detail::ResponseSingleTokenReader reader;
    make_request("GET", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(link) + "/pdistance", reader);
    if (strcasecmp(reader.get_token().c_str(), "dynamic") == 0)
    {
        return new PDistanceDynamic();
    }
    else
    {
        try
        {
            return new PDistanceStatic(p4p::protocol::detail::to_double(reader.get_token()));
        }
        catch (std::invalid_argument& e)
        {
            throw P4PProtocolParseError(e.what());
        }
    }
}
Esempio n. 14
0
void AdminPortalProtocol::admin_view_del_pid_node(const std::string& view, const std::string& pid, const std::string& node) throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_ + '/' + url_escape(view) + "/pid/" + url_escape(pid) + "/nodes/" + url_escape(node));
}
Esempio n. 15
0
void AdminPortalProtocol::admin_view_set_pidlink_weight(const std::string& view, const std::string& link, double value) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(link) + "/weight?v=" + p4p::detail::p4p_token_cast<std::string>(value));
}
Esempio n. 16
0
void AdminPortalProtocol::admin_net_del_link(const std::string& name) throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_ + "/net/link/" + url_escape(name));
}
Esempio n. 17
0
void AdminPortalProtocol::admin_net_add_link(const NamedNetLink& link) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + "/net/link/" + url_escape(link.name) + "?src=" + url_escape(link.link.src) + "&dst=" + url_escape(link.link.dst));
}
Esempio n. 18
0
void AdminPortalProtocol::admin_net_add_node(const std::string& name, bool external) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + "/net/node/" + url_escape(name) + (external ? "?ext=1" : ""));
}
Esempio n. 19
0
void AdminPortalProtocol::admin_view_del_pidlink(const std::string& view, const std::string& name) throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(name));
}
Esempio n. 20
0
void AdminPortalProtocol::admin_view_add_pid(const std::string& view, const NamedPID& pid) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(view) + "/pid/" + url_escape(pid.name) + "?v=" + p4p::detail::p4p_token_cast<std::string>(pid.pid));
}
Esempio n. 21
0
void AdminPortalProtocol::admin_view_clear_pid_prefixes(const std::string& view, const std::string& name) throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_ + '/' + url_escape(view) + "/pid/" + url_escape(name) + "/prefixes");
}
Esempio n. 22
0
void AdminPortalProtocol::admin_view_del_pid_prefix(const std::string& view, const std::string& name, const std::string& address, unsigned short len) throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_ + '/' + url_escape(view) + "/pid/" + url_escape(name) + "/prefixes/" + url_escape(address) + "?len=" + p4p::detail::p4p_token_cast<std::string>(len));
}
Esempio n. 23
0
void AdminPortalProtocol::admin_view_set_prop(const std::string& view, const std::string& name, const std::string& value) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(view) + "/prop/" + url_escape(name) + "?v=" + url_escape(value));
}
Esempio n. 24
0
void AdminPortalProtocol::admin_cancel_txn() throw (P4PProtocolError)
{
    check_txn();
    make_request("DELETE", "admin/" + admin_token_);
    admin_token_.clear();
}
Esempio n. 25
0
void AdminPortalProtocol::admin_view_update_pdistance(const std::string& view) throw (P4PProtocolError)
{
    check_txn();
    make_request("POST", "admin/" + admin_token_ + '/' + url_escape(view) + "/pdistance");
}
Esempio n. 26
0
void AdminPortalProtocol::admin_view_add_pidlink(const std::string& view, const NamedPIDLink& link) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(view) + "/link/" + url_escape(link.name) + "?src=" + url_escape(link.link.src) + "&dst=" + url_escape(link.link.dst));
}
Esempio n. 27
0
void AdminPortalProtocol::admin_commit_txn() throw (P4PProtocolError)
{
    check_txn();
    make_request("POST", "admin/" + admin_token_);
    admin_token_.clear();
}
Esempio n. 28
0
void AdminPortalProtocol::admin_view_add(const std::string& name) throw (P4PProtocolError)
{
    check_txn();
    make_request("PUT", "admin/" + admin_token_ + '/' + url_escape(name));
}