From: Gary Lowell Date: Tue, 2 Apr 2013 20:26:48 +0000 (-0400) Subject: ceph_deploy: Add local sudo transport method X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d5fa55b23120c9e85fdc475e43f9b9b3052d1394;p=ceph-deploy.git ceph_deploy: Add local sudo transport method 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 Reviewed-by: Dan Mick --- diff --git a/ceph_deploy/admin.py b/ceph_deploy/admin.py index 0291747..5b9287a 100644 --- a/ceph_deploy/admin.py +++ b/ceph_deploy/admin.py @@ -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, diff --git a/ceph_deploy/config.py b/ceph_deploy/config.py index ae8aa48..be625fa 100644 --- a/ceph_deploy/config.py +++ b/ceph_deploy/config.py @@ -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: diff --git a/ceph_deploy/gatherkeys.py b/ceph_deploy/gatherkeys.py index a6715c2..9ec9d35 100644 --- a/ceph_deploy/gatherkeys.py +++ b/ceph_deploy/gatherkeys.py @@ -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: diff --git a/ceph_deploy/install.py b/ceph_deploy/install.py index 5872450..b356fd1 100644 --- a/ceph_deploy/install.py +++ b/ceph_deploy/install.py @@ -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) diff --git a/ceph_deploy/mds.py b/ceph_deploy/mds.py index 8005121..2cf88b2 100644 --- a/ceph_deploy/mds.py +++ b/ceph_deploy/mds.py @@ -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) diff --git a/ceph_deploy/mon.py b/ceph_deploy/mon.py index 969d17f..3f840b6 100644 --- a/ceph_deploy/mon.py +++ b/ceph_deploy/mon.py @@ -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( diff --git a/ceph_deploy/osd.py b/ceph_deploy/osd.py index 734def5..27099da 100644 --- a/ceph_deploy/osd.py +++ b/ceph_deploy/osd.py @@ -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) diff --git a/ceph_deploy/sudo_pushy.py b/ceph_deploy/sudo_pushy.py index 892f7ee..1f5aa72 100644 --- a/ceph_deploy/sudo_pushy.py +++ b/ceph_deploy/sudo_pushy.py @@ -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