#![allow(unused_imports)]
extern crate ceph_rust;
extern crate libc;
use ceph_rust::JsonData;
#[cfg(target_os = "linux")]
use ceph_rust::admin_sockets::*;
#[cfg(target_os = "linux")]
use ceph_rust::ceph as ceph_helpers;
#[cfg(target_os = "linux")]
use ceph_rust::rados as ceph;
#[cfg(not(target_os = "linux"))]
fn main() {}
#[cfg(target_os = "linux")]
fn main() {
let pool_name = "lsio";
match admin_socket_command("help", "/var/run/ceph/ceph-mon.ip-172-31-31-247.asok") {
Ok(json) => {
println!("{}", json);
},
Err(e) => {
println!("{}", e);
},
}
let rados_version = ceph_helpers::rados_libversion();
println!("Librados version: {:?}", rados_version);
println!("Connecting to ceph");
let cluster = ceph_helpers::connect_to_ceph("admin", "/etc/ceph/ceph.conf").unwrap();
println!("Creating pool {}", pool_name);
ceph_helpers::rados_create_pool(cluster, pool_name).unwrap();
println!("Listing pools");
let pools_list = ceph_helpers::rados_pools(cluster).unwrap();
for pool in pools_list{
println!("pool: {}", pool);
}
println!("Deleting pool: {}", pool_name);
ceph_helpers::rados_delete_pool(cluster, pool_name).unwrap();
println!("Getting cluster fsid");
let fsid = ceph_helpers::rados_fsid(cluster);
println!("rados_cluster_fsid {:?}", fsid);
let cluster_stat = ceph_helpers::rados_stat_cluster(cluster).unwrap();
println!("Cluster stat: {:?}", cluster_stat);
println!("{}", ceph_helpers::ceph_health_string(cluster).unwrap_or("".to_string()));
println!("{}", ceph_helpers::ceph_status(cluster, &["health", "overall_status"]).unwrap());
let ceph_ver = ceph_helpers::ceph_version("/var/run/ceph/ceph-mon.ip-172-31-31-247.asok");
println!("Ceph Version - {:?}", ceph_ver);
match ceph_helpers::ceph_mon_command(cluster, "prefix", "status", None) {
Ok((outbuf, outs)) => {
match outbuf {
Some(output) => println!("Ceph mon command (outbuf):\n{}", output),
None => {},
}
match outs {
Some(output) => println!("Ceph mon command (outs):\n{}", output),
None => {},
}
},
Err(e) => {
println!("{:?}", e);
},
}
println!("{:?}",
ceph_helpers::ceph_command(cluster, "prefix", "status", ceph_helpers::CephCommandTypes::Mon, &["health"]));
unsafe {
println!("Getting rados instance id");
let instance_id = ceph::rados_get_instance_id(cluster);
println!("Instance ID: {}", instance_id);
let buf_size: usize = 37; let mut fs_id: Vec<u8> = Vec::with_capacity(buf_size);
let len = ceph::rados_cluster_fsid(cluster, fs_id.as_mut_ptr() as *mut c_char, buf_size);
let slice = slice::from_raw_parts(fs_id.as_mut_ptr(), buf_size - 1);
let s: &str = str::from_utf8(slice).unwrap();
println!("rados_cluster_fsid len: {} - {}", len, s);
let ping_monitor = ceph_helpers::ping_monitor(cluster, "ceph-mon.ceph-vm1"); println!("Ping monitor: {:?}", ping_monitor);
let cluster_stat = ceph_helpers::rados_stat_cluster(cluster);
println!("Cluster stat: {:?}", cluster_stat);
match ceph_helpers::ceph_mon_command(cluster, "prefix", "status", None) {
Ok((outbuf, outs)) => {
match outbuf {
Some(output) => println!("Ceph mon command (outbuf):\n{}", output),
None => {},
}
match outs {
Some(output) => println!("Ceph mon command (outs):\n{}", output),
None => {},
}
},
Err(e) => {println!("{:?}", e);},
}
println!("{}", ceph_helpers::ceph_health_string(cluster).unwrap_or("".to_string()));
println!("{}", ceph_helpers::ceph_status(cluster, &["health", "overall_status"]).unwrap());
println!("{:?}", ceph_helpers::ceph_command(cluster, "prefix", "status", ceph_helpers::CephCommandTypes::Mon, &["health"]));
let ceph_ver = ceph_helpers::ceph_version("/var/run/ceph/ceph-mon.ceph-vm1.asok"); println!("Ceph Version - {:?}", ceph_ver);
ceph::rados_shutdown(cluster);
}
ceph_helpers::disconnect_from_ceph(cluster);
println!("RADOS Version - v{}.{}.{}", rados_version.major, rados_version.minor, rados_version.extra);
}