ia64/xen-unstable

changeset 12848:e98c84468b72

The new lifecycle patches in xen-unstable added 3 new operations which can
be performed on domains - new, start and delete. libvirt has had no-op
stub implementations of these APIs for a while & thus we'd enable their
use for Xen 3.0.4 builds. The new APIs are not currently exposed via the
existing SEXPR protocol, and since the new Xen-API protocol is unsupported
tech-preview for 3.0.4 we don't want to re-write against that just yet.

Thus the attached patch adds the 3 neccessary bindings for the SEXPR protocol
to allow the lifecycle functionality to be invoked. It also allows the 'state'
parameter to be specified when listing domains, so we can explicitly request
inactive domains if we know we're running against a 3.0.4 era XenD

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 07 12:15:30 2006 +0000 (2006-12-07)
parents 78528a88d082
children a330509abb20
files tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py
line diff
     1.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Thu Dec 07 12:14:22 2006 +0000
     1.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Thu Dec 07 12:15:30 2006 +0000
     1.3 @@ -21,6 +21,7 @@ from xen.web import http
     1.4  from xen.xend import sxp
     1.5  from xen.xend import XendDomain
     1.6  from xen.xend.Args import FormFn
     1.7 +from xen.xend.XendLogging import log
     1.8  
     1.9  from xen.web.SrvDir import SrvDir
    1.10  
    1.11 @@ -63,6 +64,18 @@ class SrvDomain(SrvDir):
    1.12          self.acceptCommand(req)
    1.13          return self.dom.shutdown(req.args['reason'][0])
    1.14  
    1.15 +    def op_delete(self, _, req):
    1.16 +        self.acceptCommand(req)
    1.17 +        return self.xd.domain_delete(self.dom.getName())
    1.18 +
    1.19 +    def op_start(self, _, req):
    1.20 +        self.acceptCommand(req)
    1.21 +        paused = False
    1.22 +        if 'paused' in req.args and req.args['paused'] == [1]:
    1.23 +            paused = True
    1.24 +        log.debug("Starting domain " + self.dom.getName() + " " + str(paused))
    1.25 +        return self.xd.domain_start(self.dom.getName(), paused)
    1.26 +
    1.27      def op_sysrq(self, _, req):
    1.28          self.acceptCommand(req)
    1.29          return self.dom.send_sysrq(int(req.args['key'][0]))
     2.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Thu Dec 07 12:14:22 2006 +0000
     2.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Thu Dec 07 12:15:30 2006 +0000
     2.3 @@ -25,6 +25,8 @@ from xen.xend import XendDomain
     2.4  from xen.xend.XendDomainInfo import XendDomainInfo
     2.5  from xen.xend.Args import FormFn
     2.6  from xen.xend.XendError import XendError
     2.7 +from xen.xend.XendLogging import log
     2.8 +from xen.xend.XendConstants import DOM_STATE_RUNNING
     2.9  
    2.10  from xen.web.SrvDir import SrvDir
    2.11  from SrvDomain import SrvDomain
    2.12 @@ -101,6 +103,35 @@ class SrvDomainDir(SrvDir):
    2.13              out.close()
    2.14              return val
    2.15  
    2.16 +    def op_new(self, _, req):
    2.17 +        """Define a new domain.
    2.18 +        Expects the domain config in request parameter 'config' in SXP format.
    2.19 +        """
    2.20 +        ok = 0
    2.21 +        errmsg = ''
    2.22 +        try:
    2.23 +            configstring = req.args.get('config')[0]
    2.24 +            #print 'op_create>', 'config:', configstring
    2.25 +            pin = sxp.Parser()
    2.26 +            pin.input(configstring)
    2.27 +            pin.input_eof()
    2.28 +            config = pin.get_val()
    2.29 +            ok = 1
    2.30 +        except sxp.ParseError, ex:
    2.31 +            errmsg = 'Invalid configuration ' + str(ex)
    2.32 +        except Exception, ex:
    2.33 +            print 'op_create> Exception in config', ex
    2.34 +            traceback.print_exc()
    2.35 +            errmsg = 'Configuration error ' + str(ex)
    2.36 +        if not ok:
    2.37 +            raise XendError(errmsg)
    2.38 +        try:
    2.39 +            self.xd.domain_new(config)
    2.40 +        except Exception, ex:
    2.41 +            print 'op_create> Exception creating domain:'
    2.42 +            traceback.print_exc()
    2.43 +            raise XendError("Error creating domain: " + str(ex))
    2.44 +
    2.45      def op_restore(self, op, req):
    2.46          """Restore a domain from file.
    2.47  
    2.48 @@ -159,7 +190,11 @@ class SrvDomainDir(SrvDir):
    2.49              if detail:
    2.50                  sxp.show(map(XendDomainInfo.sxpr, self.xd.list()), out=req)
    2.51              else:
    2.52 -                sxp.show(self.xd.list_names(), out=req)
    2.53 +                state = DOM_STATE_RUNNING
    2.54 +                if 'state' in req.args and len(req.args['state']) > 0:
    2.55 +                    state = req.args['state'][0]
    2.56 +                log.debug("Listing domains in state " + str(state))
    2.57 +                sxp.show(self.xd.list_names(state), out=req)
    2.58          else:
    2.59              domains = self.xd.list_sorted()
    2.60              req.write('<ul>')