[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Added Xen-API features needed to implement xm info: host.sched_policy



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1173906178 0
# Node ID 0c354aa0bb4aa66a47729b77d7b16ac27a662d8b
# Parent  460dac5742cf0349f8968f5e9802e27d633f87ac
Added Xen-API features needed to implement xm info: host.sched_policy
(replacing VM.VCPUs_policy, which never made sense), and
host.cpu_configuration.  Add other details into either host.software_version
or host.other_config as appropriate.

Implement xm info and the scheduler-detection check using this.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
Signed-off-by: Tom Wilkie <tom.wilkie@xxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py        |   32 ++++----
 tools/python/xen/xend/XendDomainInfo.py |    9 --
 tools/python/xen/xend/XendNode.py       |   53 ++++++++++++++
 tools/python/xen/xm/main.py             |  115 +++++++++++++++++++++++++-------
 4 files changed, 159 insertions(+), 50 deletions(-)

diff -r 460dac5742cf -r 0c354aa0bb4a tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Wed Mar 14 20:41:56 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Wed Mar 14 21:02:58 2007 +0000
@@ -641,6 +641,7 @@ class XendAPI(object):
     host_attr_ro = ['software_version',
                     'resident_VMs',
                     'host_CPUs',
+                    'cpu_configuration',
                     'metrics',
                     'capabilities',
                     'supported_bootloaders',
@@ -650,6 +651,7 @@ class XendAPI(object):
                     'API_version_vendor_implementation']
     
     host_attr_rw = ['name_label',
+                    'sched_policy',
                     'name_description',
                     'other_config']
 
@@ -712,7 +714,13 @@ class XendAPI(object):
         return xen_api_success(XendNode.instance().get_capabilities())
     def host_get_supported_bootloaders(self, session, host_ref):
         return xen_api_success(['pygrub'])
-
+    def host_get_sched_policy(self, _, host_ref):
+        return xen_api_success(XendNode.instance().get_vcpus_policy())
+    def host_set_sched_policy(self, _, host_ref, policy):
+        return xen_api_todo()
+    def host_get_cpu_configuration(self, _, host_ref):
+        return xen_api_success(XendNode.instance().get_cpu_configuration())
+    
     # object methods
     def host_disable(self, session, host_ref):
         XendDomain.instance().set_allow_new_domains(False)
@@ -747,9 +755,11 @@ class XendAPI(object):
                   'other_config': node.other_config,
                   'resident_VMs': dom.get_domain_refs(),
                   'host_CPUs': node.get_host_cpu_refs(),
+                  'cpu_configuration': node.get_cpu_configuration(),
                   'metrics': node.host_metrics_uuid,
                   'capabilities': node.get_capabilities(),
-                  'supported_bootloaders': 'pygrub'}
+                  'supported_bootloaders': 'pygrub',
+                  'sched_policy': node.get_vcpus_policy()}
         return xen_api_success(record)
 
     # class methods
@@ -771,7 +781,8 @@ class XendAPI(object):
                         'modelname',
                         'stepping',
                         'flags',
-                        'utilisation']
+                        'utilisation',
+                        'features']
 
     # attributes
     def _host_cpu_get(self, ref, field):
@@ -780,6 +791,8 @@ class XendAPI(object):
 
     def host_cpu_get_host(self, _, ref):
         return xen_api_success(XendNode.instance().uuid)
+    def host_cpu_get_features(self, _, ref):
+        return self._host_cpu_get(ref, 'features')
     def host_cpu_get_number(self, _, ref):
         return self._host_cpu_get(ref, 'number')
     def host_cpu_get_vendor(self, _, ref):
@@ -1022,7 +1035,6 @@ class XendAPI(object):
                   'auto_power_on',
                   'memory_dynamic_max',
                   'memory_dynamic_min',
-                  'VCPUs_policy',
                   'VCPUs_params',
                   'actions_after_shutdown',
                   'actions_after_reboot',
