debuggers.hg

view tools/python/xen/xend/server/blkif.py @ 10959:4c2fab8f8c34

[qemu] Use xenstore to configure ioemu block devices.
- read ioemu block device config from xenstore
- don't require the ioemu: prefix on block devices any longer
- allow change of media associated with cdrom drives
- replace cdrom= option by :cdrom suffix on regular block device config:
'file:/root/mytest.iso,hdc:cdrom,r'
- don't create default cdrom drive anymore - to create default empty
cdrom drive use: ',hdc:cdrom,r'

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Thu Aug 03 18:28:29 2006 +0100 (2006-08-03)
parents 25c6ea6d4024
children 353404fe850c
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, 2005 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 XenSource Ltd
17 #============================================================================
20 import re
21 import string
23 from xen.util import blkif
24 from xen.util import security
25 from xen.xend import sxp
26 from xen.xend.XendError import VmError
28 from xen.xend.server.DevController import DevController
31 class BlkifController(DevController):
32 """Block device interface controller. Handles all block devices
33 for a domain.
34 """
36 def __init__(self, vm):
37 """Create a block device controller.
38 """
39 DevController.__init__(self, vm)
42 def getDeviceDetails(self, config):
43 """@see DevController.getDeviceDetails"""
44 uname = sxp.child_value(config, 'uname')
46 dev = sxp.child_value(config, 'dev')
48 if 'ioemu:' in dev:
49 (_, dev) = string.split(dev, ':', 1)
50 try:
51 (dev, dev_type) = string.split(dev, ':', 1)
52 except ValueError:
53 dev_type = "disk"
55 try:
56 (typ, params) = string.split(uname, ':', 1)
57 except ValueError:
58 (typ, params) = ("", "")
59 back = { 'dev' : dev,
60 'type' : typ,
61 'params' : params,
62 'mode' : sxp.child_value(config, 'mode', 'r')
63 }
65 if security.on():
66 (label, ssidref, policy) = security.get_res_security_details(uname)
67 back.update({'acm_label' : label,
68 'acm_ssidref': str(ssidref),
69 'acm_policy' : policy})
71 devid = blkif.blkdev_name_to_number(dev)
72 front = { 'virtual-device' : "%i" % devid,
73 'device-type' : dev_type
74 }
76 return (devid, back, front)
79 def configuration(self, devid):
80 """@see DevController.configuration"""
82 result = DevController.configuration(self, devid)
84 (dev, typ, params, mode) = self.readBackend(devid,
85 'dev', 'type', 'params',
86 'mode')
88 if dev:
89 result.append(['dev', dev])
90 if typ and params:
91 result.append(['uname', typ + ":" + params])
92 if mode:
93 result.append(['mode', mode])
95 return result
98 def destroyDevice(self, devid):
99 """@see DevController.destroyDevice"""
101 # If we are given a device name, then look up the device ID from it,
102 # and destroy that ID instead. If what we are given is an integer,
103 # then assume it's a device ID and pass it straight through to our
104 # superclass's method.
106 try:
107 DevController.destroyDevice(self, int(devid))
108 except ValueError:
109 devid_end = type(devid) is str and devid.split('/')[-1] or None
111 for i in self.deviceIDs():
112 d = self.readBackend(i, 'dev')
113 if d == devid or (devid_end and d == devid_end):
114 DevController.destroyDevice(self, i)
115 return
116 raise VmError("Device %s not connected" % devid)