debuggers.hg
changeset 14636:ea68ae90fc10
Add auto-start and auto-stop functionality.
Patch by Alastair Tse <atse@xensource.com>.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Patch by Alastair Tse <atse@xensource.com>.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Tue Mar 27 16:52:56 2007 +0100 (2007-03-27) |
parents | 104fc282e53c |
children | b13a95fc0e2f |
files | tools/python/xen/xend/XendConfig.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/server/SrvServer.py |
line diff
1.1 --- a/tools/python/xen/xend/XendConfig.py Tue Mar 27 16:33:26 2007 +0100 1.2 +++ b/tools/python/xen/xend/XendConfig.py Tue Mar 27 16:52:56 2007 +0100 1.3 @@ -452,7 +452,10 @@ class XendConfig(dict): 1.4 for key, typ in XENAPI_CFG_TYPES.items(): 1.5 val = sxp.child_value(sxp_cfg, key) 1.6 if val is not None: 1.7 - cfg[key] = typ(val) 1.8 + try: 1.9 + cfg[key] = typ(val) 1.10 + except (ValueError, TypeError), e: 1.11 + log.warn('Unable to convert type value for key: %s' % key) 1.12 1.13 # Convert deprecated options to current equivalents. 1.14
2.1 --- a/tools/python/xen/xend/XendDomain.py Tue Mar 27 16:33:26 2007 +0100 2.2 +++ b/tools/python/xen/xend/XendDomain.py Tue Mar 27 16:52:56 2007 +0100 2.3 @@ -569,6 +569,26 @@ class XendDomain: 2.4 finally: 2.5 self.domains_lock.release() 2.6 2.7 + def autostart_domains(self): 2.8 + """ Autostart managed domains that are marked as such. """ 2.9 + 2.10 + need_starting = [] 2.11 + 2.12 + self.domains_lock.acquire() 2.13 + try: 2.14 + for dom_uuid, dom in self.managed_domains.items(): 2.15 + if dom and dom.state == DOM_STATE_HALTED: 2.16 + on_xend_start = dom.info.get('on_xend_start', 'ignore') 2.17 + auto_power_on = dom.info.get('auto_power_on', False) 2.18 + should_start = (on_xend_start == 'start') or auto_power_on 2.19 + if should_start: 2.20 + need_starting.append(dom_uuid) 2.21 + finally: 2.22 + self.domains_lock.release() 2.23 + 2.24 + for dom_uuid in need_starting: 2.25 + self.domain_start(dom_uuid, False) 2.26 + 2.27 def cleanup_domains(self): 2.28 """Clean up domains that are marked as autostop. 2.29 Should be called when Xend goes down. This is currently
3.1 --- a/tools/python/xen/xend/server/SrvServer.py Tue Mar 27 16:33:26 2007 +0100 3.2 +++ b/tools/python/xen/xend/server/SrvServer.py Tue Mar 27 16:52:56 2007 +0100 3.3 @@ -52,6 +52,7 @@ from xen.xend import XendNode, XendOptio 3.4 from xen.xend import Vifctl 3.5 from xen.xend.XendLogging import log 3.6 from xen.xend.XendClient import XEN_API_SOCKET 3.7 +from xen.xend.XendDomain import instance as xenddomain 3.8 from xen.web.SrvDir import SrvDir 3.9 3.10 from SrvRoot import SrvRoot 3.11 @@ -72,7 +73,7 @@ class XendServers: 3.12 def add(self, server): 3.13 self.servers.append(server) 3.14 3.15 - def cleanup(self, signum = 0, frame = None): 3.16 + def cleanup(self, signum = 0, frame = None, reloading = False): 3.17 log.debug("SrvServer.cleanup()") 3.18 self.cleaningUp = True 3.19 for server in self.servers: 3.20 @@ -80,12 +81,18 @@ class XendServers: 3.21 server.shutdown() 3.22 except: 3.23 pass 3.24 + 3.25 + # clean up domains for those that have on_xend_stop 3.26 + if not reloading: 3.27 + xenddomain().cleanup_domains() 3.28 + 3.29 self.running = False 3.30 + 3.31 3.32 def reloadConfig(self, signum = 0, frame = None): 3.33 log.debug("SrvServer.reloadConfig()") 3.34 self.reloadingConfig = True 3.35 - self.cleanup(signum, frame) 3.36 + self.cleanup(signum, frame, reloading = True) 3.37 3.38 def start(self, status): 3.39 # Running the network script will spawn another process, which takes 3.40 @@ -144,6 +151,12 @@ class XendServers: 3.41 status.close() 3.42 status = None 3.43 3.44 + # Reaching this point means we can auto start domains 3.45 + try: 3.46 + xenddomain().autostart_domains() 3.47 + except Exception, e: 3.48 + log.exception("Failed while autostarting domains") 3.49 + 3.50 # loop to keep main thread alive until it receives a SIGTERM 3.51 self.running = True 3.52 while self.running: