module CephStorage # Create a cluster object # Returns only a single cluster object for given settings class Cluster < ::CephRuby::Cluster extend CephStorage::ClusterWrapper include Multiton # Configure default values for this object attr_reader :cluster_fd, :cluster, :config_dir, :user, :flags wrap_me :pool_id_by_name, :pool_name_by_id, :status, :fsid private :connect, :setup_using_file class << self # Make this private otherwise the self.new {} returns a different # Object to self.new {CONFIG_DIR, CLUSTER, USER} protected :new end # Create a new object def initialize(config_dir: CONFIG_DIR, cluster: CLUSTER, user: USER, flags: FLAGS) CephRuby.logger = CephStorage.logger init(config_dir, cluster, user, flags) log("init config_dir #{config_dir}, cluster #{cluster}, user: #{user}") open yield(@cluster_fd) if block_given? rescue StandardError log("unable to open cluster #{cluster}") raise end def rados_cluster return @cluster_fd unless block_given? yield(@cluster_fd) end def pool(name) ensure_open p = CephStorage::PoolFactory.build(self, name) yield(p) if block_given? p end def pools CephStorage::PoolEnumerator.new(self) end def shutdown return unless open? log('shutdown') @cluster_fd.shutdown end def open? !@cluster_fd.nil? && !@cluster_fd.handle.nil? end def ensure_open return if open? open end def open return if open? log('open') fd_init unless @cluster_fd @cluster_fd.connect unless open? end def path "ceph://#{cluster}" end private def log(message) CephStorage.log("cluster #{cluster} #{message}") end def fd_init @cluster_fd = ::CephRuby::Cluster.new( config_path: config_dir, cluster: cluster, user: user, flags: flags ) end def init(config_dir, cluster, user, flags) @cluster = cluster @user = user @config_dir = config_dir @flags = flags end end end