mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
Added DevController.configuration and configurations methods. These parse the
store for the current device configuration, and convert it back into the s-expression used in the config files and the save files. This means that we can bring the devices up properly on restore. Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
4bc0323bff
commit
a4db84d76c
3 files changed
+72
-9
No files matched your search
@@ -75,12 +75,28 @@ class DevController:
|
||||
"""
|
||||
|
||||
frontpath = self.frontendPath(devid)
|
||||
backpath = xstransact.Read("%s/backend" % frontpath)
|
||||
backpath = xstransact.Read(frontpath, "backend")
|
||||
|
||||
xstransact.Remove(frontpath)
|
||||
xstransact.Remove(backpath)
|
||||
|
||||
|
||||
def configurations(self):
|
||||
return map(lambda x: self.configuration(int(x)),
|
||||
xstransact.List(self.frontendRoot()))
|
||||
|
||||
|
||||
def configuration(self, devid):
|
||||
"""@return an s-expression giving the current configuration of the
|
||||
specified device. This would be suitable for giving to {@link
|
||||
#createDevice} in order to recreate that device."""
|
||||
|
||||
backdomid = int(xstransact.Read(self.frontendPath(devid),
|
||||
"backend-id"))
|
||||
|
||||
return [self.deviceClass, ['backend', backdomid]]
|
||||
|
||||
|
||||
def sxprs(self):
|
||||
"""@return an s-expression describing all the devices of this
|
||||
controller's device-class.
|
||||
@@ -150,6 +166,12 @@ class DevController:
|
||||
raise
|
||||
|
||||
|
||||
def readBackend(self, devid, *args):
|
||||
frontpath = self.frontendPath(devid)
|
||||
backpath = xstransact.Read(frontpath, "backend")
|
||||
return xstransact.Read(backpath, *args)
|
||||
|
||||
|
||||
## private:
|
||||
|
||||
def writeDetails(self, config, devid, backDetails, frontDetails):
|
||||
@@ -211,4 +233,5 @@ class DevController:
|
||||
|
||||
|
||||
def frontendMiscPath(self):
|
||||
return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass)
|
||||
return "%s/device-misc/%s" % (self.vm.getPath(),
|
||||
self.deviceClass)
|
||||
@@ -40,14 +40,15 @@ class BlkifController(DevController):
|
||||
def getDeviceDetails(self, config):
|
||||
"""@see DevController.getDeviceDetails"""
|
||||
|
||||
typedev = sxp.child_value(config, 'dev')
|
||||
if re.match('^ioemu:', typedev):
|
||||
dev = sxp.child_value(config, 'dev')
|
||||
if re.match('^ioemu:', dev):
|
||||
return (0,{},{})
|
||||
|
||||
devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev'))
|
||||
devid = blkif.blkdev_name_to_number(dev)
|
||||
|
||||
(typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1)
|
||||
back = { 'type' : typ,
|
||||
back = { 'dev' : dev,
|
||||
'type' : typ,
|
||||
'params' : params
|
||||
}
|
||||
|
||||
@@ -57,3 +58,22 @@ class BlkifController(DevController):
|
||||
front = { 'virtual-device' : "%i" % devid }
|
||||
|
||||
return (devid, back, front)
|
||||
|
||||
|
||||
def configuration(self, devid):
|
||||
"""@see DevController.configuration"""
|
||||
|
||||
result = DevController.configuration(self, devid)
|
||||
|
||||
(dev, typ, params, ro) = self.readBackend(devid,
|
||||
'dev', 'type', 'params',
|
||||
'read-only')
|
||||
|
||||
result.append(['dev', dev])
|
||||
result.append(['uname', typ + ":" + params])
|
||||
if ro:
|
||||
result.append(['mode', 'r'])
|
||||
else:
|
||||
result.append(['mode', 'w'])
|
||||
|
||||
return result
|
||||
@@ -23,10 +23,14 @@
|
||||
import os
|
||||
|
||||
from xen.xend import sxp
|
||||
from xen.xend import XendRoot
|
||||
|
||||
from xen.xend.server.DevController import DevController
|
||||
|
||||
|
||||
xroot = XendRoot.instance()
|
||||
|
||||
|
||||
class NetifController(DevController):
|
||||
"""Network interface controller. Handles all network devices for a domain.
|
||||
"""
|
||||
@@ -38,9 +42,6 @@ class NetifController(DevController):
|
||||
def getDeviceDetails(self, config):
|
||||
"""@see DevController.getDeviceDetails"""
|
||||
|
||||
from xen.xend import XendRoot
|
||||
xroot = XendRoot.instance()
|
||||
|
||||
def _get_config_ipaddr(config):
|
||||
val = []
|
||||
for ipaddr in sxp.children(config, elt='ip'):
|
||||
@@ -68,3 +69,22 @@ class NetifController(DevController):
|
||||
'mac' : mac }
|
||||
|
||||
return (devid, back, front)
|
||||
|
||||
|
||||
def configuration(self, devid):
|
||||
"""@see DevController.configuration"""
|
||||
|
||||
result = DevController.configuration(self, devid)
|
||||
|
||||
(script, ip, bridge, mac) = self.readBackend(devid,
|
||||
'script', 'ip', 'bridge',
|
||||
'mac')
|
||||
|
||||
result.append(['script',
|
||||
script.replace(xroot.network_script_dir + os.sep, "")])
|
||||
if ip:
|
||||
result.append(['ip', ip.split(" ")])
|
||||
result.append(['bridge', bridge])
|
||||
result.append(['mac', mac])
|
||||
|
||||
return result
|
||||