From 365e87562a84abf27bfed2bc8a9e4db3cbe0d7c8 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Fri, 6 Jul 2007 14:34:54 +0100 Subject: Improve xm sched-credit command for inactive managed domains Allows to change the scheduler parameters of inactive managed domains. Signed-off-by: Masaki Kanno --- tools/python/xen/xend/XendDomain.py | 17 ++++++++++++----- tools/python/xen/xm/main.py | 34 ++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index f3a832509c..5820bc566c 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -1399,10 +1399,15 @@ class XendDomain: dominfo = self.domain_lookup_nr(domid) if not dominfo: raise XendInvalidDomain(str(domid)) - try: - return xc.sched_credit_domain_get(dominfo.getDomid()) - except Exception, ex: - raise XendError(str(ex)) + + if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED): + try: + return xc.sched_credit_domain_get(dominfo.getDomid()) + except Exception, ex: + raise XendError(str(ex)) + else: + return {'weight' : dominfo.getWeight(), + 'cap' : dominfo.getCap()} def domain_sched_credit_set(self, domid, weight = None, cap = None): """Set credit scheduler parameters for a domain. @@ -1436,7 +1441,9 @@ class XendDomain: assert type(weight) == int assert type(cap) == int - rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap) + rc = 0 + if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED): + rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap) if rc == 0: if set_weight: dominfo.setWeight(weight) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index 8bc0efe90a..7f93373bd7 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -1529,7 +1529,7 @@ def xm_sched_credit(args): doms = filter(lambda x : domid_match(domid, x), [parse_doms_info(dom) - for dom in getDomains(None, 'running')]) + for dom in getDomains(None, 'all')]) if weight is None and cap is None: if domid is not None and doms == []: @@ -1545,7 +1545,7 @@ def xm_sched_credit(args): server.xenapi.VM.get_metrics( get_single_vm(d['name']))) else: - info = server.xend.domain.sched_credit_get(d['domid']) + info = server.xend.domain.sched_credit_get(d['name']) except xmlrpclib.Fault: pass @@ -1557,8 +1557,8 @@ def xm_sched_credit(args): info['cap'] = int(info['cap']) info['name'] = d['name'] - info['domid'] = int(d['domid']) - print( ("%(name)-32s %(domid)5d %(weight)6d %(cap)4d") % info) + info['domid'] = str(d['domid']) + print( ("%(name)-32s %(domid)5s %(weight)6d %(cap)4d") % info) else: if domid is None: # place holder for system-wide scheduler parameters @@ -1566,14 +1566,24 @@ def xm_sched_credit(args): usage('sched-credit') if serverType == SERVER_XEN_API: - server.xenapi.VM.add_to_VCPUs_params_live( - get_single_vm(domid), - "weight", - weight) - server.xenapi.VM.add_to_VCPUs_params_live( - get_single_vm(domid), - "cap", - cap) + if doms[0]['domid']: + server.xenapi.VM.add_to_VCPUs_params_live( + get_single_vm(domid), + "weight", + weight) + server.xenapi.VM.add_to_VCPUs_params_live( + get_single_vm(domid), + "cap", + cap) + else: + server.xenapi.VM.add_to_VCPUs_params( + get_single_vm(domid), + "weight", + weight) + server.xenapi.VM.add_to_VCPUs_params( + get_single_vm(domid), + "cap", + cap) else: result = server.xend.domain.sched_credit_set(domid, weight, cap) if result != 0: -- cgit v1.2.3