1717extern crate ceph_rust;
1818extern crate libc;
1919
20- use libc:: * ;
21- use std:: ffi:: { CStr , CString } ;
22- use std:: { ptr, str, slice} ;
2320
21+ use ceph_rust:: JsonData ;
22+ #[ cfg( target_os = "linux" ) ]
23+ use ceph_rust:: admin_sockets:: * ;
2424#[ cfg( target_os = "linux" ) ]
2525use ceph_rust:: ceph as ceph_helpers;
2626#[ cfg( target_os = "linux" ) ]
2727use ceph_rust:: rados as ceph;
28- #[ cfg( target_os = "linux" ) ]
29- use ceph_rust:: admin_sockets:: * ;
30-
31- use ceph_rust:: JsonData ;
32-
33- macro_rules! zeroed_c_char_buf {
34- ( $n: expr) => {
35- repeat( 0 ) . take( $n) . collect:: <Vec <c_char>>( ) ;
36- }
37- }
3828
3929#[ cfg( not( target_os = "linux" ) ) ]
4030fn main ( ) { }
@@ -43,50 +33,87 @@ fn main() {}
4333
4434#[ cfg( target_os = "linux" ) ]
4535fn main( ) {
46- let mut major: i32 = 0 ;
47- let mut minor: i32 = 0 ;
48- let mut extra: i32 = 0 ;
49-
50- let config_file = CString :: new ( "/etc/ceph/ceph.conf" ) . unwrap ( ) ;
51- let pool_name = CString :: new ( "lsio" ) . unwrap ( ) ;
52- let mut cluster: ceph:: rados_t = std:: ptr:: null_mut ( ) ;
53- let mut ret_code: i32 ;
54-
36+ let pool_name = "lsio" ;
5537 // NB: These examples (except for a few) are low level examples that require the unsafe block.
5638 // However, work for the higher level pur Rust is being worked on in the ceph.rs module of
5739 // the library. A few of those are present below. We will create a common Result or Option
5840 // return and allow for pattern matching.
5941
6042 // Example of accessing the `Admin Socket` for mon
61- match admin_socket_command ( "help" , "/var/run/ceph/ceph-mon.ceph-vm1 .asok" ) {
43+ match admin_socket_command ( "help" , "/var/run/ceph/ceph-mon.ip-172-31-31-247 .asok" ) {
6244 Ok ( json) => {
6345 println ! ( "{}" , json) ;
6446 } ,
65- Err ( e) => { println ! ( "{}" , e) ; } ,
47+ Err ( e) => {
48+ println ! ( "{}" , e) ;
49+ } ,
6650 }
6751
68- unsafe {
69- ceph:: rados_version ( & mut major, & mut minor, & mut extra) ;
70- ret_code = ceph:: rados_create ( & mut cluster, std:: ptr:: null ( ) ) ;
71- println ! ( "Return code: {} - {:?}" , ret_code, cluster) ;
52+ let rados_version = ceph_helpers:: rados_libversion ( ) ;
53+ println ! ( "Librados version: {:?}" , rados_version) ;
7254
73- ret_code = ceph:: rados_conf_read_file ( cluster, config_file. as_ptr ( ) ) ;
74- println ! ( "Return code: {} - {:?}" , ret_code, cluster) ;
55+ println ! ( "Connecting to ceph" ) ;
56+ let cluster = ceph_helpers:: connect_to_ceph ( "admin" , "/etc/ceph/ceph.conf" ) . unwrap ( ) ;
57+ println ! ( "Creating pool {}" , pool_name) ;
58+ ceph_helpers:: rados_create_pool ( cluster, pool_name) . unwrap ( ) ;
7559
76- ret_code = ceph :: rados_connect ( cluster ) ;
77- println ! ( "Return code: {} - {:?}" , ret_code , cluster) ;
78-
79- ret_code = ceph :: rados_pool_create ( cluster , pool_name . as_ptr ( ) ) ;
80- println ! ( "Return code: {}" , ret_code ) ;
60+ println ! ( "Listing pools" ) ;
61+ let pools_list = ceph_helpers :: rados_pools ( cluster) . unwrap ( ) ;
62+ for pool in pools_list {
63+ println ! ( "pool: {}" , pool ) ;
64+ }
8165
82- let pools_list = ceph_helpers:: rados_pools ( cluster) . unwrap ( ) ;
83- println ! ( "{:?}" , pools_list) ;
66+ println ! ( "Deleting pool: {}" , pool_name) ;
67+ ceph_helpers:: rados_delete_pool ( cluster, pool_name) . unwrap ( ) ;
68+
69+ println ! ( "Getting cluster fsid" ) ;
70+ let fsid = ceph_helpers:: rados_fsid ( cluster) ;
71+ println ! ( "rados_cluster_fsid {:?}" , fsid) ;
72+
73+ let cluster_stat = ceph_helpers:: rados_stat_cluster ( cluster) . unwrap ( ) ;
74+ println ! ( "Cluster stat: {:?}" , cluster_stat) ;
75+
76+ // Print CephHealth of cluster
77+ println ! ( "{}" , ceph_helpers:: ceph_health_string( cluster) . unwrap_or( "" . to_string( ) ) ) ;
78+
79+ // Print Status of cluster health a different way
80+ println ! ( "{}" , ceph_helpers:: ceph_status( cluster, & [ "health" , "overall_status" ] ) . unwrap( ) ) ;
81+ // Currently - parses the `ceph --version` call. The admin socket commands `version`
82+ // and `git_version`
83+ // will be called soon to replace the string parse.
84+ // Change to the real mon admin socket name
85+ let ceph_ver = ceph_helpers:: ceph_version ( "/var/run/ceph/ceph-mon.ip-172-31-31-247.asok" ) ;
86+ println ! ( "Ceph Version - {:?}" , ceph_ver) ;
87+ // Mon command to check the health. Same as `ceph -s`
88+ match ceph_helpers:: ceph_mon_command ( cluster, "prefix" , "status" , None ) {
89+ Ok ( ( outbuf, outs) ) => {
90+ match outbuf {
91+ Some ( output) => println ! ( "Ceph mon command (outbuf):\n {}" , output) ,
92+ None => { } ,
93+ }
94+ match outs {
95+ Some ( output) => println ! ( "Ceph mon command (outs):\n {}" , output) ,
96+ None => { } ,
97+ }
98+ } ,
99+ Err ( e) => {
100+ println ! ( "{:?}" , e) ;
101+ } ,
102+ }
84103
85- ret_code = ceph:: rados_pool_delete ( cluster, pool_name. as_ptr ( ) ) ;
86- println ! ( "Return code: {}" , ret_code) ;
104+ // This command encapsulates the lower level mon, osd, pg commands and returns JsonData
105+ // objects based on the key path
106+ println ! ( "{:?}" ,
107+ ceph_helpers:: ceph_command( cluster, "prefix" , "status" , ceph_helpers:: CephCommandTypes :: Mon , & [ "health" ] ) ) ;
87108
109+ // Get a list of Ceph librados commands in JSON format.
110+ // It's very long so it's commented out.
111+ // println!("{}", ceph_helpers::ceph_commands(cluster, None).unwrap().pretty());
112+ unsafe {
113+ println ! ( "Getting rados instance id" ) ;
88114 let instance_id = ceph:: rados_get_instance_id ( cluster) ;
89115 println ! ( "Instance ID: {}" , instance_id) ;
116+ <<<<<<< HEAD
90117
91118 let buf_size: usize = 37 ; // 36 is the constant size +1 for null.
92119 let mut fs_id: Vec < u8 > = Vec :: with_capacity ( buf_size ) ;
@@ -137,8 +164,10 @@ fn main() {
137164 println ! ( "Ceph Version - {:?}" , ceph_ver) ;
138165
139166 ceph:: rados_shutdown ( cluster ) ;
167+ =======
168+ >>>>>>> 35 d831707aa957a5375e64ab1e36a1d83b57e5ee
140169 }
141170
142- println ! ( "RADOS Version - v{}.{}.{}" , major , minor , extra ) ;
143-
171+ ceph_helpers :: disconnect_from_ceph ( cluster ) ;
172+ println ! ( "RADOS Version - v{}.{}.{}" , rados_version . major , rados_version . minor , rados_version . extra ) ;
144173}
0 commit comments