From 57ee7f4e7d1aad8bc0f77529a82306599ee2388e Mon Sep 17 00:00:00 2001 From: Gunther Hagleitner Date: Thu, 2 Feb 2012 21:50:10 -0800 Subject: [PATCH] auto install on start, fix for host ip on br100 --- devstack/cfg.py | 4 ++-- devstack/component.py | 6 ++++++ devstack/progs/actions.py | 27 +++++++++++++++++---------- devstack/trace.py | 3 +++ devstack/utils.py | 23 +++++++++++++++-------- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/devstack/cfg.py b/devstack/cfg.py index eac8f013..82ba6dd2 100644 --- a/devstack/cfg.py +++ b/devstack/cfg.py @@ -100,8 +100,8 @@ class EnvConfigParser(ConfigParser.RawConfigParser): if section == 'host' and option == 'ip': LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.") netifc = self.get("default", "net_interface") or "eth0" - netifc = netifc.strip() - host_ip = utils.get_host_ip(netifc, settings.IPV4) + netifcs = [netifc.strip(), 'br100'] + host_ip, netifc = utils.get_host_ip(netifcs, settings.IPV4) LOG.debug("Determined host ip to be: \"%s\" from network interface: %s" % (host_ip, netifc)) return host_ip elif section == 'passwords': diff --git a/devstack/component.py b/devstack/component.py index 31e6d70c..8c88e3eb 100644 --- a/devstack/component.py +++ b/devstack/component.py @@ -60,6 +60,12 @@ class ComponentBase(object): def pre_fetch_configs(self): pass + def is_started(self): + return tr.TraceReader(self.tracedir, tr.START_TRACE).exists() + + def is_installed(self): + return tr.TraceReader(self.tracedir, tr.IN_TRACE).exists() + class PkgInstallComponent(ComponentBase): def __init__(self, component_name, *args, **kargs): diff --git a/devstack/progs/actions.py b/devstack/progs/actions.py index 65351bb0..e24489ed 100644 --- a/devstack/progs/actions.py +++ b/devstack/progs/actions.py @@ -254,6 +254,15 @@ def _run_components(action_name, component_order, components, distro, root_dir, elif action_name == settings.STOP: _stop(component, instance, force) elif action_name == settings.START: + if not instance.is_installed(): + install_cls = common.get_action_cls(settings.INSTALL, component) + install_instance = install_cls(instances=dict(), + distro=distro, + packager=pkg_manager, + config=config, + root=root_dir, + opts=components.get(component, list())) + _install(component, install_instance) start_result = _start(component, instance) if start_result: #TODO clean this up. @@ -263,19 +272,17 @@ def _run_components(action_name, component_order, components, distro, root_dir, results.append(str(start_result)) elif action_name == settings.UNINSTALL: if component not in _NO_AUTO_STOP: - # always stop first. doesn't hurt if already stopped - but makes - # sure that there are no lingering processes if not - try: + # stop the component if started + if instance.is_started(): stop_cls = common.get_action_cls(settings.STOP, component) stop_instance = stop_cls(instances=dict(), - distro=distro, - packager=pkg_manager, - config=config, - root=root_dir, - opts=components.get(component, list())) + distro=distro, + packager=pkg_manager, + config=config, + root=root_dir, + opts=components.get(component, list())) _stop(component, stop_instance, force) - except excp.StopException: - LOG.warn("Failed at stopping %s before uninstalling, skipping stop.", component) + _uninstall(component, instance, force) end_time = time.time() #display any configs touched... diff --git a/devstack/trace.py b/devstack/trace.py index 9392e9c9..df5fc304 100644 --- a/devstack/trace.py +++ b/devstack/trace.py @@ -168,6 +168,9 @@ class TraceReader(object): def _read(self): return parse_name(self.root, self.name) + def exists(self): + return sh.exists(self.trace_fn) + def py_listing(self): return self._readpy() diff --git a/devstack/utils.py b/devstack/utils.py index 7aa2be7c..c50f70cb 100644 --- a/devstack/utils.py +++ b/devstack/utils.py @@ -144,18 +144,25 @@ def load_json(fn): return json.loads(data) -def get_host_ip(def_net_ifc, def_ip_version): +def get_host_ip(def_net_ifcs, def_ip_version): ip = None + ifc = None + interfaces = get_interfaces() - def_info = interfaces.get(def_net_ifc) - if def_info: - ipinfo = def_info.get(def_ip_version) - if ipinfo: - ip = ipinfo.get('addr') + + for net_ifc in def_net_ifcs: + def_info = interfaces.get(net_ifc) + if def_info: + ipinfo = def_info.get(def_ip_version) + if ipinfo: + ip = ipinfo.get('addr') + ifc = net_ifc + if ip: + break if ip is None: - msg = "Your host does not have an ip address on interface: %s using ip version: %s!" % (def_net_ifc, def_ip_version) + msg = "Your host does not have an ip address on interfaces: %s using ip version: %s!" % (def_net_ifcs.join(','), def_ip_version) raise excp.NoIpException(msg) - return ip + return (ip, ifc) def get_interfaces():