direct-io.hg

changeset 14380:0c354aa0bb4a

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@xensource.com>
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Mar 14 21:02:58 2007 +0000 (2007-03-14)
parents 460dac5742cf
children 036e42d1c9bb
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendNode.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Wed Mar 14 20:41:56 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Wed Mar 14 21:02:58 2007 +0000
     1.3 @@ -641,6 +641,7 @@ class XendAPI(object):
     1.4      host_attr_ro = ['software_version',
     1.5                      'resident_VMs',
     1.6                      'host_CPUs',
     1.7 +                    'cpu_configuration',
     1.8                      'metrics',
     1.9                      'capabilities',
    1.10                      'supported_bootloaders',
    1.11 @@ -650,6 +651,7 @@ class XendAPI(object):
    1.12                      'API_version_vendor_implementation']
    1.13      
    1.14      host_attr_rw = ['name_label',
    1.15 +                    'sched_policy',
    1.16                      'name_description',
    1.17                      'other_config']
    1.18  
    1.19 @@ -712,7 +714,13 @@ class XendAPI(object):
    1.20          return xen_api_success(XendNode.instance().get_capabilities())
    1.21      def host_get_supported_bootloaders(self, session, host_ref):
    1.22          return xen_api_success(['pygrub'])
    1.23 -
    1.24 +    def host_get_sched_policy(self, _, host_ref):
    1.25 +        return xen_api_success(XendNode.instance().get_vcpus_policy())
    1.26 +    def host_set_sched_policy(self, _, host_ref, policy):
    1.27 +        return xen_api_todo()
    1.28 +    def host_get_cpu_configuration(self, _, host_ref):
    1.29 +        return xen_api_success(XendNode.instance().get_cpu_configuration())
    1.30 +    
    1.31      # object methods
    1.32      def host_disable(self, session, host_ref):
    1.33          XendDomain.instance().set_allow_new_domains(False)
    1.34 @@ -747,9 +755,11 @@ class XendAPI(object):
    1.35                    'other_config': node.other_config,
    1.36                    'resident_VMs': dom.get_domain_refs(),
    1.37                    'host_CPUs': node.get_host_cpu_refs(),
    1.38 +                  'cpu_configuration': node.get_cpu_configuration(),
    1.39                    'metrics': node.host_metrics_uuid,
    1.40                    'capabilities': node.get_capabilities(),
    1.41 -                  'supported_bootloaders': 'pygrub'}
    1.42 +                  'supported_bootloaders': 'pygrub',
    1.43 +                  'sched_policy': node.get_vcpus_policy()}
    1.44          return xen_api_success(record)
    1.45  
    1.46      # class methods
    1.47 @@ -771,7 +781,8 @@ class XendAPI(object):
    1.48                          'modelname',
    1.49                          'stepping',
    1.50                          'flags',
    1.51 -                        'utilisation']
    1.52 +                        'utilisation',
    1.53 +                        'features']
    1.54  
    1.55      # attributes
    1.56      def _host_cpu_get(self, ref, field):
    1.57 @@ -780,6 +791,8 @@ class XendAPI(object):
    1.58  
    1.59      def host_cpu_get_host(self, _, ref):
    1.60          return xen_api_success(XendNode.instance().uuid)
    1.61 +    def host_cpu_get_features(self, _, ref):
    1.62 +        return self._host_cpu_get(ref, 'features')
    1.63      def host_cpu_get_number(self, _, ref):
    1.64          return self._host_cpu_get(ref, 'number')
    1.65      def host_cpu_get_vendor(self, _, ref):
    1.66 @@ -1022,7 +1035,6 @@ class XendAPI(object):
    1.67                    'auto_power_on',
    1.68                    'memory_dynamic_max',
    1.69                    'memory_dynamic_min',
    1.70 -                  'VCPUs_policy',
    1.71                    'VCPUs_params',
    1.72                    'actions_after_shutdown',
    1.73                    'actions_after_reboot',
    1.74 @@ -1071,7 +1083,6 @@ class XendAPI(object):
    1.75          'memory_dynamic_max',
    1.76          'memory_dynamic_min',
    1.77          'memory_static_min',
    1.78 -        'VCPUs_policy',
    1.79          'VCPUs_params',
    1.80          'actions_after_shutdown',
    1.81          'actions_after_reboot',
    1.82 @@ -1169,11 +1180,7 @@ class XendAPI(object):
    1.83  
    1.84      def VM_get_memory_dynamic_min(self, session, vm_ref):
    1.85          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
    1.86 -        return xen_api_success(dom.get_memory_dynamic_min())        
    1.87 -    
    1.88 -    def VM_get_VCPUs_policy(self, session, vm_ref):
    1.89 -        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
    1.90 -        return xen_api_success(dom.get_vcpus_policy())
    1.91 +        return xen_api_success(dom.get_memory_dynamic_min())
    1.92      
    1.93      def VM_get_VCPUs_params(self, session, vm_ref):
    1.94          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
    1.95 @@ -1264,10 +1271,6 @@ class XendAPI(object):
    1.96          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
    1.97          return xen_api_todo()
    1.98      
    1.99 -    def VM_set_VCPUs_policy(self, session, vm_ref, policy):
   1.100 -        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
   1.101 -        return xen_api_todo()
   1.102 -    
   1.103      def VM_set_VCPUs_params(self, session, vm_ref, value):
   1.104          return self.VM_set('vcpus_params', session, vm_ref, value)
   1.105  
   1.106 @@ -1425,7 +1428,6 @@ class XendAPI(object):
   1.107              'memory_static_max': xeninfo.get_memory_static_max(),
   1.108              'memory_dynamic_min': xeninfo.get_memory_dynamic_min(),
   1.109              'memory_dynamic_max': xeninfo.get_memory_dynamic_max(),
   1.110 -            'VCPUs_policy': xeninfo.get_vcpus_policy(),
   1.111              'VCPUs_params': xeninfo.get_vcpus_params(),
   1.112              'VCPUs_number': xeninfo.getVCpuCount(),
   1.113              'actions_after_shutdown': xeninfo.get_on_shutdown(),
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Mar 14 20:41:56 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Mar 14 21:02:58 2007 +0000
     2.3 @@ -2045,15 +2045,6 @@ class XendDomainInfo:
     2.4          return self.info.get('memory_dynamic_max', 0)
     2.5      def get_memory_dynamic_min(self):
     2.6          return self.info.get('memory_dynamic_min', 0)
     2.7 -
     2.8 -    def get_vcpus_policy(self):
     2.9 -        sched_id = xc.sched_id_get()
    2.10 -        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
    2.11 -            return 'sedf'
    2.12 -        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
    2.13 -            return 'credit'
    2.14 -        else:
    2.15 -            return 'unknown'
    2.16      def get_vcpus_params(self):
    2.17          if self.getDomid() is None:
    2.18              return self.info['vcpus_params']
     3.1 --- a/tools/python/xen/xend/XendNode.py	Wed Mar 14 20:41:56 2007 +0000
     3.2 +++ b/tools/python/xen/xend/XendNode.py	Wed Mar 14 21:02:58 2007 +0000
     3.3 @@ -75,6 +75,11 @@ class XendNode:
     3.4              self.other_config = {}
     3.5              self.cpus = {}
     3.6              self.host_metrics_uuid = uuid.createString()
     3.7 +
     3.8 +        # put some arbitrary params in other_config as this
     3.9 +        # is directly exposed via XenAPI
    3.10 +        self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"]
    3.11 +        self.other_config["platform_params"] = self.xeninfo_dict()["platform_params"]
    3.12              
    3.13          # load CPU UUIDs
    3.14          saved_cpus = self.state_store.load_state('cpu')
    3.15 @@ -353,14 +358,37 @@ class XendNode:
    3.16  
    3.17      def xen_version(self):
    3.18          info = self.xc.xeninfo()
    3.19 +
    3.20          try:
    3.21              from xen import VERSION
    3.22 -            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
    3.23 +            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
    3.24                      'Xend': VERSION}
    3.25          except (ImportError, AttributeError):
    3.26 -            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
    3.27 +            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
    3.28                      'Xend': '3.0.3'}
    3.29  
    3.30 +        # Add xend_config_format
    3.31 +        info.update(self.xendinfo_dict())
    3.32 +
    3.33 +        # Add version info about machine
    3.34 +        info.update(self.nodeinfo_dict())
    3.35 +
    3.36 +        # Add specific xen version info
    3.37 +        xeninfo_dict = self.xeninfo_dict()
    3.38 +
    3.39 +        info.update({
    3.40 +            "xen_major":         xeninfo_dict["xen_major"],
    3.41 +            "xen_minor":         xeninfo_dict["xen_minor"],
    3.42 +            "xen_extra":         xeninfo_dict["xen_extra"],
    3.43 +            "cc_compiler":       xeninfo_dict["cc_compiler"],
    3.44 +            "cc_compile_by":     xeninfo_dict["cc_compile_by"],
    3.45 +            "cc_compile_domain": xeninfo_dict["cc_compile_domain"],
    3.46 +            "cc_compile_date":   xeninfo_dict["cc_compile_date"],
    3.47 +            "xen_changeset":     xeninfo_dict["xen_changeset"]
    3.48 +            })
    3.49 +        
    3.50 +        return info
    3.51 +
    3.52      def get_name(self):
    3.53          return self.name
    3.54  
    3.55 @@ -415,6 +443,27 @@ class XendNode:
    3.56  
    3.57          return 0.0
    3.58  
    3.59 +    def get_vcpus_policy(self):
    3.60 +        sched_id = self.xc.sched_id_get()
    3.61 +        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
    3.62 +            return 'sedf'
    3.63 +        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
    3.64 +            return 'credit'
    3.65 +        else:
    3.66 +            return 'unknown'
    3.67 +
    3.68 +    def get_cpu_configuration(self):
    3.69 +        phys_info = self.physinfo_dict()
    3.70 +
    3.71 +        cpu_info = {
    3.72 +            "nr_nodes":         phys_info["nr_nodes"],
    3.73 +            "sockets_per_node": phys_info["sockets_per_node"],
    3.74 +            "cores_per_socket": phys_info["cores_per_socket"],
    3.75 +            "threads_per_core": phys_info["threads_per_core"]
    3.76 +            }
    3.77 +
    3.78 +        return cpu_info
    3.79 +    
    3.80      #
    3.81      # Network Functions
    3.82      #
     4.1 --- a/tools/python/xen/xm/main.py	Wed Mar 14 20:41:56 2007 +0000
     4.2 +++ b/tools/python/xen/xm/main.py	Wed Mar 14 21:02:58 2007 +0000
     4.3 @@ -750,11 +750,14 @@ def parse_doms_info(info):
     4.4          }
     4.5  
     4.6  def check_sched_type(sched):
     4.7 -    current = 'unknown'
     4.8 -    for x in server.xend.node.info()[1:]:
     4.9 -        if len(x) > 1 and x[0] == 'xen_scheduler':
    4.10 -            current = x[1]
    4.11 -            break
    4.12 +    if serverType == SERVER_XEN_API:
    4.13 +        current = server.xenapi.host.get_sched_policy(server.xenapi.session.get_this_host())
    4.14 +    else:
    4.15 +        current = 'unknown'
    4.16 +        for x in server.xend.node.info()[1:]:
    4.17 +            if len(x) > 1 and x[0] == 'xen_scheduler':
    4.18 +                current = x[1]
    4.19 +                break
    4.20      if sched != current:
    4.21          err("Xen is running with the %s scheduler" % current)
    4.22          sys.exit(1)
    4.23 @@ -1095,28 +1098,43 @@ def xm_mem_max(args):
    4.24      arg_check(args, "mem-max", 2)
    4.25  
    4.26      dom = args[0]
    4.27 -    mem = int_unit(args[1], 'm')
    4.28  
    4.29 -    server.xend.domain.maxmem_set(dom, mem)
    4.30 +    if serverType == SERVER_XEN_API:
    4.31 +        mem = int_unit(args[1], 'k') * 1024
    4.32 +        server.xenapi.VM.set_memory_static_max(get_single_vm(dom), mem)
    4.33 +    else:
    4.34 +        mem = int_unit(args[1], 'm')
    4.35 +        server.xend.domain.maxmem_set(dom, mem)
    4.36      
    4.37  def xm_mem_set(args):
    4.38      arg_check(args, "mem-set", 2)
    4.39  
    4.40      dom = args[0]
    4.41 -    mem_target = int_unit(args[1], 'm')
    4.42  
    4.43 -    server.xend.domain.setMemoryTarget(dom, mem_target)
    4.44 +    if serverType == SERVER_XEN_API:
    4.45 +        mem_target = int_unit(args[1], 'k') * 1024
    4.46 +        server.xenapi.VM.set_memory_dynamic_max(get_single_vm(dom), mem_target)
    4.47 +        server.xenapi.VM.set_memory_dynamic_min(get_single_vm(dom), mem_target)
    4.48 +    else:
    4.49 +        mem_target = int_unit(args[1], 'm')
    4.50 +        server.xend.domain.setMemoryTarget(dom, mem_target)
    4.51      
    4.52  def xm_vcpu_set(args):
    4.53      arg_check(args, "vcpu-set", 2)
    4.54 -    
    4.55 -    server.xend.domain.setVCpuCount(args[0], int(args[1]))
    4.56 +
    4.57 +    dom = args[0]
    4.58 +    vcpus = int(args[1])
    4.59  
    4.60 +    if serverType == SERVER_XEN_API:
    4.61 +        server.xenapi.VM.set_vcpus_live(get_single_vm(dom), vcpus)
    4.62 +    else:
    4.63 +        server.xend.domain.setVCpuCount(dom, vcpus)
    4.64  
    4.65  def xm_destroy(args):
    4.66      arg_check(args, "destroy", 1)
    4.67  
    4.68      dom = args[0]
    4.69 +    
    4.70      if serverType == SERVER_XEN_API:
    4.71          server.xenapi.VM.hard_shutdown(get_single_vm(dom))
    4.72      else:
    4.73 @@ -1135,9 +1153,12 @@ def xm_domname(args):
    4.74      arg_check(args, "domname", 1)
    4.75  
    4.76      name = args[0]
    4.77 -
    4.78 -    dom = server.xend.domain(name)
    4.79 -    print sxp.child_value(dom, 'name')
    4.80 +    
    4.81 +    if serverType == SERVER_XEN_API:
    4.82 +        print server.xenapi.VM.get_domid(get_single_vm(dom))
    4.83 +    else:
    4.84 +        dom = server.xend.domain(name)
    4.85 +        print sxp.child_value(dom, 'name')
    4.86  
    4.87  def xm_sched_sedf(args):
    4.88      def ns_to_ms(val):
    4.89 @@ -1285,13 +1306,59 @@ def xm_sched_credit(args):
    4.90  def xm_info(args):
    4.91      arg_check(args, "info", 0)
    4.92  
    4.93 -    info = server.xend.node.info()
    4.94 -    
    4.95 -    for x in info[1:]:
    4.96 -        if len(x) < 2: 
    4.97 -            print "%-23s: (none)" % x[0]
    4.98 -        else: 
    4.99 -            print "%-23s:" % x[0], x[1]
   4.100 +    if serverType == SERVER_XEN_API:
   4.101 +
   4.102 +        # Need to fake out old style xm info as people rely on parsing it
   4.103 +        
   4.104 +        host_record = server.xenapi.host.get_record(
   4.105 +            server.xenapi.session.get_this_host())        
   4.106 +
   4.107 +        host_cpu_records = map(server.xenapi.host_cpu.get_record, host_record["host_CPUs"])
   4.108 +
   4.109 +        host_metrics_record = server.xenapi.host_metrics.get_record(host_record["metrics"])
   4.110 +
   4.111 +        info = {
   4.112 +            "host":              host_record["name_label"],
   4.113 +            "release":           host_record["software_version"]["release"],
   4.114 +            "version":           host_record["software_version"]["version"],
   4.115 +            "machine":           host_record["software_version"]["machine"],
   4.116 +            "nr_cpus":           len(host_record["host_CPUs"]),
   4.117 +            "nr_nodes":          host_record["cpu_configuration"]["nr_nodes"],
   4.118 +            "sockets_per_node":  host_record["cpu_configuration"]["sockets_per_node"],
   4.119 +            "cores_per_socket":  host_record["cpu_configuration"]["cores_per_socket"],
   4.120 +            "threads_per_core":  host_record["cpu_configuration"]["threads_per_core"],
   4.121 +            "cpu_mhz":           sum([int(host_cpu_record["speed"]) for host_cpu_record in host_cpu_records])
   4.122 +                                   / len(host_cpu_records),
   4.123 +            "hw_caps":           host_cpu_records[0]["features"],
   4.124 +            "total_memory":      int(host_metrics_record["memory_total"])/1024/1024,
   4.125 +            "free_memory":       int(host_metrics_record["memory_free"])/1024/1024,
   4.126 +            "xen_major":         host_record["software_version"]["xen_major"],
   4.127 +            "xen_minor":         host_record["software_version"]["xen_minor"],
   4.128 +            "xen_extra":         host_record["software_version"]["xen_extra"],
   4.129 +            "xen_caps":          " ".join(host_record["capabilities"]),
   4.130 +            "xen_scheduler":     host_record["sched_policy"],
   4.131 +            "xen_pagesize":      host_record["other_config"]["xen_pagesize"],
   4.132 +            "platform_params":   host_record["other_config"]["platform_params"],
   4.133 +            "xen_changeset":     host_record["software_version"]["xen_changeset"],
   4.134 +            "cc_compiler":       host_record["software_version"]["cc_compiler"],
   4.135 +            "cc_compile_by":     host_record["software_version"]["cc_compile_by"],
   4.136 +            "cc_compile_domain": host_record["software_version"]["cc_compile_domain"],
   4.137 +            "cc_compile_date":   host_record["software_version"]["cc_compile_date"],
   4.138 +            "xend_config_format":host_record["software_version"]["xend_config_format"]                                
   4.139 +        }
   4.140 +
   4.141 +        sorted = info.items()
   4.142 +        sorted.sort(lambda (x1,y1), (x2,y2): -cmp(x1,x2))
   4.143 +        
   4.144 +        for (k, v) in sorted:
   4.145 +           print "%-23s:" % k, v 
   4.146 +    else:
   4.147 +        info = server.xend.node.info()
   4.148 +        for x in info[1:]:
   4.149 +            if len(x) < 2: 
   4.150 +                print "%-23s: (none)" % x[0]
   4.151 +            else: 
   4.152 +                print "%-23s:" % x[0], x[1]
   4.153  
   4.154  def xm_console(args):
   4.155      arg_check(args, "console", 1, 2)