Skip to content
Snippets Groups Projects
example1.cpp 1.05 KiB
Newer Older
root's avatar
root committed
#include <iostream>
#include <string>
#include <rados/librados.hpp>
 
int main(int argc, const char **argv)
{
  int ret = 0;
  /* Declare the cluster handle and required variables. */
  librados::Rados cluster;
  char cluster_name[] = "ceph";
  char user_name[] = "client.admin";
  uint64_t flags = 0;

  ret = cluster.init2(user_name, cluster_name, flags);
  if (ret < 0) {
    std::cerr << "Couldn't initialize the cluster handle! error " << ret << std::endl;
    return EXIT_FAILURE;
  } else {
           std::cout << "Created a cluster handle." << std::endl;
  }

  ret = cluster.conf_read_file("/etc/ceph/ceph.conf");
  if (ret < 0) {
    std::cerr << "Couldn't read the Ceph configuration file! error " << ret << std::endl;
    return EXIT_FAILURE;
  } else {
      std::cout << "Read the Ceph configuration file." << std::endl;
  }

  ret = cluster.connect();
  if (ret < 0) {
     std::cerr << "Couldn't connect to cluster! error " << ret << std::endl;
     return EXIT_FAILURE;
  } else {
      std::cout << "Connected to the cluster." << std::endl;
  }

  return 0;
}