diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/xenmgr/lib/XendDomain.py | 20 | ||||
-rw-r--r-- | tools/xenmgr/lib/XendDomainInfo.py | 47 | ||||
-rwxr-xr-x | tools/xenmgr/lib/server/blkif.py | 28 | ||||
-rwxr-xr-x | tools/xenmgr/lib/server/netif.py | 13 |
4 files changed, 82 insertions, 26 deletions
diff --git a/tools/xenmgr/lib/XendDomain.py b/tools/xenmgr/lib/XendDomain.py index 94afe3e87d..794c1f2931 100644 --- a/tools/xenmgr/lib/XendDomain.py +++ b/tools/xenmgr/lib/XendDomain.py @@ -18,6 +18,9 @@ import XendDomainInfo import XendConsole import EventServer +from xenmgr.server import SrvConsoleServer +xend = SrvConsoleServer.instance() + eserver = EventServer.instance() __all__ = [ "XendDomain" ] @@ -49,15 +52,16 @@ class XendDomain: def initial_refresh(self): """Refresh initial domain info from domain_db. """ - print "initial_refresh> db=", self.domain_db.values() + print "initial_refresh>" + for d in self.domain_db.values(): print 'db dom=', d domlist = xc.domain_getinfo() - print "doms=", domlist + for d in domlist: print 'xc dom=', d doms = {} for d in domlist: domid = str(d['dom']) doms[domid] = d for config in self.domain_db.values(): - domid = int(sxp.child_value(config, 'id')) + domid = str(sxp.child_value(config, 'id')) print "dom=", domid, "config=", config if domid in doms: print "dom=", domid, "new" @@ -141,7 +145,7 @@ class XendDomain: config = None image = None newinfo = XendDomainInfo.XendDomainInfo( - config, d['dom'], d['name'], d['mem_kb']/1024, image) + config, d['dom'], d['name'], d['mem_kb']/1024, image=image, info=d) self._add_domain(newinfo.id, newinfo) # Remove entries for domains that no longer exist. for d in self.domain.values(): @@ -193,13 +197,13 @@ class XendDomain: """ dom = int(id) eserver.inject('xend.domain.start', id) - return xc.domain_start(dom=dom) + return xend.domain_start(dom) def domain_stop(self, id): """Stop domain running. """ dom = int(id) - return xc.domain_stop(dom=dom) + return xend.domain_stop(dom) def domain_shutdown(self, id): """Shutdown domain (nicely). @@ -208,7 +212,7 @@ class XendDomain: if dom <= 0: return 0 eserver.inject('xend.domain.shutdown', id) - val = xc.domain_destroy(dom=dom, force=0) + val = xend.domain_destroy(dom, force=0) self.refresh() return val @@ -219,7 +223,7 @@ class XendDomain: if dom <= 0: return 0 eserver.inject('xend.domain.halt', id) - val = xc.domain_destroy(dom=dom, force=1) + val = xend.domain_destroy(dom, force=1) self.refresh() return val diff --git a/tools/xenmgr/lib/XendDomainInfo.py b/tools/xenmgr/lib/XendDomainInfo.py index 61a9b21c5a..ec9258afd8 100644 --- a/tools/xenmgr/lib/XendDomainInfo.py +++ b/tools/xenmgr/lib/XendDomainInfo.py @@ -59,7 +59,7 @@ class VmError(ValueError): class XendDomainInfo: """Virtual machine object.""" - def __init__(self, config, dom, name, memory, image=None, console=None): + def __init__(self, config, dom, name, memory, image=None, console=None, info=None): """Construct a virtual machine object. config configuration @@ -78,8 +78,10 @@ class XendDomainInfo: self.console = console self.devices = {} self.configs = [] - self.info = None + self.info = info self.ipaddrs = [] + self.block_controller = 0 + self.net_controller = 0 #todo: state: running, suspended self.state = 'running' @@ -111,6 +113,7 @@ class XendDomainInfo: ['name', self.name], ['memory', self.memory] ] if self.info: + print 'info:', self.info run = (self.info['running'] and 'r') or '-' block = (self.info['blocked'] and 'b') or '-' stop = (self.info['stopped'] and 's') or '-' @@ -528,6 +531,18 @@ def vm_create_devices(vm, config): print '<vm_create_devices' return deferred +def config_controllers(vm, config): + for c in sxp.children(config, 'controller'): + name = sxp.name(c) + if name == 'block': + vm.block_controller = 1 + xend.blkif_set_control_domain(vm.dom) + elif name == 'net': + vm.net_controller = 1 + xend.netif_set_control_domain(vm.dom) + else: + raise VmError('invalid controller type:' + str(name)) + def vm_configure(vm, config): """Configure a vm. @@ -536,7 +551,12 @@ def vm_configure(vm, config): returns Deferred - calls callback with vm """ - d = xend.blkif_create(vm.dom) + config_controllers(vm, config) + if vm.block_controller: + d = xend.blkif_create(vm.dom) + else: + d = defer.Deferred() + d.callback(1) d.addCallback(_vm_configure1, vm, config) return d @@ -653,8 +673,11 @@ def vm_dev_vif(vm, val, index): val vif config index vif index """ + if vm.net_controller: + raise VmError('vif: vif in control domain') vif = index #todo vmac = sxp.child_value(val, "mac") + bridge = sxp.child_value(val, "bridge") # todo defer = make_vif(vm.dom, vif, vmac) def fn(id): dev = val + ['vif', vif] @@ -671,6 +694,8 @@ def vm_dev_vbd(vm, val, index): val vbd config index vbd index """ + if vm.block_controller: + raise VmError('vbd: vbd in control domain') uname = sxp.child_value(val, 'uname') if not uname: raise VMError('vbd: Missing uname') @@ -686,6 +711,16 @@ def vm_dev_vbd(vm, val, index): defer.addCallback(fn) return defer +def parse_pci(val): + if isinstance(val, StringType): + radix = 10 + if val.startswith('0x') or val.startswith('0X'): + radix = 16 + v = int(val, radix) + else: + v = val + return v + def vm_dev_pci(vm, val, index): bus = sxp.child_value(val, 'bus') if not bus: @@ -697,9 +732,9 @@ def vm_dev_pci(vm, val, index): if not func: raise VMError('pci: Missing func') try: - bus = int(bus, 16) - dev = int(dev, 16) - func = int(func, 16) + bus = parse_pci(bus) + dev = parse_pci(dev) + func = parse_pci(func) except: raise VMError('pci: invalid parameter') rc = xc.physdev_pci_access_modify(dom=vm.dom, bus=bus, dev=dev, func=func, enable=1) diff --git a/tools/xenmgr/lib/server/blkif.py b/tools/xenmgr/lib/server/blkif.py index ae2736da43..7ffa35179d 100755 --- a/tools/xenmgr/lib/server/blkif.py +++ b/tools/xenmgr/lib/server/blkif.py @@ -34,9 +34,9 @@ class BlkifControllerFactory(controller.ControllerFactory): return d def setControlDomain(self, dom): - if self.channel: - self.deregisterChannel() - self.attached = 0 + if self.dom == dom: return + self.deregisterChannel() + self.attached = 0 self.dom = dom self.registerChannel() # @@ -44,6 +44,9 @@ class BlkifControllerFactory(controller.ControllerFactory): # xend.blkif.recovery = True #xend.blkif.be_port = xend.main.port_from_dom(dom) + def getControlDomain(self): + return self.dom + def recv_be_create(self, msg, req): #print 'recv_be_create>' val = unpackMsg('blkif_be_create_t', msg) @@ -81,15 +84,20 @@ class BlkifControllerFactory(controller.ControllerFactory): blkif = self.getInstanceByDom(dom) if blkif: blkif.reattach_device(vdev) + self.attached = self.devices_attached() + if self.attached: + self.reattached() + + def devices_attached(self): + """Check if all devices are attached. + """ attached = 1 for blkif in self.getInstances(): if not blkif.attached: attached = 0 break - self.attached = attached - if self.attached: - self.reattached() - + return attached + def reattached(self): for blkif in self.getInstances(): blkif.reattached() @@ -149,12 +157,16 @@ class BlkifController(controller.Controller): return self.factory.addDeferred() def detach(self): + """Detach all devices, when the back-end control domain has changed. + """ self.attached = 0 for dev in self.devices.values(): dev.attached = 0 self.send_be_vbd_create(vdev) def reattach_device(self, vdev): + """Reattach a device, when the back-end control domain has changed. + """ dev = self.devices[vdev] dev.attached = 1 attached = 1 @@ -166,6 +178,8 @@ class BlkifController(controller.Controller): return self.attached def reattached(self): + """All devices have been reattached after the back-end control domain has changed. + """ msg = packMsg('blkif_fe_interface_status_changed_t', { 'handle' : 0, 'status' : BLKIF_INTERFACE_STATUS_DISCONNECTED}) diff --git a/tools/xenmgr/lib/server/netif.py b/tools/xenmgr/lib/server/netif.py index 7403054409..13bdd96486 100755 --- a/tools/xenmgr/lib/server/netif.py +++ b/tools/xenmgr/lib/server/netif.py @@ -35,6 +35,7 @@ class NetifControllerFactory(controller.ControllerFactory): def setControlDomain(self, dom): """Set the 'back-end' device driver domain. """ + if self.dom == dom: return self.deregisterChannel() self.attached = 0 self.dom = dom @@ -44,7 +45,9 @@ class NetifControllerFactory(controller.ControllerFactory): # xend.netif.recovery = True # xend.netif.be_port = xend.main.port_from_dom(dom) # - pass + + def getControlDomain(self): + return self.dom def recv_be_create(self, msg, req): self.callDeferred(0) @@ -64,6 +67,8 @@ class NetifControllerFactory(controller.ControllerFactory): val = unpackMsg('netif_be_driver_status_changed_t', msg) status = val['status'] if status == NETIF_DRIVER_STATUS_UP and not self.attached: + # If we are not attached the driver domain was changed, and + # this signals the new driver domain is ready. for netif in self.getInstances(): netif.reattach_devices() self.attached = 1 @@ -149,6 +154,8 @@ class NetifController(controller.Controller): return d def reattach_devices(self): + """Reattach all devices when the back-end control domain has changed. + """ d = self.factory.addDeferred() self.send_be_create(vif) self.attach_fe_devices(0) @@ -182,10 +189,6 @@ class NetifController(controller.Controller): 'rx_shmem_frame' : val['rx_shmem_frame'] }) self.factory.writeRequest(msg) - #def recv_fe_interface_status_changed(self): - # print 'recv_fe_interface_status_changed>' - # pass - def send_interface_connected(self, vif): dev = self.devices[vif] msg = packMsg('netif_fe_interface_status_changed_t', |