@@ -1071,7 +1083,6 @@ class XendAPI(object):
         'memory_dynamic_max',
         'memory_dynamic_min',
         'memory_static_min',
-        'VCPUs_policy',
         'VCPUs_params',
         'actions_after_shutdown',
         'actions_after_reboot',
@@ -1169,11 +1180,7 @@ class XendAPI(object):
 
     def VM_get_memory_dynamic_min(self, session, vm_ref):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
-        return xen_api_success(dom.get_memory_dynamic_min())        
-    
-    def VM_get_VCPUs_policy(self, session, vm_ref):
-        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
-        return xen_api_success(dom.get_vcpus_policy())
+        return xen_api_success(dom.get_memory_dynamic_min())
     
     def VM_get_VCPUs_params(self, session, vm_ref):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
@@ -1261,10 +1268,6 @@ class XendAPI(object):
         return xen_api_todo()
     
     def VM_set_memory_dynamic_min(self, session, vm_ref, mem):
-        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
-        return xen_api_todo()
-    
-    def VM_set_VCPUs_policy(self, session, vm_ref, policy):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
         return xen_api_todo()
     
@@ -1425,7 +1428,6 @@ class XendAPI(object):
             'memory_static_max': xeninfo.get_memory_static_max(),
             'memory_dynamic_min': xeninfo.get_memory_dynamic_min(),
             'memory_dynamic_max': xeninfo.get_memory_dynamic_max(),
-            'VCPUs_policy': xeninfo.get_vcpus_policy(),
             'VCPUs_params': xeninfo.get_vcpus_params(),
             'VCPUs_number': xeninfo.getVCpuCount(),
             'actions_after_shutdown': xeninfo.get_on_shutdown(),
diff -r 460dac5742cf -r 0c354aa0bb4a tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Wed Mar 14 20:41:56 2007 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Mar 14 21:02:58 2007 +0000
@@ -2045,15 +2045,6 @@ class XendDomainInfo:
         return self.info.get('memory_dynamic_max', 0)
     def get_memory_dynamic_min(self):
         return self.info.get('memory_dynamic_min', 0)
-
-    def get_vcpus_policy(self):
-        sched_id = xc.sched_id_get()
-        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
-            return 'sedf'
-        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
-            return 'credit'
-        else:
-            return 'unknown'
     def get_vcpus_params(self):
         if self.getDomid() is None:
             return self.info['vcpus_params']
diff -r 460dac5742cf -r 0c354aa0bb4a tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Wed Mar 14 20:41:56 2007 +0000
+++ b/tools/python/xen/xend/XendNode.py Wed Mar 14 21:02:58 2007 +0000
@@ -75,6 +75,11 @@ class XendNode:
             self.other_config = {}
             self.cpus = {}
             self.host_metrics_uuid = uuid.createString()
+
+        # put some arbitrary params in other_config as this
+        # is directly exposed via XenAPI
+        self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"]
+        self.other_config["platform_params"] = 
self.xeninfo_dict()["platform_params"]
             
         # load CPU UUIDs
         saved_cpus = self.state_store.load_state('cpu')
@@ -353,13 +358,36 @@ class XendNode:
 
     def xen_version(self):
         info = self.xc.xeninfo()
+
         try:
             from xen import VERSION
-            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
+            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
                     'Xend': VERSION}
         except (ImportError, AttributeError):
-            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
+            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
                     'Xend': '3.0.3'}
+
+        # Add xend_config_format
+        info.update(self.xendinfo_dict())
+
+        # Add version info about machine
+        info.update(self.nodeinfo_dict())
+
+        # Add specific xen version info
+        xeninfo_dict = self.xeninfo_dict()
+
+        info.update({
+            "xen_major":         xeninfo_dict["xen_major"],
+            "xen_minor":         xeninfo_dict["xen_minor"],
+            "xen_extra":         xeninfo_dict["xen_extra"],
+            "cc_compiler":       xeninfo_dict["cc_compiler"],
+            "cc_compile_by":     xeninfo_dict["cc_compile_by"],
+            "cc_compile_domain": xeninfo_dict["cc_compile_domain"],
+            "cc_compile_date":   xeninfo_dict["cc_compile_date"],
+            "xen_changeset":     xeninfo_dict["xen_changeset"]
+            })
+        
+        return info
 
     def get_name(self):
         return self.name
