aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenmgr/lib/server
diff options
context:
space:
mode:
Diffstat (limited to 'tools/xenmgr/lib/server')
-rw-r--r--tools/xenmgr/lib/server/SrvConsoleServer.py50
-rwxr-xr-xtools/xenmgr/lib/server/blkif.py28
-rwxr-xr-xtools/xenmgr/lib/server/controller.py4
-rw-r--r--tools/xenmgr/lib/server/messages.py28
-rwxr-xr-xtools/xenmgr/lib/server/netif.py13
5 files changed, 108 insertions, 15 deletions
diff --git a/tools/xenmgr/lib/server/SrvConsoleServer.py b/tools/xenmgr/lib/server/SrvConsoleServer.py
index 88f3964811..6059ef2ebf 100644
--- a/tools/xenmgr/lib/server/SrvConsoleServer.py
+++ b/tools/xenmgr/lib/server/SrvConsoleServer.py
@@ -21,6 +21,8 @@ from twisted.internet import protocol
from twisted.internet import abstract
from twisted.internet import defer
+import Xc; xc = Xc.new()
+
import xend.utils
from xenmgr import sxp
@@ -289,6 +291,12 @@ class EventProtocol(protocol.Protocol):
else:
self.send_error()
+ def loseConnection(self):
+ if self.transport:
+ self.transport.loseConnection()
+ if self.connected:
+ reactor.callLater(0, self.connectionLost)
+
def connectionLost(self, reason=None):
self.unsubscribe()
@@ -559,6 +567,16 @@ class Daemon:
reactor.diconnectAll()
sys.exit(0)
+ def blkif_set_control_domain(self, dom):
+ """Set the block device backend control domain.
+ """
+ return self.blkifCF.setControlDomain(dom)
+
+ def blkif_get_control_domain(self, dom):
+ """Get the block device backend control domain.
+ """
+ return self.blkifCF.getControlDomain()
+
def blkif_create(self, dom):
"""Create a block device interface controller.
@@ -579,6 +597,16 @@ class Daemon:
d = ctrl.attach_device(vdev, mode, segment)
return d
+ def netif_set_control_domain(self, dom):
+ """Set the network interface backend control domain.
+ """
+ return self.netifCF.setControlDomain(dom)
+
+ def netif_get_control_domain(self, dom):
+ """Get the network interface backend control domain.
+ """
+ return self.netifCF.getControlDomain()
+
def netif_create(self, dom):
"""Create a network interface controller.
@@ -622,6 +650,28 @@ class Daemon:
if console.conn:
console.conn.loseConnection()
+ def domain_start(self, id):
+ """Start domain running.
+ """
+ dom = int(id)
+ if dom <= 0: return 0
+ return xc.domain_start(dom=dom)
+
+ def domain_stop(self, id):
+ """Stop domain running.
+ """
+ dom = int(id)
+ if dom <= 0: return 0
+ xc.domain_stop(dom=dom)
+
+ def domain_destroy(self, id, force=0):
+ """Destroy a domain. Shutdown if force=0, terminate immediately if force=1.
+ """
+ dom = int(id)
+ if dom <= 0: return 0
+ return xc.domain_destroy(dom=dom, force=force)
+
+
def instance():
global inst
try:
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/controller.py b/tools/xenmgr/lib/server/controller.py
index 793ac85968..23b0f7fde1 100755
--- a/tools/xenmgr/lib/server/controller.py
+++ b/tools/xenmgr/lib/server/controller.py
@@ -37,9 +37,7 @@ class CtrlMsgRcvr:
def registerChannel(self):
self.channel = self.channelFactory.domChannel(self.dom)
- #print 'registerChannel> channel=', self.channel, self
self.idx = self.channel.getIndex()
- #print 'registerChannel> idx=', self.idx
if self.majorTypes:
self.channel.registerDevice(self.majorTypes, self)
@@ -90,7 +88,7 @@ class ControllerFactory(CtrlMsgRcvr):
return None
def delInstance(self, instance):
- if instance in self.instances:
+ if instance.idx in self.instances:
del self.instances[instance.idx]
def createInstance(self, dom):
diff --git a/tools/xenmgr/lib/server/messages.py b/tools/xenmgr/lib/server/messages.py
index f918e5d440..649629105c 100644
--- a/tools/xenmgr/lib/server/messages.py
+++ b/tools/xenmgr/lib/server/messages.py
@@ -142,6 +142,34 @@ netif_formats = {
msg_formats.update(netif_formats)
#============================================================================
+CMSG_SUSPEND = 5
+CMSG_SHUTDOWN = 6
+
+CMSG_SHUTDOWN_HALT = 0
+CMSG_SHUTDOWN_POWEROFF = 1
+CMSG_SHUTDOWN_REBOOT = 2
+
+STOPCODE_shutdown = 0
+STOPCODE_reboot = 1
+STOPCODE_suspend = 2
+
+ctrlif_formats = {
+ 'ctrlif_suspend_t':
+ (CMSG_SUSPEND, 0, "??"),
+
+ 'ctrlif_shutdown_halt_t':
+ (CMSG_SHUTDOWN, CMSG_SHUTDOWN_HALT, "??"),
+
+ 'ctrlif_shutdown_poweroff_t':
+ (CMSG_SHUTDOWN, CMSG_SHUTDOWN_POWEROFF, "??"),
+
+ 'ctrlif_shutdown_reboot_t':
+ (CMSG_SHUTDOWN, CMSG_SHUTDOWN_REBOOT, "??"),
+ }
+
+msg_formats.update(ctrlif_formats)
+
+#============================================================================
class Msg:
pass
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',