]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
ceph_deploy: Add local sudo transport method
authorGary Lowell <glowell@inktank.com>
Tue, 2 Apr 2013 20:26:48 +0000 (16:26 -0400)
committerGary Lowell <glowell@inktank.com>
Sat, 13 Apr 2013 00:56:26 +0000 (20:56 -0400)
Adds a local transport with sudo to parallel the existing ssh
sudo transport for pushy.  Override the original local
transport __init__ to prevent initializer from overwriting
the command line.  (Bug #4367)

Signed-off-by: Gary Lowell <gary.lowell@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
ceph_deploy/admin.py
ceph_deploy/config.py
ceph_deploy/gatherkeys.py
ceph_deploy/install.py
ceph_deploy/mds.py
ceph_deploy/mon.py
ceph_deploy/osd.py
ceph_deploy/sudo_pushy.py

index 02917473a37dbe9eb9f4028ff757cdaf48703626..5b9287adb1f33c47947955bebf9460a144e54577 100644 (file)
@@ -5,7 +5,7 @@ from cStringIO import StringIO
 from . import exc
 from . import conf
 from .cliutil import priority
-
+from .sudo_pushy import get_transport
 
 LOG = logging.getLogger(__name__)
 
@@ -32,10 +32,7 @@ def admin(args):
     for hostname in args.client:
         LOG.debug('Pushing admin keys and conf to %s', hostname)
         try:
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                    hostname=hostname,
-                    ))
-
+            sudo = args.pushy(get_transport(hostname))
             write_conf_r = sudo.compile(conf.write_conf)
             write_conf_r(
                 cluster=args.cluster,
@@ -43,9 +40,7 @@ def admin(args):
                 overwrite=args.overwrite_conf,
                 )
 
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                    hostname=hostname,
-                    ))
+            sudo = args.pushy(get_transport(hostname))
             write_file_r = sudo.compile(write_file)
             error = write_file_r(
                 '/etc/ceph/%s.client.admin.keyring' % args.cluster,
index ae8aa48f52b52c5268d868e82d35373a3898f7b9..be625faa1773362c1f0663c1db3b3553eec20aaa 100644 (file)
@@ -6,6 +6,7 @@ from . import exc
 from . import conf
 from . import misc
 from .cliutil import priority
+from .sudo_pushy import get_transport
 
 LOG = logging.getLogger(__name__)
 
@@ -18,10 +19,7 @@ def config_push(args):
     for hostname in args.client:
         LOG.debug('Pushing config to %s', hostname)
         try:
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                    hostname=hostname,
-                    ))
-
+            sudo = args.pushy(get_transport(hostname))
             write_conf_r = sudo.compile(conf.write_conf)
             write_conf_r(
                 cluster=args.cluster,
@@ -47,7 +45,7 @@ def config_pull(args):
     for hostname in args.client:
         try:
             LOG.debug('Checking %s for %s', hostname, frompath)
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            sudo = args.pushy(get_transport(hostname))
             get_file_r = sudo.compile(misc.get_file)
             conf_file = get_file_r(path=frompath)
             if conf_file is not None:
index a6715c2b3ed94022f5f4282dff6ba489ab7676a0..9ec9d3594d57fa6eb6ce95ddc4f67e32cbe7762e 100644 (file)
@@ -3,6 +3,7 @@ import logging
 
 from .cliutil import priority
 from . import misc
+from .sudo_pushy import get_transport
 
 LOG = logging.getLogger(__name__)
 
@@ -14,7 +15,7 @@ def fetch_file(args, frompath, topath, hosts):
     else:
         for hostname in hosts:
             LOG.debug('Checking %s for %s', hostname, frompath)
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            sudo = args.pushy(get_transport(hostname))
             get_file_r = sudo.compile(misc.get_file)
             key = get_file_r(path=frompath.format(hostname=hostname))
             if key is not None:
index 587245007ae49143b13c5f5c21ffdce58ecf3443..b356fd1d3964ac9c3f7ee4aecadb964a45485fbb 100644 (file)
@@ -4,6 +4,7 @@ import logging
 from . import exc
 from . import lsb
 from .cliutil import priority
+from .sudo_pushy import get_transport
 
 LOG = logging.getLogger(__name__)
 
@@ -194,7 +195,7 @@ def install(args):
         LOG.debug('Detecting platform for host %s ...', hostname)
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+        sudo = args.pushy(get_transport(hostname))
         (distro, release, codename) = lsb.get_lsb_release(sudo)
         LOG.debug('Distro %s release %s codename %s', distro, release, codename)
 
@@ -225,7 +226,7 @@ def uninstall(args):
         LOG.debug('Detecting platform for host %s ...', hostname)
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+        sudo = args.pushy(get_transport(hostname))
         (distro, release, codename) = lsb.get_lsb_release(sudo)
         LOG.debug('Distro %s codename %s', distro, codename)
 
@@ -251,7 +252,7 @@ def purge(args):
         LOG.debug('Detecting platform for host %s ...', hostname)
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+        sudo = args.pushy(get_transport(hostname))
         (distro, release, codename) = lsb.get_lsb_release(sudo)
         LOG.debug('Distro %s codename %s', distro, codename)
 
@@ -272,7 +273,7 @@ def purge_data(args):
 
     for hostname in args.host:
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+        sudo = args.pushy(get_transport(hostname))
 
         LOG.debug('Purging data from host %s ...', hostname)
         purge_data_any_r = sudo.compile(purge_data_any)
index 8005121ec6ebb8e348f11538241aea10a23f1274..2cf88b2e3a4855f97946f97b736e46bb4d9c2b72 100644 (file)
@@ -6,6 +6,7 @@ from . import conf
 from . import exc
 from . import lsb
 from .cliutil import priority
+from .sudo_pushy import get_transport
 
 
 LOG = logging.getLogger(__name__)
@@ -143,7 +144,7 @@ def mds_create(args):
     for hostname, name in args.mds:
         try:
             # TODO username
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            sudo = args.pushy(get_transport(hostname))
 
             (distro, release, codename) = lsb.get_lsb_release(sudo)
             init = lsb.choose_init(distro, codename)
index 969d17fc235a950d545d2eaa8cca658006b58cb2..3f840b6501f486179203fd85dbd0491f33875c74 100644 (file)
@@ -8,6 +8,7 @@ from . import conf
 from . import exc
 from . import lsb
 from .cliutil import priority
+from .sudo_pushy import get_transport
 
 
 LOG = logging.getLogger(__name__)
@@ -81,6 +82,7 @@ def create_mon(cluster, monitor_keyring, init):
 
 
 def mon_create(args):
+
     cfg = conf.load(args)
     if not args.mon:
         try:
@@ -113,7 +115,7 @@ def mon_create(args):
             LOG.debug('Deploying mon to %s', hostname)
 
             # TODO username
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            sudo = args.pushy(get_transport(hostname))
 
             (distro, release, codename) = lsb.get_lsb_release(sudo)
             init = lsb.choose_init(distro, codename)
@@ -209,7 +211,7 @@ def mon_destroy(args):
             LOG.debug('Removing mon from %s', hostname)
 
             # TODO username
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            sudo = args.pushy(get_transport(hostname))
 
             destroy_mon_r = sudo.compile(destroy_mon)
             destroy_mon_r(
index 734def5cb48360bb304e86edc823869543201f6b..27099daec4e627d9a0d1349b97b00f3fd2d5eb8e 100644 (file)
@@ -9,6 +9,7 @@ from . import conf
 from . import exc
 from . import lsb
 from .cliutil import priority
+from .sudo_pushy import get_transport
 
 
 LOG = logging.getLogger(__name__)
@@ -136,9 +137,7 @@ def prepare(args, cfg, activate_prepared_disk):
     for hostname, disk, journal in args.disk:
         try:
             # TODO username
-            sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                    hostname=hostname,
-                    ))
+            sudo = args.pushy(get_transport(hostname))
 
             if hostname not in bootstrapped:
                 bootstrapped.add(hostname)