@@ -415,6 +443,27 @@ class XendNode:
 
         return 0.0
 
+    def get_vcpus_policy(self):
+        sched_id = self.xc.sched_id_get()
+        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
+            return 'sedf'
+        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
+            return 'credit'
+        else:
+            return 'unknown'
+
+    def get_cpu_configuration(self):
+        phys_info = self.physinfo_dict()
+
+        cpu_info = {
+            "nr_nodes":         phys_info["nr_nodes"],
+            "sockets_per_node": phys_info["sockets_per_node"],
+            "cores_per_socket": phys_info["cores_per_socket"],
+            "threads_per_core": phys_info["threads_per_core"]
+            }
+
+        return cpu_info
+    
     #
     # Network Functions
     #
diff -r 460dac5742cf -r 0c354aa0bb4a tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed Mar 14 20:41:56 2007 +0000
+++ b/tools/python/xen/xm/main.py       Wed Mar 14 21:02:58 2007 +0000
@@ -750,11 +750,14 @@ def parse_doms_info(info):
         }
 
 def check_sched_type(sched):
-    current = 'unknown'
-    for x in server.xend.node.info()[1:]:
-        if len(x) > 1 and x[0] == 'xen_scheduler':
-            current = x[1]
-            break
+    if serverType == SERVER_XEN_API:
+        current = 
server.xenapi.host.get_sched_policy(server.xenapi.session.get_this_host())
+    else:
+        current = 'unknown'
+        for x in server.xend.node.info()[1:]:
+            if len(x) > 1 and x[0] == 'xen_scheduler':
+                current = x[1]
+                break
     if sched != current:
         err("Xen is running with the %s scheduler" % current)
         sys.exit(1)
@@ -1095,28 +1098,43 @@ def xm_mem_max(args):
     arg_check(args, "mem-max", 2)
 
     dom = args[0]
-    mem = int_unit(args[1], 'm')
-
-    server.xend.domain.maxmem_set(dom, mem)
+
+    if serverType == SERVER_XEN_API:
+        mem = int_unit(args[1], 'k') * 1024
+        server.xenapi.VM.set_memory_static_max(get_single_vm(dom), mem)
+    else:
+        mem = int_unit(args[1], 'm')
+        server.xend.domain.maxmem_set(dom, mem)
     
 def xm_mem_set(args):
     arg_check(args, "mem-set", 2)
 
     dom = args[0]
-    mem_target = int_unit(args[1], 'm')
-
-    server.xend.domain.setMemoryTarget(dom, mem_target)
+
+    if serverType == SERVER_XEN_API:
+        mem_target = int_unit(args[1], 'k') * 1024
+        server.xenapi.VM.set_memory_dynamic_max(get_single_vm(dom), mem_target)
+        server.xenapi.VM.set_memory_dynamic_min(get_single_vm(dom), mem_target)
+    else:
+        mem_target = int_unit(args[1], 'm')
+        server.xend.domain.setMemoryTarget(dom, mem_target)
     
 def xm_vcpu_set(args):
     arg_check(args, "vcpu-set", 2)
-    
-    server.xend.domain.setVCpuCount(args[0], int(args[1]))
-
+
+    dom = args[0]
+    vcpus = int(args[1])
+
+    if serverType == SERVER_XEN_API:
+        server.xenapi.VM.set_vcpus_live(get_single_vm(dom), vcpus)
+    else:
+        server.xend.domain.setVCpuCount(dom, vcpus)
 
 def xm_destroy(args):
     arg_check(args, "destroy", 1)
 
     dom = args[0]
