ia64/xen-unstable

view tools/python/xen/xend/server/tpmif.py @ 9808:83b092a2cbe6

The attached patch replaces the current numbers identifying the
individual steps of device migration with constants.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Fri Apr 21 11:57:34 2006 +0100 (2006-04-21)
parents 1fe63743a147
children 36e0159c001b
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, live, dst, step, domName):
75 """@see DevContoller.migrate"""
76 if live:
77 tool = xroot.get_external_migration_tool()
78 if tool != '':
79 log.info("Request to live-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, live, dst, step, domName):
103 """@see DevContoller.recover_migrate"""
104 if live:
105 tool = xroot.get_external_migration_tool()
106 if tool != '':
107 log.info("Request to recover live-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