Beispiel #1
0
 def _get_tree (path):
     """ return a dict , parsed from xenstore-ls """
     cmd = "xenstore-ls %s" % (path)
     out = call_cmd (cmd)
     lines = out.split ("\n")
     _static = {
             'node': {},
             'last_key': None,
             'last_value': None,
             'last_space': 0,
     }
     stack = []
     def __process (space, key, value):
         #print _static['last_space'], space, _static['last_key'], _static['last_value'], key, value
         if _static['last_key'] is None:
             _static['last_space'] = 0
         elif _static['last_value'] == "" and _static['last_space'] + 1 == space:
             _static['node'][_static['last_key']] = {} 
             stack.append (_static['node'])
             _static['node'] = _static['node'][_static['last_key']]
         elif _static['last_space'] > space:
             _static['node'][_static['last_key']] = _static['last_value']
             for i in xrange (0, _static['last_space'] - space):
                 _static['node'] = stack.pop ()
         else:
             assert _static['last_space'] == space
             _static['node'][_static['last_key']] = _static['last_value']
         _static['last_key'] = key
         _static['last_value'] = value
         _static['last_space'] = space
         return
             
     reg_key_value = re.compile (r"^(\s*)([\w\-]+)\s*=\s*\"(.*)\".*$")
     for line in lines:
         om = re.match (reg_key_value, line)
         if not om:
             raise Exception ("unexpect format: %s" % (line))
         space = len (om.group (1))
         key = om.group (2)
         value = om.group (3)
         __process (space, key, value)
     __process (0, None, None)
     return _static['node']
Beispiel #2
0
 def destroy (domain):
     call_cmd ("xm destroy %s" % (domain))
Beispiel #3
0
 def shutdown (domain):
     call_cmd ("xm shutdown %s" % (domain))
Beispiel #4
0
 def restore (path):
     call_cmd ("xm restore %s" % (path))
Beispiel #5
0
 def save (domain, path):
     call_cmd ("xm save %s %s" % (domain, path))
Beispiel #6
0
 def create (xen_config):
     if not os.path.exists (xen_config):
         raise Exception ("%s not exist" % (xen_config))
     call_cmd ("xm create %s" % (xen_config))
Beispiel #7
0
 def _read (path):
     return call_cmd ("xenstore-read %s" % (path))
Beispiel #8
0
 def _list (path):
     out = call_cmd ("xenstore-list %s" % (path))
     return out.split ("\n")
Beispiel #9
0
 def mem_total ():
     """ return mem total (MB) in Xen """
     out = call_cmd ("xl info | grep total_memory")
     return int(out.strip("\r\n").split (":")[1].strip ())
Beispiel #10
0
 def mem_free ():
     """ return mem free (MB) in Xen """
     out = call_cmd ("xl info | grep free_memory")
     return int(out.strip("\r\n").split (":")[1].strip ())