ceph客户端命令行

#include <stdio.h>
#include <string.h>
//#include <rados/librados.h>
#include <rados/librados.hpp>
#include <iostream>
#include <fstream>
#include <list>
#include <iterator>
#define EXIT_SUCCESS 0
using namespace std;
using namespace librados;
int main(int argc, char **argv)
{
   Rados rados;
    rados_ioctx_t io;
    const char *poolname = "data";
   const char cluster_name[] = "ceph";
   const char user_name[] = "client.admin"; //用户名
    uint64_t flags=0;
    char xattr[] = "en_US";
  int err;
 
  char fsid[50]={0};
    
  err= rados.init2(user_name,cluster_name,  flags);
  if (err<0) {
     cerr << "couldn't initialize rados! error " << err << std::endl;
  }
  //读取配置文件,完成rados句柄
  err=rados.conf_read_file("/etc/ceph/ceph.conf");
 if (err < 0)
    {
        fprintf(stderr, "%s: cannot read config file: %s\n", argv[0], strerror(-err));
    }
    else
    {
        printf("\nRead the config file.\n");
    }

        /* Connect to the cluster */
    err = rados.connect();
    if (err < 0)
    {
        fprintf(stderr, "%s: cannot connect to cluster: %s\n", argv[0], strerror(-err));
    }
    else
    {
        printf("\nConnected to the cluster.\n");
   }

  bufferlist inbl, outbl;
  string outs;
  err = rados.mon_command("{\"prefix\": \"mon_status\"}",
                   inbl, &outbl, &outs);
  if (err < 0) {
      cerr << "error listing get_command_descriptions: " << err << std::endl;
      rados.shutdown();
  }
  cout << outbl.c_str() << std::endl;
      
  err = rados.mon_command("{\"prefix\": \"osd find\", \"id\":\"osd.1\"}",
                   inbl, &outbl, &outs);
  if (err < 0) {
      cerr << "error listing get_command_descriptions: " << err << std::endl;
      rados.shutdown();
  }
  cout << outbl.c_str() << std::endl;    

    rados.shutdown();
    return 0;
}

g++ ceph_conmand.c -o ceph_con -lrados


你可能感兴趣的:(命令,command,ceph,rados)