ia64/xen-unstable

changeset 18107:f8221241d187

xend: portability cleanup

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jul 18 14:14:12 2008 +0100 (2008-07-18)
parents f4135a620f59
children 226b04f0f1f9
files tools/python/xen/xend/XendNode.py tools/python/xen/xend/osdep.py
line diff
     1.1 --- a/tools/python/xen/xend/XendNode.py	Fri Jul 18 14:09:14 2008 +0100
     1.2 +++ b/tools/python/xen/xend/XendNode.py	Fri Jul 18 14:14:12 2008 +0100
     1.3 @@ -23,6 +23,7 @@ import xen.lowlevel.xc
     1.4  from xen.util import Brctl
     1.5  from xen.util import pci as PciUtil
     1.6  from xen.xend import XendAPIStore
     1.7 +from xen.xend import osdep
     1.8  
     1.9  import uuid, arch
    1.10  from XendPBD import XendPBD
    1.11 @@ -91,7 +92,7 @@ class XendNode:
    1.12          for cpu_uuid, cpu in saved_cpus.items():
    1.13              self.cpus[cpu_uuid] = cpu
    1.14  
    1.15 -        cpuinfo = parse_proc_cpuinfo()
    1.16 +        cpuinfo = osdep.get_cpuinfo()
    1.17          physinfo = self.physinfo_dict()
    1.18          cpu_count = physinfo['nr_cpus']
    1.19          cpu_features = physinfo['hw_caps']
    1.20 @@ -743,31 +744,6 @@ class XendNode:
    1.21      def info_dict(self):
    1.22          return dict(self.info())
    1.23  
    1.24 -def parse_proc_cpuinfo():
    1.25 -    cpuinfo = {}
    1.26 -    f = file('/proc/cpuinfo', 'r')
    1.27 -    try:
    1.28 -        p = -1
    1.29 -        d = {}
    1.30 -        for line in f:
    1.31 -            keyvalue = line.split(':')
    1.32 -            if len(keyvalue) != 2:
    1.33 -                continue
    1.34 -            key = keyvalue[0].strip()
    1.35 -            val = keyvalue[1].strip()
    1.36 -            if key == 'processor':
    1.37 -                if p != -1:
    1.38 -                    cpuinfo[p] = d
    1.39 -                p = int(val)
    1.40 -                d = {}
    1.41 -            else:
    1.42 -                d[key] = val
    1.43 -        cpuinfo[p] = d
    1.44 -        return cpuinfo
    1.45 -    finally:
    1.46 -        f.close()
    1.47 -
    1.48 -
    1.49  def instance():
    1.50      global inst
    1.51      try:
     2.1 --- a/tools/python/xen/xend/osdep.py	Fri Jul 18 14:09:14 2008 +0100
     2.2 +++ b/tools/python/xen/xend/osdep.py	Fri Jul 18 14:14:12 2008 +0100
     2.3 @@ -87,6 +87,33 @@ def _solaris_balloon_stat(label):
     2.4      "SunOS": _solaris_balloon_stat
     2.5  }
     2.6  
     2.7 +def _linux_get_cpuinfo():
     2.8 +    cpuinfo = {}
     2.9 +    f = file('/proc/cpuinfo', 'r')
    2.10 +    try:    
    2.11 +        p = -1  
    2.12 +        d = {}  
    2.13 +        for line in f:
    2.14 +            keyvalue = line.split(':')
    2.15 +            if len(keyvalue) != 2:
    2.16 +                continue 
    2.17 +            key = keyvalue[0].strip()
    2.18 +            val = keyvalue[1].strip()
    2.19 +            if key == 'processor':
    2.20 +                if p != -1:
    2.21 +                    cpuinfo[p] = d
    2.22 +                p = int(val)
    2.23 +                d = {}
    2.24 +            else:
    2.25 +                d[key] = val
    2.26 +        cpuinfo[p] = d
    2.27 +        return cpuinfo
    2.28 +    finally:
    2.29 +        f.close()
    2.30 +
    2.31 +_get_cpuinfo = {
    2.32 +}
    2.33 +
    2.34  def _get(var, default=None):
    2.35      return var.get(os.uname()[0], default)
    2.36  
    2.37 @@ -95,3 +122,4 @@ xend_autorestart = _get(_xend_autorestar
    2.38  pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
    2.39  vif_script = _get(_vif_script, "vif-bridge")
    2.40  lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)
    2.41 +get_cpuinfo = _get(_get_cpuinfo, _linux_get_cpuinfo)