@@ -193,9 +192,7 @@ def activate(args, cfg):
     for hostname, disk, journal in args.disk:
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                hostname=hostname,
-                ))
+        sudo = args.pushy(get_transport(hostname))
 
         LOG.debug('Activating host %s disk %s', hostname, disk)
 
@@ -250,9 +247,7 @@ def disk_zap(args):
         LOG.debug('zapping %s on %s', disk, hostname)
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                hostname=hostname,
-                ))
+        sudo = args.pushy(get_transport(hostname))
         zap_r = sudo.compile(zap)
         zap_r(disk)
 
@@ -272,9 +267,8 @@ def disk_list(args, cfg):
     for hostname, disk, journal in args.disk:
 
         # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                hostname=hostname,
-                ))
+        sudo = args.pushy(get_transport(hostname))
+
         LOG.debug('Listing disks on {hostname}...'.format(hostname=hostname))
 
         list_disk_r = sudo.compile(list_disk)
index 892f7ee4875f4ec3305de62c1f6fc7432b21af9b..1f5aa72ce84bcae7d1d653b0a81c0f85ff854391 100644 (file)
@@ -1,5 +1,18 @@
 import pushy.transport.ssh
+import pushy.transport.local
+import os, shutil, subprocess, sys
 
+def __init__(self, command, address, **kwargs):
+    pushy.transport.BaseTransport.__init__(self, address)
+
+    self.__proc = subprocess.Popen(command, stdin=subprocess.PIPE,
+                                   stdout=subprocess.PIPE,
+                                   stderr=subprocess.PIPE,
+                                   bufsize=65535)
+
+    self.stdout = self.__proc.stdout
+    self.stderr = self.__proc.stderr
+    self.stdin  = self.__proc.stdin
 
 class SshSudoTransport(object):
     @staticmethod
@@ -7,6 +20,22 @@ class SshSudoTransport(object):
         command = ['sudo'] + command
         return pushy.transport.ssh.Popen(command, *a, **kw)
 
+class LocalSudoTransport(object):
+    @staticmethod
+    def Popen(command, *a, **kw):
+        command = ['sudo'] + command
+        # Overide the original initializer
+        pushy.transport.local.Popen.__init__ = __init__
+        return pushy.transport.local.Popen(command, *a, **kw)
+
+def get_transport(hostname):
+    import socket
+
+    myhostname = socket.gethostname().split('.')[0]
+    if hostname == myhostname:
+        return 'local+sudo:'
+    else:
+        return 'ssh+sudo:{hostname}'.format(hostname=hostname)
 
 def patch():
     """
@@ -14,3 +43,4 @@ def patch():
     sudo on the remote host.
     """
     pushy.transports['ssh+sudo'] = SshSudoTransport
+    pushy.transports['local+sudo'] = LocalSudoTransport