+    
     if serverType == SERVER_XEN_API:
         server.xenapi.VM.hard_shutdown(get_single_vm(dom))
     else:
@@ -1135,9 +1153,12 @@ def xm_domname(args):
     arg_check(args, "domname", 1)
 
     name = args[0]
-
-    dom = server.xend.domain(name)
-    print sxp.child_value(dom, 'name')
+    
+    if serverType == SERVER_XEN_API:
+        print server.xenapi.VM.get_domid(get_single_vm(dom))
+    else:
+        dom = server.xend.domain(name)
+        print sxp.child_value(dom, 'name')
 
 def xm_sched_sedf(args):
     def ns_to_ms(val):
@@ -1285,13 +1306,59 @@ def xm_info(args):
 def xm_info(args):
     arg_check(args, "info", 0)
 
-    info = server.xend.node.info()
-    
-    for x in info[1:]:
-        if len(x) < 2: 
-            print "%-23s: (none)" % x[0]
-        else: 
-            print "%-23s:" % x[0], x[1]
+    if serverType == SERVER_XEN_API:
+
+        # Need to fake out old style xm info as people rely on parsing it
+        
+        host_record = server.xenapi.host.get_record(
+            server.xenapi.session.get_this_host())        
+
+        host_cpu_records = map(server.xenapi.host_cpu.get_record, 
host_record["host_CPUs"])
+
+        host_metrics_record = 
server.xenapi.host_metrics.get_record(host_record["metrics"])
+
+        info = {
+            "host":              host_record["name_label"],
+            "release":           host_record["software_version"]["release"],
+            "version":           host_record["software_version"]["version"],
+            "machine":           host_record["software_version"]["machine"],
+            "nr_cpus":           len(host_record["host_CPUs"]),
+            "nr_nodes":          host_record["cpu_configuration"]["nr_nodes"],
+            "sockets_per_node":  
host_record["cpu_configuration"]["sockets_per_node"],
+            "cores_per_socket":  
host_record["cpu_configuration"]["cores_per_socket"],
+            "threads_per_core":  
host_record["cpu_configuration"]["threads_per_core"],
+            "cpu_mhz":           sum([int(host_cpu_record["speed"]) for 
host_cpu_record in host_cpu_records])
+                                   / len(host_cpu_records),
+            "hw_caps":           host_cpu_records[0]["features"],
+            "total_memory":      
int(host_metrics_record["memory_total"])/1024/1024,
+            "free_memory":       
int(host_metrics_record["memory_free"])/1024/1024,
+            "xen_major":         host_record["software_version"]["xen_major"],
+            "xen_minor":         host_record["software_version"]["xen_minor"],
+            "xen_extra":         host_record["software_version"]["xen_extra"],
+            "xen_caps":          " ".join(host_record["capabilities"]),
+            "xen_scheduler":     host_record["sched_policy"],
+            "xen_pagesize":      host_record["other_config"]["xen_pagesize"],
+            "platform_params":   
host_record["other_config"]["platform_params"],
+            "xen_changeset":     
host_record["software_version"]["xen_changeset"],
+            "cc_compiler":       
host_record["software_version"]["cc_compiler"],
+            "cc_compile_by":     
host_record["software_version"]["cc_compile_by"],
+            "cc_compile_domain": 
host_record["software_version"]["cc_compile_domain"],
+            "cc_compile_date":   
host_record["software_version"]["cc_compile_date"],
+            
"xend_config_format":host_record["software_version"]["xend_config_format"]      
                          
+        }
+
+        sorted = info.items()
+        sorted.sort(lambda (x1,y1), (x2,y2): -cmp(x1,x2))
+        
+        for (k, v) in sorted:
+           print "%-23s:" % k, v 
+    else:
+        info = server.xend.node.info()
+        for x in info[1:]:
+            if len(x) < 2: 
+                print "%-23s: (none)" % x[0]
+            else: 
+                print "%-23s:" % x[0], x[1]
 
 def xm_console(args):
     arg_check(args, "console", 1, 2)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.