您好,登錄后才能下訂單哦!
小編給大家分享一下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
看完了這篇文章,相信你對(duì)“ceph客戶端命令行的示例分析”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。