From: Dan Mick Date: Tue, 30 Apr 2013 21:00:20 +0000 (-0700) Subject: ceph-deploy update (RPM or deb) X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fheads%2Fwip-update;p=ceph-deploy.git ceph-deploy update (RPM or deb) --- diff --git a/ceph_deploy/update.py b/ceph_deploy/update.py new file mode 100644 index 0000000..c38071c --- /dev/null +++ b/ceph_deploy/update.py @@ -0,0 +1,99 @@ +import logging +import subprocess + +from . import exc +from . import conf +from . import lsb +from .cliutil import priority +from .sudo_pushy import get_transport + +APT_SOURCES_LIST_LINE = 'deb http://ceph.com/packages/ceph-deploy/debian precise main' +APT_KEY_LOC = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc' +YUM_REPO_UPDATE = '' +YUM_KEY_LOC = '' + +LOG = logging.getLogger(__name__) + +def update_apt(sources_list_line, key_loc): + import subprocess + + # must define this inside to be able to use it with pushy + def gather_stderr(*args, **kwargs): + p = subprocess.Popen(*args, **kwargs) + (out, err) = p.communicate() + rc = p.returncode + if rc == 0: + return None + return ' '.join(args[0]) + ': error code {}\n'.format(rc) + err + + # update apt configuration if file is not present or empty + + with open('/etc/apt/sources.list.d/ceph-deploy.list', 'a+') as f: + if not len(f.readlines()): + f.write(sources_list_line + '\n') + + s = gather_stderr( + args='wget -q -O- \'{}\' | apt-key add -'.format(key_loc), + shell=True + ) + if s: + return s + + s = gather_stderr(['/usr/bin/apt-get', '-q', 'update'], + stderr=subprocess.PIPE) + if s: + return s + + return gather_stderr(['/usr/bin/apt-get', '-qy', 'install', 'ceph-deploy'], + stderr = subprocess.PIPE) + +def update_yum(rpm_url, key_url): + import subprocess + + def gather_stderr(*args, **kwargs): + p = subprocess.Popen(*args, **kwargs) + (out, err) = p.communicate() + rc = p.returncode + if rc == 0: + return None + return ' '.join(args[0]) + ': error code {}\n'.format(rc) + err + + s = gather_stderr(['/usr/bin/rpm', '--import', key_url]) + if s: + return s + + s = gather_stderr(['/usr/bin/rpm', '-Uvh', '--quiet', rpm_url]) + if s: + return s + + return gather_stderr(['/usr/bin/yum', '-yq', 'install', 'ceph-deploy']) + +def update(args): + LOG.info("Checking for/installing new ceph-deploy packages") + + sudo = args.pushy("local+sudo:") + (distro, release, codename) = lsb.get_lsb_release(sudo) + if distro == 'Debian' or distro == 'Ubuntu': + sudo_r = sudo.compile(update_apt) + s = sudo_r(APT_SOURCES_LIST_LINE, APT_KEY_LOC) + elif distro == 'CentOS': + sudo_r = sudo.compile(update_yum) + s = sudo_r(YUM_REPO_UPDATE, YUM_KEY_LOC) + else: + raise exc.UnsupportedPlatform(distro, codename) + if s: + LOG.error("Error installing latest ceph-deploy packages:") + LOG.error(s) + else: + LOG.info("Updated ceph-deploy") + + +@priority(80) +def make(parser): + """ + Install latest ceph-deploy packages. + """ + parser.set_defaults( + func=update, + ) + diff --git a/setup.py b/setup.py index 19168f5..6208650 100644 --- a/setup.py +++ b/setup.py @@ -57,6 +57,7 @@ setup( 'forgetkeys = ceph_deploy.forgetkeys:make', 'config = ceph_deploy.config:make', 'admin = ceph_deploy.admin:make', + 'update = ceph_deploy.update:make', ], },