James (song wei)
2010-Jun-25 05:56 UTC
[Xen-devel] [PATCH] add a command to get the state of VMs
add a command "domstate" to get the state of Vms, which may have one state of {''shutoff'', ''idle'',''shutdown'',''running'',''crashed'',''paused'' or ''paused by admin"}. For case of pause, I distinguish it into two conditions. One is "paused" the other is "paused by admin". "pasued by admin" means that users pause a domain voluntary by "xm paused VM" or " API" -James (Song Wei) Signed-off-by James (Song Wei) <jsong@novell.com> diff -r 007de86b27e7 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Thu Jun 03 16:10:37 2010 +0800 +++ b/tools/python/xen/xend/XendDomain.py Mon Jun 21 11:41:15 2010 +0800 @@ -251,6 +251,18 @@ @return: path to config file. """ return os.path.join(self._managed_path(domuuid), CACHED_CONFIG_FILE) + def domain_setpauseflag(self, dom, flag=False): + try: + dominfo = self.domain_lookup_nr(dom) + dominfo.paused_by_admin = flag + except Exception, err: + log.debug("error in in setpauseflag") + def domain_getpauseflag(self, dom): + try: + dominfo = self.domain_lookup_nr(dom) + return dominfo.paused_by_admin + except Exception, err: + log.debug("error in in getpauseflag") def _managed_check_point_path(self, domuuid): """Returns absolute path to check point file for managed domain. diff -r 007de86b27e7 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Jun 03 16:10:37 2010 +0800 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Jun 21 11:41:15 2010 +0800 @@ -329,6 +329,8 @@ @type info: dictionary @ivar domid: Domain ID (if VM has started) @type domid: int or None + @ivar paused_by_admin: Is this Domain paused by command or API + @type paused_by_admin: bool @ivar guest_bitsize: the bitsize of guest @type guest_bitsize: int or None @ivar alloc_mem: the memory domain allocated when booting @@ -392,6 +394,7 @@ self.domid = domid self.guest_bitsize = None self.alloc_mem = None + self.paused_by_admin = False maxmem = self.info.get(''memory_static_max'', 0) memory = self.info.get(''memory_dynamic_max'', 0) diff -r 007de86b27e7 tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Thu Jun 03 16:10:37 2010 +0800 +++ b/tools/python/xen/xend/server/SrvDomain.py Mon Jun 21 11:41:15 2010 +0800 @@ -249,6 +249,20 @@ def op_reset(self, _, req): self.acceptCommand(req) return self.xd.domain_reset(self.dom.getName()) + + def op_do_get_pauseflag(self, op, req): + self.acceptCommand(req) + return req.threadRequest(self.do_get_pauseflag, op, req) + + def do_get_pauseflag(self, _, req): + return self.xd.domain_getpauseflag(self.dom.getName(), req) + + def op_do_set_pauseflag(self, op, req): + self.acceptCommand(req) + return req.threadRequest(self.do_set_pauseflag, op, req) + + def do_set_pauseflag(self, _, req): + return self.xd.domain_setpauseflag(self.dom.getName(), req) def op_usb_add(self, op, req): self.acceptCommand(req) diff -r 007de86b27e7 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Thu Jun 03 16:10:37 2010 +0800 +++ b/tools/python/xen/xm/main.py Mon Jun 21 11:41:15 2010 +0800 @@ -174,6 +174,8 @@ #usb ''usb-add'' : (''<domain> <[host:bus.addr] [host:vendor_id:product_id]>'',''Add the usb device to FV VM.''), ''usb-del'' : (''<domain> <[host:bus.addr] [host:vendor_id:product_id]>'',''Delete the usb device to FV VM.''), + #domstate + ''domstate'' : (''<domain> '', ''get the state of a domain''), # device commands @@ -409,6 +411,7 @@ "uptime", "usb-add", "usb-del", + "domstate", "vcpu-set", ] @@ -447,6 +450,7 @@ "uptime", "usb-add", "usb-del", + "domstate", "vcpu-list", "vcpu-pin", "vcpu-set", @@ -1018,7 +1022,6 @@ return "-" state_str = "".join([state_on_off(state) for state in states]) - dom_rec.update({''name'': dom_rec[''name_label''], ''memory_actual'': int(dom_metrics_rec[''memory_actual''])/1024, ''vcpus'': dom_metrics_rec[''VCPUs_number''], @@ -1527,8 +1530,10 @@ if serverType == SERVER_XEN_API: server.xenapi.VM.pause(get_single_vm(dom)) + server.xenapi.VM.set_pauseflag(get_single_vm(dom), True) else: server.xend.domain.pause(dom) + server.xend.domain.setpauseflag(dom, True) def xm_unpause(args): arg_check(args, "unpause", 1) @@ -1536,8 +1541,10 @@ if serverType == SERVER_XEN_API: server.xenapi.VM.unpause(get_single_vm(dom)) + server.xenapi.VM.set_pauseflag(get_single_vm(dom), False) else: server.xend.domain.unpause(dom) + server.xend.domain.setpauseflag(dom, False) def xm_dump_core(args): live = False @@ -1647,6 +1654,32 @@ arg_check(args, "usb-add", 2) server.xend.domain.usb_add(args[0],args[1]) +def xm_domstate(args): + arg_check(args, "domstate", 1) + (opitons, params) = getopt.gnu_getopt(args, ''s'', [''domname='']) + doms = getDomains(params, ''all'') + d = parse_doms_info(doms[0]) + state = d[''state''] + if state: + if state.find(''s'') > 0: + print ''shutoff'' + elif state.find(''b'') > 0: + print ''idle'' + elif state.find(''d'') > 0: + print ''shutdown'' + elif state.find(''r'') > 0: + print ''running'' + elif state.find(''c'') > 0: + print ''crashed'' + elif state.find(''p'') > 0: + if server.xend.domain.getpauseflag(args[0]): + print ''paused by admin'' + else: + print ''paused'' + else: + print ''shutoff'' + return + def xm_usb_del(args): arg_check(args, "usb-del", 2) server.xend.domain.usb_del(args[0],args[1]) @@ -3857,6 +3890,8 @@ #usb "usb-add": xm_usb_add, "usb-del": xm_usb_del, + #domstate + "domstate": xm_domstate, } ## The commands supported by a separate argument parser in xend.xm. -- View this message in context: http://old.nabble.com/-PATCH--add-a-command-to-get-the-state-of-VMs-tp28989229p28989229.html Sent from the Xen - Dev mailing list archive at Nabble.com. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Jun-25 14:19 UTC
Re: [Xen-devel] [PATCH] add a command to get the state of VMs
James (song wei) writes ("[Xen-devel] [PATCH] add a command to get the state of VMs"):> add a command "domstate" to get the state of Vms, which may have one state of > {''shutoff'', ''idle'',''shutdown'',''running'',''crashed'',''paused'' or ''paused by > admin"}.I''m going to apply this patch, but: That you wrote this patch suggests that you''re using the xend "managed domains" feature. This feature is not supported by the new xl/libxl tools, and the current plans are to phase out xend. Xend will still be in 4.1 but will very likely not be the default toolstack in 4.1. Personally at some point I hope it will be removed; it''s unreliable and unmaintainable. So you may want to consider a migration path away from xend "managed domains". The xl toolstack supports the init.d-based machinery for automatically saving and restoring domains on dom0 reboot; if you need a more heavyweight approach then XCP may be more to your liking. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Jun-25 14:21 UTC
Re: [Xen-devel] [PATCH] add a command to get the state of VMs
I wrote:> James (song wei) writes ("[Xen-devel] [PATCH] add a command to get the state of VMs"): > > add a command "domstate" to get the state of Vms, which may have one state of > > {''shutoff'', ''idle'',''shutdown'',''running'',''crashed'',''paused'' or ''paused by > > admin"}. > > I''m going to apply this patch, but:I''m afraid that the patch has been mangled by your email client; it has been wordwrapped. Can you submit it again, please ? If you can''t manage to stop your email program mangling it, try sending it as an attachment (although if you do this please send a copy in the body of the message too as otherwise it can be hard for people to review it). Thanks, Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
James Song
2010-Jun-29 03:04 UTC
Re: [Xen-devel] [PATCH] add a command to get the state of VMs
>>> Ian Jackson <Ian.Jackson@eu.citrix.com> 2010-6-25 22:19 >>>James (song wei) writes ("[Xen-devel] [PATCH] add a command to get the state of VMs"):> add a command "domstate" to get the state of Vms, which may have one state of > {''shutoff'', ''idle'',''shutdown'',''running'',''crashed'',''paused'' or ''paused by > admin"}.I''m going to apply this patch, but: That you wrote this patch suggests that you''re using the xend "managed domains" feature. This feature is not supported by the new xl/libxl tools, and the current plans are to phase out xend. Xend will still be in 4.1 but will very likely not be the default toolstack in 4.1. Personally at some point I hope it will be removed; it''s unreliable and unmaintainable. -Sorry for replying late. By now, xl/libxl only contain part of function xm/xend. What the release date of 4.1 and would xl/libxl be enhanced in it? So you may want to consider a migration path away from xend "managed domains". The xl toolstack supports the init.d-based machinery for automatically saving and restoring domains on dom0 reboot; - Yeah, I could get the status of VMs from Hypervisor by hypercall. I would implement it in xl/libxl. if you need a more heavyweight approach then XCP may be more to your liking. -I am looking at it. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
James Song
2010-Jun-29 03:11 UTC
Re: [Xen-devel] [PATCH] add a command to get the state of VMs
sorry, Ian, I resend the patch and attach it here. thank you very much! Signed-off-by: James (Song Wei) <jsong@novell.com> diff -r b622e411eef8 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Thu Jun 24 21:56:03 2010 +0100 +++ b/tools/python/xen/xend/XendDomain.py Tue Jun 29 11:06:56 2010 +0800 @@ -250,6 +250,18 @@ @return: path to config file. """ return os.path.join(self._managed_path(domuuid), CACHED_CONFIG_FILE) + def domain_setpauseflag(self, dom, flag=False): + try: + dominfo = self.domain_lookup_nr(dom) + dominfo.paused_by_admin = flag + except Exception, err: + log.debug("error in in setpauseflag") + def domain_getpauseflag(self, dom): + try: + dominfo = self.domain_lookup_nr(dom) + return dominfo.paused_by_admin + except Exception, err: + log.debug("error in in getpauseflag") def _managed_check_point_path(self, domuuid): """Returns absolute path to check point file for managed domain. diff -r b622e411eef8 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Jun 24 21:56:03 2010 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Tue Jun 29 11:06:56 2010 +0800 @@ -329,6 +329,8 @@ @type info: dictionary @ivar domid: Domain ID (if VM has started) @type domid: int or None + @ivar paused_by_admin: Is this Domain paused by command or API + @type paused_by_admin: bool @ivar guest_bitsize: the bitsize of guest @type guest_bitsize: int or None @ivar alloc_mem: the memory domain allocated when booting @@ -392,6 +394,7 @@ self.domid = domid self.guest_bitsize = None self.alloc_mem = None + self.paused_by_admin = False maxmem = self.info.get(''memory_static_max'', 0) memory = self.info.get(''memory_dynamic_max'', 0) diff -r b622e411eef8 tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Thu Jun 24 21:56:03 2010 +0100 +++ b/tools/python/xen/xend/server/SrvDomain.py Tue Jun 29 11:06:56 2010 +0800 @@ -238,6 +238,20 @@ def op_reset(self, _, req): self.acceptCommand(req) return self.xd.domain_reset(self.dom.getName()) + + def op_do_get_pauseflag(self, op, req): + self.acceptCommand(req) + return req.threadRequest(self.do_get_pauseflag, op, req) + + def do_get_pauseflag(self, _, req): + return self.xd.domain_getpauseflag(self.dom.getName(), req) + + def op_do_set_pauseflag(self, op, req): + self.acceptCommand(req) + return req.threadRequest(self.do_set_pauseflag, op, req) + + def do_set_pauseflag(self, _, req): + return self.xd.domain_setpauseflag(self.dom.getName(), req) def op_usb_add(self, op, req): self.acceptCommand(req) diff -r b622e411eef8 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Thu Jun 24 21:56:03 2010 +0100 +++ b/tools/python/xen/xm/main.py Tue Jun 29 11:06:56 2010 +0800 @@ -169,6 +169,8 @@ #usb ''usb-add'' : (''<domain> <[host:bus.addr] [host:vendor_id:product_id]>'',''Add the usb device to FV VM.''), ''usb-del'' : (''<domain> <[host:bus.addr] [host:vendor_id:product_id]>'',''Delete the usb device to FV VM.''), + #domstate + ''domstate'' : (''<domain> '', ''get the state of a domain''), # device commands @@ -401,6 +403,7 @@ "uptime", "usb-add", "usb-del", + "domstate", "vcpu-set", ] @@ -435,6 +438,7 @@ "uptime", "usb-add", "usb-del", + "domstate", "vcpu-list", "vcpu-pin", "vcpu-set", @@ -948,7 +952,6 @@ return "-" state_str = "".join([state_on_off(state) for state in states]) - dom_rec.update({''name'': dom_rec[''name_label''], ''memory_actual'': int(dom_metrics_rec[''memory_actual''])/1024, ''vcpus'': dom_metrics_rec[''VCPUs_number''], @@ -1457,8 +1460,10 @@ if serverType == SERVER_XEN_API: server.xenapi.VM.pause(get_single_vm(dom)) + server.xenapi.VM.set_pauseflag(get_single_vm(dom), True) else: server.xend.domain.pause(dom) + server.xend.domain.setpauseflag(dom, True) def xm_unpause(args): arg_check(args, "unpause", 1) @@ -1466,8 +1471,10 @@ if serverType == SERVER_XEN_API: server.xenapi.VM.unpause(get_single_vm(dom)) + server.xenapi.VM.set_pauseflag(get_single_vm(dom), False) else: server.xend.domain.unpause(dom) + server.xend.domain.setpauseflag(dom, False) def xm_dump_core(args): live = False @@ -1579,6 +1586,32 @@ arg_check(args, "usb-add", 2) server.xend.domain.usb_add(args[0],args[1]) +def xm_domstate(args): + arg_check(args, "domstate", 1) + (opitons, params) = getopt.gnu_getopt(args, ''s'', [''domname='']) + doms = getDomains(params, ''all'') + d = parse_doms_info(doms[0]) + state = d[''state''] + if state: + if state.find(''s'') > 0: + print ''shutoff'' + elif state.find(''b'') > 0: + print ''idle'' + elif state.find(''d'') > 0: + print ''shutdown'' + elif state.find(''r'') > 0: + print ''running'' + elif state.find(''c'') > 0: + print ''crashed'' + elif state.find(''p'') > 0: + if server.xend.domain.getpauseflag(args[0]): + print ''paused by admin'' + else: + print ''paused'' + else: + print ''shutoff'' + return + def xm_usb_del(args): arg_check(args, "usb-del", 2) server.xend.domain.usb_del(args[0],args[1]) @@ -3861,6 +3894,8 @@ #usb "usb-add": xm_usb_add, "usb-del": xm_usb_del, + #domstate + "domstate": xm_domstate, } ## The commands supported by a separate argument parser in xend.xm.>>> Ian Jackson <Ian.Jackson@eu.citrix.com> 2010-6-25 22:21 >>>I wrote:> James (song wei) writes ("[Xen-devel] [PATCH] add a command to get the state of VMs"): > > add a command "domstate" to get the state of Vms, which may have one state of > > {''shutoff'', ''idle'',''shutdown'',''running'',''crashed'',''paused'' or ''paused by > > admin"}. > > I''m going to apply this patch, but:I''m afraid that the patch has been mangled by your email client; it has been wordwrapped. Can you submit it again, please ? If you can''t manage to stop your email program mangling it, try sending it as an attachment (although if you do this please send a copy in the body of the message too as otherwise it can be hard for people to review it). Thanks, Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Jun-29 13:50 UTC
Re: [Xen-devel] [PATCH] add a command to get the state of VMs
James Song writes ("Re: [Xen-devel] [PATCH] add a command to get the state of VMs"):> Sorry for replying late. By now, xl/libxl only contain part of > function xm/xend. What the release date of 4.1 and would xl/libxl be > enhanced in it?We don''t have a firm schedule for 4.1 but Keir will have a clearer idea of the general plan. Certainly libxl should be feature-complete by then - indeed it very nearly is already. Which functionality of xm that you use is currently missing from xl ? NB that the "managed domains" facility in xend is not being replaced directly with equivalent functionality in xl. However, the startup/shutdown scripts (which now work with xl as well as xm) provide address many of the same needs.> > So you may want to consider a migration path away from xend "managed > > domains". The xl toolstack supports the init.d-based machinery for > > automatically saving and restoring domains on dom0 reboot; > > Yeah, I could get the status of VMs from Hypervisor by hypercall. I > would implement it in xl/libxl.I''m not sure exactly what you mean. "Managed domains" as provided by xend are not always present in the hypervisor, so you can''t query their status by hypercall. We do not intend to replicate this feature directly in libxl. I hope this is all helpful and informative. Regards, Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel