ia64/xen-unstable

view tools/python/xen/xend/server/tpmif.py @ 10039:36e0159c001b

This patch adds a boolean parameter 'network' to the save method of the
XendCheckpoint class to differentiate between network suspend/resume
(network=True) and local suspend/resume (network=False).
Instead of passing the 'live' parameter to the migration methods, this
'network' parameter is passed now. This ends up being merely a renaming
of the parameter.
A check with the xm-test suite against this change has resulted in no
additional errors.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 10 16:52:55 2006 +0100 (2006-05-10)
parents 83b092a2cbe6
children 97f3368d1dd3
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 IBM Corporation
17 # Author: Stefan Berger, stefanb@us.ibm.com
18 # Copyright (C) 2005 XenSource Ltd
19 #============================================================================
21 """Support for virtual TPM interfaces.
22 """
24 from xen.xend import sxp
25 from xen.xend.XendLogging import log
26 from xen.xend.XendError import XendError
27 from xen.xend import XendRoot
28 from xen.xend.XendDomainInfo import DEV_MIGRATE_TEST
30 from xen.xend.server.DevController import DevController
32 import os
33 import re
36 xroot = XendRoot.instance()
39 class TPMifController(DevController):
40 """TPM interface controller. Handles all TPM devices for a domain.
41 """
43 def __init__(self, vm):
44 DevController.__init__(self, vm)
47 def getDeviceDetails(self, config):
48 """@see DevController.getDeviceDetails"""
50 devid = self.allocateDeviceID()
51 inst = int(sxp.child_value(config, 'pref_instance', '-1'))
52 if inst == -1:
53 inst = int(sxp.child_value(config, 'instance' , '0'))
55 log.info("The domain has a TPM with instance %d and devid %d.",
56 inst, devid)
57 back = { 'pref_instance' : "%i" % inst,
58 'resume' : "%s" % (self.vm.getResume()) }
59 front = { 'handle' : "%i" % devid }
61 return (devid, back, front)
63 def configuration(self, devid):
65 result = DevController.configuration(self, devid)
67 instance = self.readBackend(devid, 'instance')
69 if instance:
70 result.append(['instance', instance])
72 return result
74 def migrate(self, deviceConfig, network, dst, step, domName):
75 """@see DevContoller.migrate"""
76 if network:
77 tool = xroot.get_external_migration_tool()
78 if tool != '':
79 log.info("Request to network-migrate device to %s. step=%d.",
80 dst, step)
82 if step == DEV_MIGRATE_TEST:
83 """Assuming for now that everything is ok and migration
84 with the given tool can proceed.
85 """
86 return 0
87 else:
88 fd = os.popen("%s -type vtpm -step %d -host %s -domname %s" %
89 (tool, step, dst, domName),
90 'r')
91 for line in fd.readlines():
92 mo = re.search('Error', line)
93 if mo:
94 raise XendError("vtpm: Fatal error in migration step %d: %s" %
95 (step, line))
96 return 0
97 else:
98 log.debug("External migration tool not in configuration.")
99 return -1
100 return 0
102 def recover_migrate(self, deviceConfig, network, dst, step, domName):
103 """@see DevContoller.recover_migrate"""
104 if network:
105 tool = xroot.get_external_migration_tool()
106 if tool != '':
107 log.info("Request to recover network-migrated device. last good step=%d.",
108 step)
109 fd = os.popen("%s -type vtpm -step %d -host %s -domname %s -recover" %
110 (tool, step, dst, domName),
111 'r')
112 return 0