]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/ssh: add/remove labels
authorSage Weil <sage@redhat.com>
Mon, 25 Nov 2019 14:32:59 +0000 (08:32 -0600)
committerSage Weil <sage@redhat.com>
Tue, 26 Nov 2019 13:31:06 +0000 (07:31 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/ssh/module.py

index 98a795599e3eef424a12fa09b664aee38372e320..f5e47bffc6655f2136a8988a24a88db888c76fff 100644 (file)
@@ -579,6 +579,38 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         nodes = [orchestrator.InventoryNode(host_name, inventory.Devices([])) for host_name in self.inventory_cache]
         return orchestrator.TrivialReadCompletion(nodes)
 
+    def add_host_label(self, host, label):
+        if host not in self.inventory:
+            raise OrchestratorError('host %s does not exist' % host)
+
+        @log_exceptions
+        def run(host, label):
+            if 'labels' not in self.inventory[host]:
+                self.inventory[host]['labels'] = list()
+            if label not in self.inventory[host]['labels']:
+                self.inventory[host]['labels'].append(label)
+            self._save_inventory()
+            return 'Added label %s to host %s' % (label, host)
+
+        return SSHWriteCompletion(
+            self._worker_pool.apply_async(run, (host, label)))
+
+    def remove_host_label(self, host, label):
+        if host not in self.inventory:
+            raise OrchestratorError('host %s does not exist' % host)
+
+        @log_exceptions
+        def run(host, label):
+            if 'labels' not in self.inventory[host]:
+                self.inventory[host]['labels'] = list()
+            if label in self.inventory[host]['labels']:
+                self.inventory[host]['labels'].remove(label)
+            self._save_inventory()
+            return 'Removed label %s to host %s' % (label, host)
+
+        return SSHWriteCompletion(
+            self._worker_pool.apply_async(run, (host, label)))
+
     def _refresh_host_services(self, host):
         out, code = self._run_ceph_daemon(
             host, 'mon', 'ls', [], no_fsid=True)