aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xen/lib/xend/XendNode.py
blob: 7221785affd23fb90ad4cb59cd48272bd1783ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>

"""Handler for node operations.
 Has some persistent state:
 - logs
 - notification urls

"""

import os
import xen.ext.xc

class XendNode:

    def __init__(self):
        self.xc = xen.ext.xc.new()

    def shutdown(self):
        return 0

    def reboot(self):
        return 0

    def notify(self, uri):
        return 0
    
    def cpu_bvt_slice_set(self, slice):
        ret = 0
        #ret = self.xc.bvtsched_global_set(ctx_allow=slice)
        return ret

    def cpu_bvt_slice_get(self, slice):
        ret = 0
        #ret = self.xc.bvtsched_global_get()
        return ret
    
    def cpu_rrobin_slice_set(self, slice):
        ret = 0
        #ret = self.xc.rrobin_global_set(slice)
        return ret

    def info(self):
        return self.nodeinfo() + self.physinfo()

    def nodeinfo(self):
        (sys, host, rel, ver, mch) = os.uname()
        return [['system',  sys],
                ['host',    host],
                ['release', rel],
                ['version', ver],
                ['machine', mch]]

    def physinfo(self):
        pinfo = self.xc.physinfo()
        info = [['cores', pinfo['cores']],
                ['hyperthreads_per_core', pinfo['ht_per_core']],
                ['cpu_mhz', pinfo['cpu_khz']/1000],
                ['memory', pinfo['total_pages']/256],
                ['free_memory', pinfo['free_pages']/256]]
        return info
        
        

def instance():
    global inst
    try:
        inst
    except:
        inst = XendNode()
    return inst