aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xen/lib/xend/server/domain.py
blob: ab22234480fdf00d5422c8b2b53e5a407a6a8d77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import channel
import controller
from messages import *

class DomainControllerFactory(controller.ControllerFactory):
    """Factory for creating domain controllers.
    """

    def createInstance(self, dom):
        d = DomainController(self, dom)
        self.addInstance(d)
        return d
    
    def getInstanceByDom(self, dom):
        for inst in self.instances.values():
            if inst.dom == dom:
                return inst
        inst = self.createInstance(dom)
        return inst


class DomainController(controller.Controller):
    """Generic controller for a domain.
    """

    reasons = {'poweroff' : 'shutdown_poweroff_t',
               'reboot'   : 'shutdown_reboot_t',
               'suspend'  : 'shutdown_suspend_t' }

    def __init__(self, factory, dom):
        controller.Controller.__init__(self, factory, dom)
        self.majorTypes = [ CMSG_SHUTDOWN ]
        self.registerChannel()
        print 'DomainController>', self, self.channel, self.idx

    def shutdown(self, reason):
        msgtype = self.reasons.get(reason)
        if not msgtype:
            raise ValueError('invalid reason:' + reason)
        msg = packMsg(msgtype, {})
        self.writeRequest(msg)