don't install packages if you don't want to (--keep_packages)

This commit is contained in:
Gunther Hagleitner 2012-01-27 17:42:56 -08:00
parent 29e0e6be32
commit f98c330f8f
5 changed files with 21 additions and 10 deletions

View File

@ -69,6 +69,10 @@ def parse():
dest="r_component",
metavar="COMPONENT",
help="component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)")
base_group.add_option("-k", "--keep-packages",
action="store_true",
dest="keep_packages",
help="uninstall will keep any installed packages on the system")
parser.add_option_group(base_group)
stop_un_group = OptionGroup(parser, "Uninstall/stop options")
@ -107,5 +111,6 @@ def parse():
output['ignore_deps'] = False
else:
output['ignore_deps'] = True
output['keep_packages'] = options.keep_packages
output['extras'] = args
return output

View File

@ -22,14 +22,17 @@ LOG = logging.getLogger("devstack.packager")
class Packager(object):
def __init__(self, distro):
def __init__(self, distro, keep_packages):
self.distro = distro
self.keep_packages = keep_packages
def install_batch(self, pkgs):
raise NotImplementedError()
def remove_batch(self, pkgs):
raise NotImplementedError()
if not self.keep_packages:
return self._remove_batch(pkgs)
return []
def pre_install(self, pkgs, installparams=None):
pkgnames = sorted(pkgs.keys())
@ -48,3 +51,6 @@ class Packager(object):
if postinstallcmds and len(postinstallcmds):
LOG.info("Running post-install commands for package %s." % (name))
utils.execute_template(*postinstallcmds, params=installparams)
def _remove_batch(self, pkgs):
raise NotImplementedError()

View File

@ -42,8 +42,8 @@ VERSION_TEMPL = "%s=%s"
class AptPackager(pack.Packager):
def __init__(self, distro):
pack.Packager.__init__(self, distro)
def __init__(self, distro, keep_packages):
pack.Packager.__init__(self, distro, keep_packages)
self.auto_remove = True
def _format_pkg(self, name, version):
@ -59,7 +59,7 @@ class AptPackager(pack.Packager):
env_overrides=ENV_ADDITIONS,
**kargs)
def remove_batch(self, pkgs):
def _remove_batch(self, pkgs):
pkgnames = sorted(pkgs.keys())
#form the needed commands
cmds = []

View File

@ -32,8 +32,8 @@ VERSION_TEMPL = "%s-%s"
class YumPackager(pack.Packager):
def __init__(self, distro):
pack.Packager.__init__(self, distro)
def __init__(self, distro, keep_packages):
pack.Packager.__init__(self, distro, keep_packages)
def _format_pkg_name(self, name, version):
if version is not None and len(version):

View File

@ -135,9 +135,9 @@ def _clean_action(action):
return action
def _get_pkg_manager(distro):
def _get_pkg_manager(distro, keep_packages):
cls = _PKGR_MAP.get(distro)
return cls(distro)
return cls(distro, keep_packages)
def _get_action_cls(action_name, component_name):
@ -286,7 +286,7 @@ def _run_components(action_name, component_order, components, distro, root_dir,
non_components = set(components.keys()).difference(set(component_order))
if non_components:
LOG.info("Using reference components [%s]" % (", ".join(sorted(non_components))))
pkg_manager = _get_pkg_manager(distro)
pkg_manager = _get_pkg_manager(distro, program_args.pop('keep_packages', True))
config = _get_config()
#form the active instances (this includes ones we won't use)
all_instances = dict()