Crate rust_corosync

source ·
Expand description

This crate provides access to the corosync libraries cpg, cfg, cmap, quorum & votequorum from Rust. They are a fairly thin layer around the actual API calls but with Rust data types and iterators.

Corosync is a low-level provider of cluster services for high-availability clusters, for more information about corosync see https://corosync.github.io/corosync/

No more information about corosync itself will be provided here, it is expected that if you feel you need access to the Corosync API calls, you know what they do :)

Example

extern crate rust_corosync as corosync;
use corosync::cmap;

fn main()
{
    // Open connection to corosync libcmap
    let handle =
    match cmap::initialize(cmap::Map::Icmap) {
        Ok(h) => {
            println!("cmap initialized.");
            h
        }
        Err(e) => {
            println!("Error in CMAP (Icmap) init: {}", e);
            return;
        }
    };

    // Set a numeric value (this is a generic fn)
    match cmap::set_number(handle, "test.test_uint32", 456)
    {
        Ok(_) => {}
        Err(e) => {
            println!("Error in CMAP set_u32: {}", e);
            return;
        }
    };

    // Get a value - this will be a Data struct
    match cmap::get(handle, "test.test_uint32")
    {
        Ok(v) => {
            println!("GOT value {}", v);
        }
        Err(e) => {
            println!("Error in CMAP get: {}", e);
            return;
        }
    };

    // Use an iterator
    match cmap::CmapIterStart::new(handle, "totem.") {
        Ok(cmap_iter) => {
            for i in cmap_iter {
                println!("ITER: {:?}", i);
            }
            println!("");
        }
        Err(e) => {
            println!("Error in CMAP iter start: {}", e);
        }
    }

    // Close this connection
    match cmap::finalize(handle)
    {
        Ok(_) => {}
        Err(e) => {
            println!("Error in CMAP get: {}", e);
            return;
        }
    };
}

Modules

cfg is the internal configuration and information library for corosync, it is mainly used by internal tools but may also contain API calls useful to some applications that need detailed information about or control of the operation of corosync and the cluster.
cmap is the internal ‘database’ of corosync - though it is NOT replicated. Mostly it contains a copy of the corosync.conf file and information about the running state of the daemon. The cmap API provides two ‘maps’. Icmap, which is as above, and Stats, which contains very detailed statistics on the running system, this includes network and IPC calls.
cpg is the Control Process Groups subsystem of corosync and is usually used for sending messages around the cluster. All processes using CPG belong to a named group (whose members they can query) and all messages are sent with delivery guarantees.
Quorum provides basic information about the quorate state of the cluster with callbacks when nodelists change.
votequorum is the main quorum provider for corosync, using this API, users can query the state of nodes in the cluster, request callbacks when the nodelists change, and set up a quorum device.

Structs

A corosync nodeid

Enums

Error codes returned from the corosync libraries
Flags to use with dispatch functions, eg cpg::dispatch One will dispatch a single callback (blocking) and return. All will loop trying to dispatch all possible callbacks. Blocking is like All but will block between callbacks. OneNonBlocking will dispatch a single callback only if one is available, otherwise it will return even if no callback is available.
Flags to use with (most) tracking API calls

Type Definitions

Result type returned from most corosync library calls. Contains a CsError and possibly other data as required