]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add Cluster.write_file()
authorZack Cerza <zack@cerza.org>
Wed, 4 Sep 2013 16:02:56 +0000 (11:02 -0500)
committerZack Cerza <zack@cerza.org>
Thu, 5 Sep 2013 21:55:37 +0000 (16:55 -0500)
teuthology/orchestra/cluster.py

index df97d7a525db8fbef9da7b8830701b4977afb724..7c55fa0ff6d7914b1fea6473d143ce717f06414d 100644 (file)
@@ -1,3 +1,5 @@
+import teuthology.misc
+
 class Cluster(object):
     """
     Manage SSH connections to a cluster of machines.
@@ -51,6 +53,24 @@ class Cluster(object):
         remotes = sorted(self.remotes.iterkeys(), key=lambda rem: rem.name)
         return [remote.run(**kwargs) for remote in remotes]
 
+    def write_file(self, file_name, content, sudo=False, perms=None):
+        """
+        Write text to a file on each node.
+
+        :param file_name: file name
+        :param content: file content
+        :param sudo: use sudo
+        :param perms: file permissions (passed to chmod) ONLY if sudo is True
+        """
+        remotes = sorted(self.remotes.iterkeys(), key=lambda rem: rem.name)
+        for remote in remotes:
+            if sudo:
+                teuthology.misc.sudo_write_file(remote, file_name, content, perms)
+            else:
+                if perms is not None:
+                    raise ValueError("To specify perms, sudo must be True")
+                teuthology.misc.write_file(remote, file_name, content, perms)
+
     def only(self, *roles):
         """
         Return a cluster with only the remotes that have all of given roles.