def pool_list(**kwargs): """ List all cephx authorization keys CLI Example: salt '*' sesceph.pool_list 'cluster_name'='ceph' \ 'cluster_uuid'='cluster_uuid' \ Notes: cluster_name Set the cluster name. Defaults to "ceph". cluster_uuid Set the cluster UUID. Defaults to value found in ceph config file. """ m = model.model(**kwargs) u = mdl_updater.model_updater(m) u.hostname_refresh() try: u.defaults_refresh() except: return {} u.load_confg(m.cluster_name) u.mon_members_refresh() u.pool_list() p = presenter.mdl_presentor(m) return p.pool_list()
def cluster_status(**kwargs): """ Get the cluster status CLI Example: salt '*' sesceph.cluster_status \\ 'cluster_name'='ceph' \\ 'cluster_uuid'='cluster_uuid' Notes: Get the cluster status including health if in quorum. Scope: Cluster wide Arguments: cluster_uuid Set the cluster UUID. Defaults to value found in ceph config file. cluster_name Set the cluster name. Defaults to "ceph". """ m = model.model(**kwargs) u = mdl_updater.model_updater(m) u.hostname_refresh() u.defaults_refresh() u.load_confg(m.cluster_name) u.mon_members_refresh() mur = mdl_updater_remote.model_updater_remote(m) can_connect = mur.connect() if not can_connect: raise Error("Cant connect to cluster.") p = presenter.mdl_presentor(m) return p.cluster_status()
def status(self, **kwargs): """ Get status from mon deamon CLI Example: salt '*' sesceph.prepare 'cluster_name'='ceph' \ 'cluster_uuid'='cluster_uuid' \ Notes: cluster_uuid Set the cluster UUID. Defaults to value found in ceph config file. cluster_name Set the cluster name. Defaults to "ceph". """ hostname = platform.node() u = mdl_updater.model_updater(self.model) u.hostname_refresh() try: u.defaults_refresh() except: return {} u.load_confg(self.model.cluster_name) u.mon_members_refresh() q = mdl_query.mdl_query(self.model) if not q.mon_is(): raise Error("Not a mon node") u.mon_status() p = presenter.mdl_presentor(self.model) return p.mon_status()
def pool_list(**kwargs): """ List all cephx authorization keys CLI Example: salt '*' sesceph.pool_list \\ 'cluster_name'='ceph' \\ 'cluster_uuid'='cluster_uuid' Notes: cluster_name Set the cluster name. Defaults to "ceph". cluster_uuid Set the cluster UUID. Defaults to value found in ceph config file. """ m = model.model(**kwargs) u = mdl_updater.model_updater(m) u.hostname_refresh() try: u.defaults_refresh() except: return {} u.load_confg(m.cluster_name) u.mon_members_refresh() mur = mdl_updater_remote.model_updater_remote(m) can_connect = mur.connect() if not can_connect: raise Error("Cant connect to cluster.") mur.pool_list() p = presenter.mdl_presentor(m) return p.pool_list()
def ceph_version(): """ Get the version of ceph installed """ m = model.model() u = mdl_updater.model_updater(m) u.ceph_version_refresh() p = presenter.mdl_presentor(m) return p.ceph_version()
def partition_list_journal(): ''' List all OSD journal partitions by partition CLI Example: salt '*' sesceph.partitions_journal ''' m = model.model() u = mdl_updater.model_updater(m) u.symlinks_refresh() u.partitions_all_refresh() u.discover_partitions_refresh() p = presenter.mdl_presentor(m) return p.discover_journal_partitions()
def partition_list(): ''' List partitions by disk CLI Example: salt '*' sesceph.partitions_all ''' m = model.model() u = mdl_updater.model_updater(m) u.symlinks_refresh() u.partitions_all_refresh() u.partition_table_refresh() p = presenter.mdl_presentor(m) return p.partitions_all()
def osd_discover(): """ List all OSD by cluster CLI Example: salt '*' sesceph.osd_discover """ m = model.model() u = mdl_updater.model_updater(m) u.symlinks_refresh() u.partitions_all_refresh() u.discover_partitions_refresh() p = presenter.mdl_presentor(m) return p.discover_osd()
def create(self, **kwargs): """ Create a mon node CLI Example: salt '*' sesceph.prepare 'cluster_name'='ceph' \ 'cluster_uuid'='cluster_uuid' \ Notes: cluster_uuid Set the cluster UUID. Defaults to value found in ceph config file. cluster_name Set the cluster name. Defaults to "ceph". """ u = mdl_updater.model_updater(self.model) u.hostname_refresh() u.defaults_refresh() u.load_confg(self.model.cluster_name) u.mon_members_refresh() q = mdl_query.mdl_query(self.model) if not q.mon_is(): raise Error("Not a mon node") p = presenter.mdl_presentor(self.model) path_done_file = "/var/lib/ceph/mon/%s-%s/done" % ( self.model.cluster_name, self.model.hostname ) keyring_path_mon = keyring._get_path_keyring_mon_bootstrap(self.model.cluster_name, self.model.hostname) path_adm_sock = "/var/run/ceph/%s-mon.%s.asok" % ( self.model.cluster_name, self.model.hostname ) path_mon_dir = "/var/lib/ceph/mon/%s-%s" % ( self.model.cluster_name, self.model.hostname ) path_admin_keyring = keyring._get_path_keyring_admin(self.model.cluster_name) path_monmap = "/var/lib/ceph/tmp/%s.monmap" % ( self.model.cluster_name ) path_tmp_keyring = "/var/lib/ceph/tmp/%s.keyring" % ( self.model.cluster_name ) if os.path.isfile(path_done_file): log.debug("Mon done file exists:%s" % (path_done_file)) if q.mon_active(): return True arguments = [ constants._path_systemctl, "restart", "ceph-mon@%s" % (self.model.hostname) ] output = utils.execute_local_command(arguments) if output["retcode"] != 0: raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % ( " ".join(arguments), output["retcode"], output["stdout"], output["stderr"]) ) # Error is servcie wont start if not q.mon_active(): raise Error("Failed to start monitor") return True if not os.path.isfile(keyring_path_mon): raise Error("Mon keyring missing") if not os.path.isfile(path_admin_keyring): raise Error("Admin keyring missing") try: tmpd = tempfile.mkdtemp() log.info("Create temp directory %s" %(tmpd)) os.chown(tmpd, self.uid, self.gid) # In 'tmpd' we make the monmap and keyring. key_path = os.path.join(tmpd,"keyring") path_monmap = os.path.join(tmpd,"monmap") log.info("Create monmap %s" % (path_monmap)) self._create_monmap(path_monmap) os.chown(path_monmap, self.uid, self.gid) arguments = [ constants._path_ceph_authtool, "--create-keyring", key_path, "--import-keyring", keyring_path_mon, ] output = utils.execute_local_command(arguments) if output["retcode"] != 0: raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % ( " ".join(arguments), output["retcode"], output["stdout"], output["stderr"] )) arguments = [ constants._path_ceph_authtool, key_path, "--import-keyring", path_admin_keyring, ] output = utils.execute_local_command(arguments) if output["retcode"] != 0: raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % ( " ".join(arguments), output["retcode"], output["stdout"], output["stderr"] )) # Now chown the new file os.chown(key_path, self.uid, self.gid) # Now clean the install area if os.path.isdir(path_mon_dir): log.info("Remove directory content %s" %(path_mon_dir)) shutil.rmtree(path_mon_dir) if not os.path.isdir(path_mon_dir): log.info("Make directory %s" %(path_mon_dir)) os.makedirs(path_mon_dir) os.chown(path_mon_dir, self.uid, self.gid) # now do install arguments = [ constants._path_ceph_mon, "--mkfs", "-i", self.model.hostname, "--monmap", path_monmap, '--keyring', key_path ] output = self._execute(arguments) if output["retcode"] != 0: raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % ( " ".join(arguments), output["retcode"], output["stdout"], output["stderr"] )) # check keyring created: path_mon_key = os.path.join(path_mon_dir, "keyring") if not os.path.isfile(path_mon_key): raise Error("Failed to create '%s'" % (path_mon_key)) # Now start the service arguments = { 'identifier' : self.model.hostname, 'service' : "ceph-mon", } self.init_system.restart(**arguments) self._create_check_retry() open(path_done_file, 'a').close() finally: log.info("Destroy temp directory %s" %(tmpd)) shutil.rmtree(tmpd) return True