mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
[XEND] Massive XendDomain XendDomainInfo reorganisation to use XendConfig.
* Added some constants to do with lifecycle management in XendDomain * Added docstrings * Made all private functions prefixed with an underscore (_) * Added lifecycle management in XendDomain which stores configs in SXP format. * Added bits of XenAPI support. * Moved all XendDomainInfo constants to a separate file * Moved most of the domain creation login into XendDomainInfo rather than in module level functions. * Moved to use Xen API compatible reporting of state. * Reorganised methods into logical groups in XendDomain and XendDomainInfo * Moved all domain configuration validation into XendConfig * Removed DevController cruft from the bottom of XendDomainInfo to XendDevices. Signed-off-by: Alastair Tse <atse@xensource.com>
This commit is contained in:
1 parent
9caccb8f48
commit
02ba67937c
6 files changed
+2090
-1371
No files matched your search
+907
-261
File diff suppressed because it is too large.
Load diff
+1097
-1063
File diff suppressed because it is too large.
Load diff
@@ -88,9 +88,9 @@ class DevController:
|
||||
xd = xen.xend.XendDomain.instance()
|
||||
backdom_name = sxp.child_value(config, 'backend')
|
||||
if backdom_name is None:
|
||||
backdom = xen.xend.XendDomain.PRIV_DOMAIN
|
||||
backdom = xen.xend.XendDomain.DOM0_ID
|
||||
else:
|
||||
bd = xd.domain_lookup_by_name_or_id_nr(backdom_name)
|
||||
bd = xd.domain_lookup_nr(backdom_name)
|
||||
backdom = bd.getDomid()
|
||||
count = 0
|
||||
while True:
|
||||
@@ -141,7 +141,6 @@ class DevController:
|
||||
|
||||
def waitForDevices(self):
|
||||
log.debug("Waiting for devices %s.", self.deviceClass)
|
||||
|
||||
return map(self.waitForDevice, self.deviceIDs())
|
||||
|
||||
|
||||
@@ -221,13 +220,15 @@ class DevController:
|
||||
"""@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 = xstransact.Read(self.frontendPath(devid), "backend-id")
|
||||
if backdomid is None:
|
||||
raise VmError("Device %s not connected" % devid)
|
||||
|
||||
return [self.deviceClass, ['backend', int(backdomid)]]
|
||||
|
||||
configDict = self.getDeviceConfiguration(devid)
|
||||
sxpr = [self.deviceClass]
|
||||
for key, val in configDict.items():
|
||||
if type(val) == type(list()):
|
||||
for v in val:
|
||||
sxpr.append([key, v])
|
||||
else:
|
||||
sxpr.append([key, val])
|
||||
return sxpr
|
||||
|
||||
def sxprs(self):
|
||||
"""@return an s-expression describing all the devices of this
|
||||
@@ -243,6 +244,18 @@ class DevController:
|
||||
'id', devid]]
|
||||
|
||||
|
||||
def getDeviceConfiguration(self, devid):
|
||||
"""Returns the configuration of a device.
|
||||
|
||||
@note: Similar to L{configuration} except it returns a dict.
|
||||
@return: dict
|
||||
"""
|
||||
backdomid = xstransact.Read(self.frontendPath(devid), "backend-id")
|
||||
if backdomid is None:
|
||||
raise VmError("Device %s not connected" % devid)
|
||||
|
||||
return {'backend': int(backdomid)}
|
||||
|
||||
## protected:
|
||||
|
||||
def getDeviceDetails(self, config):
|
||||
@@ -387,7 +400,7 @@ class DevController:
|
||||
|
||||
backdom_name = sxp.child_value(config, 'backend')
|
||||
if backdom_name:
|
||||
backdom = xd.domain_lookup_by_name_or_id_nr(backdom_name)
|
||||
backdom = xd.domain_lookup_nr(backdom_name)
|
||||
else:
|
||||
backdom = xd.privilegedDomain()
|
||||
|
||||
@@ -451,9 +464,10 @@ class DevController:
|
||||
|
||||
def backendRoot(self):
|
||||
import xen.xend.XendDomain
|
||||
from xen.xend.xenstore.xsutil import GetDomainPath
|
||||
backdom = xen.xend.XendDomain.PRIV_DOMAIN
|
||||
return "%s/backend/%s/%s" % (GetDomainPath(backdom), self.deviceClass, self.vm.getDomid())
|
||||
from xen.xend.xenstore.xsutil import GetDomainPath
|
||||
backdom = xen.xend.XendDomain.DOM0_ID
|
||||
return "%s/backend/%s/%s" % (GetDomainPath(backdom),
|
||||
self.deviceClass, self.vm.getDomid())
|
||||
|
||||
def frontendMiscPath(self):
|
||||
return "%s/device-misc/%s" % (self.vm.getDomainPath(),
|
||||
|
||||
@@ -39,7 +39,7 @@ class SrvDomainDir(SrvDir):
|
||||
self.xd = XendDomain.instance()
|
||||
|
||||
def domain(self, x):
|
||||
dom = self.xd.domain_lookup_by_name_or_id(x)
|
||||
dom = self.xd.domain_lookup(x)
|
||||
if not dom:
|
||||
raise XendError('No such domain ' + str(x))
|
||||
return SrvDomain(dom)
|
||||
|
||||
@@ -26,13 +26,10 @@ import re
|
||||
|
||||
from xen.xend import sxp
|
||||
from xen.xend import XendRoot
|
||||
|
||||
from xen.xend.server.DevController import DevController
|
||||
|
||||
|
||||
xroot = XendRoot.instance()
|
||||
|
||||
|
||||
def randomMAC():
|
||||
"""Generate a random MAC address.
|
||||
|
||||
@@ -139,7 +136,6 @@ class NetifController(DevController):
|
||||
def __init__(self, vm):
|
||||
DevController.__init__(self, vm)
|
||||
|
||||
|
||||
def getDeviceDetails(self, config):
|
||||
"""@see DevController.getDeviceDetails"""
|
||||
|
||||
@@ -157,6 +153,7 @@ class NetifController(DevController):
|
||||
mac = sxp.child_value(config, 'mac')
|
||||
vifname = sxp.child_value(config, 'vifname')
|
||||
rate = sxp.child_value(config, 'rate')
|
||||
uuid = sxp.child_value(config, 'uuid')
|
||||
ipaddr = _get_config_ipaddr(config)
|
||||
|
||||
devid = self.allocateDeviceID()
|
||||
@@ -182,34 +179,37 @@ class NetifController(DevController):
|
||||
back['vifname'] = vifname
|
||||
if rate:
|
||||
back['rate'] = parseRate(rate)
|
||||
if uuid:
|
||||
back['uuid'] = uuid
|
||||
|
||||
return (devid, back, front)
|
||||
|
||||
|
||||
def configuration(self, devid):
|
||||
def getDeviceConfiguration(self, devid):
|
||||
"""@see DevController.configuration"""
|
||||
|
||||
result = DevController.configuration(self, devid)
|
||||
|
||||
(script, ip, bridge, mac, typ, vifname, rate) = self.readBackend(
|
||||
devid, 'script', 'ip', 'bridge', 'mac', 'type', 'vifname', 'rate')
|
||||
result = DevController.getDeviceConfiguration(self, devid)
|
||||
devinfo = self.readBackend(devid, 'script', 'ip', 'bridge',
|
||||
'mac', 'type', 'vifname', 'rate', 'uuid')
|
||||
(script, ip, bridge, mac, typ, vifname, rate, uuid) = devinfo
|
||||
|
||||
if script:
|
||||
result.append(['script',
|
||||
script.replace(xroot.network_script_dir + os.sep,
|
||||
"")])
|
||||
network_script_dir = xroot.network_script_dir + os.sep
|
||||
result['script'] = script.replace(network_script_dir, "")
|
||||
if ip:
|
||||
for i in ip.split(" "):
|
||||
result.append(['ip', i])
|
||||
result['ip'] = ip.split(" ")
|
||||
if bridge:
|
||||
result.append(['bridge', bridge])
|
||||
result['bridge'] = bridge
|
||||
if mac:
|
||||
result.append(['mac', mac])
|
||||
result['mac'] = mac
|
||||
if typ:
|
||||
result.append(['type', typ])
|
||||
result['type'] = typ
|
||||
if vifname:
|
||||
result.append(['vifname', vifname])
|
||||
result['vifname'] = vifname
|
||||
if rate:
|
||||
result.append(['rate', formatRate(rate)])
|
||||
result['rate'] = formatRate(rate)
|
||||
if uuid:
|
||||
result['uuid'] = uuid
|
||||
|
||||
return result
|
||||
|
||||
@@ -109,30 +109,55 @@ class PciController(DevController):
|
||||
|
||||
return (0, back, {})
|
||||
|
||||
def configuration(self, devid):
|
||||
"""@see DevController.configuration"""
|
||||
|
||||
result = DevController.configuration(self, devid)
|
||||
|
||||
(num_devs) = self.readBackend(devid, 'num_devs')
|
||||
|
||||
def getDeviceConfiguration(self, devid):
|
||||
result = DevController.getDeviceConfiguration(self, devid)
|
||||
num_devs = self.readBackend(devid, 'num_devs')
|
||||
pci_devs = []
|
||||
|
||||
for i in range(int(num_devs)):
|
||||
(dev_config) = self.readBackend(devid, 'dev-%d'%(i))
|
||||
(dev_config,) = self.readBackend(devid, 'dev-%d'%(i))
|
||||
|
||||
pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
|
||||
r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
|
||||
r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
|
||||
r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
|
||||
|
||||
if pci_match!=None:
|
||||
pci_dev_info = pci_match.groupdict('0')
|
||||
result.append( ['dev', \
|
||||
['domain', '0x'+pci_dev_info['domain']], \
|
||||
['bus', '0x'+pci_dev_info['bus']], \
|
||||
['slot', '0x'+pci_dev_info['slot']], \
|
||||
['func', '0x'+pci_dev_info['func']]])
|
||||
pci_devs.append({'domain': '0x%(domain)s' % pci_dev_info,
|
||||
'bus': '0x%(bus)s' % pci_dev_info,
|
||||
'slot': '0x(slot)s' % pci_dev_info,
|
||||
'func': '0x(func)s' % pci_dev_info})
|
||||
|
||||
result['dev'] = pci_devs
|
||||
return result
|
||||
|
||||
def configuration(self, devid):
|
||||
"""Returns SXPR for devices on domain.
|
||||
|
||||
@note: we treat this dict especially to convert to
|
||||
SXP because it is not a straight dict of strings."""
|
||||
|
||||
configDict = self.getDeviceConfiguration(devid)
|
||||
sxpr = [self.deviceClass]
|
||||
|
||||
# remove devs
|
||||
devs = configDict.pop('dev', [])
|
||||
for dev in devs:
|
||||
dev_sxpr = ['dev']
|
||||
for dev_item in dev.items():
|
||||
dev_sxpr.append(list(dev_item))
|
||||
sxpr.append(dev_sxpr)
|
||||
|
||||
for key, val in configDict.items():
|
||||
if type(val) == type(list()):
|
||||
for v in val:
|
||||
sxpr.append([key, v])
|
||||
else:
|
||||
sxpr.append([key, val])
|
||||
|
||||
return sxpr
|
||||
|
||||
def setupDevice(self, domain, bus, slot, func):
|
||||
""" Attach I/O resources for device to frontend domain
|
||||
"""
|
||||
|
||||