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


转载于:https://my.oschina.net/u/2271251/blog/344014

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值