ceph客户端命令行的示例分析
小编给大家分享一下ceph客户端命令行的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
#include
#include
//#include
#include
#include
#include
#include
#include
#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客户端命令行的示例分析"有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!