auto install on start, fix for host ip on br100

This commit is contained in:
Gunther Hagleitner 2012-02-02 21:50:10 -08:00
parent 2f4b5ae17f
commit 57ee7f4e7d
5 changed files with 43 additions and 20 deletions

View File

@ -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':

View File

@ -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):

View File

@ -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,9 +272,8 @@ 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,
@ -274,8 +282,7 @@ def _run_components(action_name, component_order, components, distro, root_dir,
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...

View File

@ -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()

View File

@ -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)
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():