小编给大家分享一下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
看完了这篇文章,相信你对“ceph客户端命令行的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。