ia64/xen-unstable

changeset 14822:9e9eb5b3dab7

Make xm info more permissive

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Thu Apr 12 11:44:26 2007 +0100 (2007-04-12)
parents dcbfe557e62d
children 4c06bcd83c90
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu Apr 12 11:32:25 2007 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Thu Apr 12 11:44:26 2007 +0100
     1.3 @@ -1544,34 +1544,59 @@ def xm_info(args):
     1.4  
     1.5          host_metrics_record = server.xenapi.host_metrics.get_record(host_record["metrics"])
     1.6  
     1.7 +        def getVal(keys, default=""):
     1.8 +            data = host_record
     1.9 +            for key in keys:
    1.10 +                if key in data:
    1.11 +                    data = data[key]
    1.12 +                else:
    1.13 +                    return default
    1.14 +            return data
    1.15 +
    1.16 +        def getCpuMhz():
    1.17 +            cpu_speeds = [int(host_cpu_record["speed"])
    1.18 +                          for host_cpu_record in host_cpu_records
    1.19 +                          if "speed" in host_cpu_record]
    1.20 +            if len(cpu_speeds) > 0:
    1.21 +                return sum(cpu_speeds) / len(cpu_speeds)
    1.22 +            else:
    1.23 +                return 0
    1.24 +
    1.25 +        getCpuMhz()
    1.26 +
    1.27 +        def getCpuFeatures():
    1.28 +            if len(host_cpu_records) > 0:
    1.29 +                return host_cpu_records[0].get("features", "")
    1.30 +            else:
    1.31 +                return ""
    1.32 +                
    1.33          info = {
    1.34 -            "host":              host_record["name_label"],
    1.35 -            "release":           host_record["software_version"]["release"],
    1.36 -            "version":           host_record["software_version"]["version"],
    1.37 -            "machine":           host_record["software_version"]["machine"],
    1.38 -            "nr_cpus":           len(host_record["host_CPUs"]),
    1.39 -            "nr_nodes":          host_record["cpu_configuration"]["nr_nodes"],
    1.40 -            "sockets_per_node":  host_record["cpu_configuration"]["sockets_per_node"],
    1.41 -            "cores_per_socket":  host_record["cpu_configuration"]["cores_per_socket"],
    1.42 -            "threads_per_core":  host_record["cpu_configuration"]["threads_per_core"],
    1.43 -            "cpu_mhz":           sum([int(host_cpu_record["speed"]) for host_cpu_record in host_cpu_records])
    1.44 -                                   / len(host_cpu_records),
    1.45 -            "hw_caps":           host_cpu_records[0]["features"],
    1.46 +            "host":              getVal(["name_label"]),
    1.47 +            "release":           getVal(["software_version", "release"]),
    1.48 +            "version":           getVal(["software_version", "version"]),
    1.49 +            "machine":           getVal(["software_version", "machine"]),
    1.50 +            "nr_cpus":           len(getVal(["host_CPUs"], [])),
    1.51 +            "nr_nodes":          getVal(["cpu_configuration", "nr_nodes"]),
    1.52 +            "sockets_per_node":  getVal(["cpu_configuration", "sockets_per_node"]),
    1.53 +            "cores_per_socket":  getVal(["cpu_configuration", "cores_per_socket"]),
    1.54 +            "threads_per_core":  getVal(["cpu_configuration", "threads_per_core"]),
    1.55 +            "cpu_mhz":           getCpuMhz(),
    1.56 +            "hw_caps":           getCpuFeatures(),
    1.57              "total_memory":      int(host_metrics_record["memory_total"])/1024/1024,
    1.58              "free_memory":       int(host_metrics_record["memory_free"])/1024/1024,
    1.59 -            "xen_major":         host_record["software_version"]["xen_major"],
    1.60 -            "xen_minor":         host_record["software_version"]["xen_minor"],
    1.61 -            "xen_extra":         host_record["software_version"]["xen_extra"],
    1.62 -            "xen_caps":          " ".join(host_record["capabilities"]),
    1.63 -            "xen_scheduler":     host_record["sched_policy"],
    1.64 -            "xen_pagesize":      host_record["other_config"]["xen_pagesize"],
    1.65 -            "platform_params":   host_record["other_config"]["platform_params"],
    1.66 -            "xen_changeset":     host_record["software_version"]["xen_changeset"],
    1.67 -            "cc_compiler":       host_record["software_version"]["cc_compiler"],
    1.68 -            "cc_compile_by":     host_record["software_version"]["cc_compile_by"],
    1.69 -            "cc_compile_domain": host_record["software_version"]["cc_compile_domain"],
    1.70 -            "cc_compile_date":   host_record["software_version"]["cc_compile_date"],
    1.71 -            "xend_config_format":host_record["software_version"]["xend_config_format"]                                
    1.72 +            "xen_major":         getVal(["software_version", "xen_major"]),
    1.73 +            "xen_minor":         getVal(["software_version", "xen_minor"]),
    1.74 +            "xen_extra":         getVal(["software_version", "xen_extra"]),
    1.75 +            "xen_caps":          " ".join(getVal(["capabilities"], [])),
    1.76 +            "xen_scheduler":     getVal(["sched_policy"]),
    1.77 +            "xen_pagesize":      getVal(["other_config", "xen_pagesize"]),
    1.78 +            "platform_params":   getVal(["other_config", "platform_params"]),
    1.79 +            "xen_changeset":     getVal(["software_version", "xen_changeset"]),
    1.80 +            "cc_compiler":       getVal(["software_version", "cc_compiler"]),
    1.81 +            "cc_compile_by":     getVal(["software_version", "cc_compile_by"]),
    1.82 +            "cc_compile_domain": getVal(["software_version", "cc_compile_domain"]),
    1.83 +            "cc_compile_date":   getVal(["software_version", "cc_compile_date"]),
    1.84 +            "xend_config_format":getVal(["software_version", "xend_config_format"])                                
    1.85          }
    1.86  
    1.87          sorted = info.items()