ia64/xen-unstable

changeset 1764:b7c469ef6b99

bitkeeper revision 1.1073 (40f3a5f6jsJ9YolZiLVN9CCrudibTg)

Merge xenbk@gandalf:/var/bk/xeno-unstable.bk
into wray-m-3.hpl.hp.com:/home/mjw/repos-bk/xeno-unstable.bk
author mjw@wray-m-3.hpl.hp.com
date Tue Jul 13 09:05:58 2004 +0000 (2004-07-13)
parents b9fc18608f2b 0551cbfadfd8
children 0a953bcc44bb
files tools/python/xen/xend/XendClient.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py
line diff
     1.1 --- a/tools/python/xen/xend/XendClient.py	Tue Jul 13 09:04:27 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendClient.py	Tue Jul 13 09:05:58 2004 +0000
     1.3 @@ -213,12 +213,12 @@ class Xend:
     1.4      def xend_node_cpu_bvt_slice_set(self, ctx_allow):
     1.5          return xend_call(self.nodeurl(),
     1.6                           {'op'      : 'cpu_bvt_slice_set',
     1.7 -                          'ctx_allow'   : ctx_allow })
     1.8 +                          'ctx_allow' : ctx_allow })
     1.9      
    1.10      def xend_node_cpu_fbvt_slice_set(self, ctx_allow):
    1.11          return xend_call(self.nodeurl(),
    1.12                           {'op'      : 'cpu_fbvt_slice_set',
    1.13 -                          'ctx_allow'   : ctx_allow })
    1.14 +                          'ctx_allow' : ctx_allow })
    1.15  
    1.16      def xend_domains(self):
    1.17          return xend_get(self.domainurl())
    1.18 @@ -243,11 +243,11 @@ class Xend:
    1.19  
    1.20      def xend_domain_unpause(self, id):
    1.21          return xend_call(self.domainurl(id),
    1.22 -                         {'op'      : 'unpause'})
    1.23 +                         {'op'      : 'unpause' })
    1.24  
    1.25      def xend_domain_pause(self, id):
    1.26          return xend_call(self.domainurl(id),
    1.27 -                         {'op'      : 'pause'})
    1.28 +                         {'op'      : 'pause' })
    1.29  
    1.30      def xend_domain_shutdown(self, id, reason):
    1.31          return xend_call(self.domainurl(id),
    1.32 @@ -256,22 +256,22 @@ class Xend:
    1.33  
    1.34      def xend_domain_destroy(self, id):
    1.35          return xend_call(self.domainurl(id),
    1.36 -                         {'op'      : 'destroy'})
    1.37 +                         {'op'      : 'destroy' })
    1.38  
    1.39      def xend_domain_save(self, id, filename):
    1.40          return xend_call(self.domainurl(id),
    1.41                           {'op'      : 'save',
    1.42 -                          'file'    : filename})
    1.43 +                          'file'    : filename })
    1.44  
    1.45      def xend_domain_migrate(self, id, dst):
    1.46          return xend_call(self.domainurl(id),
    1.47                           {'op'      : 'migrate',
    1.48 -                          'destination': dst})
    1.49 +                          'destination': dst })
    1.50  
    1.51      def xend_domain_pincpu(self, id, cpu):
    1.52          return xend_call(self.domainurl(id),
    1.53                           {'op'      : 'pincpu',
    1.54 -                          'cpu'     : cpu})
    1.55 +                          'cpu'     : cpu })
    1.56  
    1.57      def xend_domain_cpu_bvt_set(self, id, mcuadv, warp, warpl, warpu):
    1.58          return xend_call(self.domainurl(id),
    1.59 @@ -302,12 +302,11 @@ class Xend:
    1.60          return xend_get(self.domainurl(id),
    1.61                          { 'op'      : 'vifs' })
    1.62      
    1.63 -    def xend_domain_vif_ip_add(self, id, vif, ipaddr):
    1.64 -        return xend_call(self.domainurl(id),
    1.65 -                         {'op'      : 'vif_ip_add',
    1.66 -                          'vif'     : vif,
    1.67 -                          'ip'      : ipaddr })
    1.68 -        
    1.69 +    def xend_domain_vif(self, id, vif):
    1.70 +        return xend_get(self.domainurl(id),
    1.71 +                        { 'op'      : 'vif',
    1.72 +                          'vif'     : vif })
    1.73 +    
    1.74      def xend_domain_vbds(self, id):
    1.75          return xend_get(self.domainurl(id),
    1.76                          {'op'       : 'vbds'})
    1.77 @@ -315,7 +314,7 @@ class Xend:
    1.78      def xend_domain_vbd(self, id, vbd):
    1.79          return xend_get(self.domainurl(id),
    1.80                          {'op'       : 'vbd',
    1.81 -                         'vbd'      : vbd})
    1.82 +                         'vbd'      : vbd })
    1.83  
    1.84      def xend_consoles(self):
    1.85          return xend_get(self.consoleurl())
    1.86 @@ -335,7 +334,7 @@ class Xend:
    1.87  
    1.88      def xend_vnet_delete(self, id):
    1.89          return xend_call(self.vneturl(id),
    1.90 -                         {'op': 'delete'})
    1.91 +                         {'op': 'delete' })
    1.92  
    1.93      def xend_event_inject(self, sxpr):
    1.94          val = xend_call(self.eventurl(),
     2.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Tue Jul 13 09:04:27 2004 +0000
     2.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Tue Jul 13 09:05:58 2004 +0000
     2.3 @@ -1,5 +1,7 @@
     2.4  # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     2.5  
     2.6 +from twisted.protocols import http
     2.7 +
     2.8  from xen.xend import sxp
     2.9  from xen.xend import XendDomain
    2.10  from xen.xend import XendConsole
    2.11 @@ -19,14 +21,17 @@ class SrvDomain(SrvDir):
    2.12          self.xconsole = XendConsole.instance()
    2.13  
    2.14      def op_configure(self, op, req):
    2.15 -        print 'op_configure>', op, req.args
    2.16          fn = FormFn(self.xd.domain_configure,
    2.17                      [['dom', 'int'],
    2.18                       ['config', 'sxpr']])
    2.19 -        val = fn(req.args, {'dom': self.dom.id})
    2.20 -        #todo: may need to add ok and err callbacks.
    2.21 -        return val
    2.22 +        deferred = fn(req.args, {'dom': self.dom.id})
    2.23 +        deferred.addErrback(self._op_configure_err, req)
    2.24 +        return deferred
    2.25  
    2.26 +    def _op_configure_err(self, err, req):
    2.27 +        req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
    2.28 +        return str(err)
    2.29 +        
    2.30      def op_unpause(self, op, req):
    2.31          val = self.xd.domain_unpause(self.dom.id)
    2.32          return val
    2.33 @@ -40,7 +45,7 @@ class SrvDomain(SrvDir):
    2.34                      [['dom', 'int'],
    2.35                       ['reason', 'str']])
    2.36          val = fn(req.args, {'dom': self.dom.id})
    2.37 -        req.setResponseCode(202)
    2.38 +        req.setResponseCode(http.ACCEPTED)
    2.39          req.setHeader("Location", "%s/.." % req.prePathURL())
    2.40          return val
    2.41  
    2.42 @@ -53,19 +58,40 @@ class SrvDomain(SrvDir):
    2.43          fn = FormFn(self.xd.domain_save,
    2.44                      [['dom', 'int'],
    2.45                       ['file', 'str']])
    2.46 -        val = fn(req.args, {'dom': self.dom.id})
    2.47 -        return val
    2.48 +        deferred = fn(req.args, {'dom': self.dom.id})
    2.49 +        deferred.addCallback(self._op_save_cb, req)
    2.50 +        deferred.addErrback(self._op_save_err, req)
    2.51 +        return deferred
    2.52  
    2.53 +    def _op_save_cb(self, val, req):
    2.54 +        return 0
    2.55 +
    2.56 +    def _op_save_err(self, err, req):
    2.57 +        req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
    2.58 +        return str(err)
    2.59 +        
    2.60      def op_migrate(self, op, req):
    2.61          fn = FormFn(self.xd.domain_migrate,
    2.62                      [['dom', 'int'],
    2.63                       ['destination', 'str']])
    2.64 -        val = fn(req.args, {'dom': self.dom.id})
    2.65 -        val = 0 # Some migrate id.
    2.66 -        req.setResponseCode(202)
    2.67 -        #req.send_header("Location", "%s/.." % self.path) # Some migrate url.
    2.68 -        return val
    2.69 +        deferred = fn(req.args, {'dom': self.dom.id})
    2.70 +        deferred.addCallback(self._op_migrate_cb, req)
    2.71 +        deferred.addErrback(self._op_migrate_err, req)
    2.72 +        return deferred
    2.73  
    2.74 +    def _op_migrate_cb(self, info, req):
    2.75 +        #req.setResponseCode(http.ACCEPTED)
    2.76 +        host = info.dst_host
    2.77 +        port = info.dst_port
    2.78 +        dom  = info.dst_dom
    2.79 +        url = "http://%s:%d/xend/domain/%d" % (host, port, dom)
    2.80 +        req.setHeader("Location", url)
    2.81 +        return url
    2.82 +
    2.83 +    def _op_migrate_err(self, err, req):
    2.84 +        req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
    2.85 +        return str(err)
    2.86 +        
    2.87      def op_pincpu(self, op, req):
    2.88          fn = FormFn(self.xd.domain_pincpu,
    2.89                      [['dom', 'int'],
    2.90 @@ -113,40 +139,6 @@ class SrvDomain(SrvDir):
    2.91          val = fn(req.args, {'dom': self.dom.id})
    2.92          return val
    2.93  
    2.94 -    def op_vif_stats(self, op, req):
    2.95 -        #todo
    2.96 -        fn = FormFn(self.xd.domain_vif_stats,
    2.97 -                    [['dom', 'int'],
    2.98 -                     ['vif', 'int']])
    2.99 -        #val = fn(req.args, {'dom': self.dom.id})
   2.100 -        val = 999
   2.101 -        #return val
   2.102 -        return val
   2.103 -
   2.104 -    def op_vif_ip_add(self, op, req):
   2.105 -        fn = FormFn(self.xd.domain_vif_ip_add,
   2.106 -                    [['dom', 'int'],
   2.107 -                     ['vif', 'int'],
   2.108 -                     ['ip', 'str']])
   2.109 -        val = fn(req.args, {'dom': self.dom.id})
   2.110 -        return val
   2.111 -
   2.112 -    def op_vif_scheduler_set(self, op, req):
   2.113 -        fn = FormFn(self.xd.domain_vif_scheduler_set,
   2.114 -                    [['dom', 'int'],
   2.115 -                     ['vif', 'int'],
   2.116 -                     ['bytes', 'int'],
   2.117 -                     ['usecs', 'int']])
   2.118 -        val = fn(req.args, {'dom': self.dom.id})
   2.119 -        return val
   2.120 -
   2.121 -    def op_vif_scheduler_get(self, op, req):
   2.122 -        fn = FormFn(self.xd.domain_vif_scheduler_set,
   2.123 -                    [['dom', 'int'],
   2.124 -                     ['vif', 'int']])
   2.125 -        val = fn(req.args, {'dom': self.dom.id})
   2.126 -        return val
   2.127 -
   2.128      def op_vbds(self, op, req):
   2.129          return self.xd.domain_vbd_ls(self.dom.id)
   2.130  
   2.131 @@ -178,7 +170,7 @@ class SrvDomain(SrvDir):
   2.132          
   2.133      def render_GET(self, req):
   2.134          op = req.args.get('op')
   2.135 -        if op and op[0] in ['vifs', 'vif', 'vif_stats', 'vbds', 'vbd']:
   2.136 +        if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd']:
   2.137              return self.perform(req)
   2.138          if self.use_sxp(req):
   2.139              req.setHeader("Content-Type", sxp.mime_type)
   2.140 @@ -200,32 +192,31 @@ class SrvDomain(SrvDir):
   2.141                  req.write("<code><pre>")
   2.142                  PrettyPrint.prettyprint(self.dom.config, out=req)
   2.143                  req.write("</pre></code>")
   2.144 -            req.write('<a href="%s?op=vif_stats&vif=0">vif 0 stats</a>'
   2.145 -                      % req.prePathURL())
   2.146              self.form(req)
   2.147              req.write('</body></html>')
   2.148          return ''
   2.149  
   2.150      def form(self, req):
   2.151 -        req.write('<form method="post" action="%s">' % req.prePathURL())
   2.152 +        url = req.prePathURL()
   2.153 +        req.write('<form method="post" action="%s">' % url)
   2.154          req.write('<input type="submit" name="op" value="unpause">')
   2.155          req.write('<input type="submit" name="op" value="pause">')
   2.156          req.write('<input type="submit" name="op" value="destroy">')
   2.157          req.write('</form>')
   2.158  
   2.159 -        req.write('<form method="post" action="%s">' % req.prePathURL())
   2.160 +        req.write('<form method="post" action="%s">' % url)
   2.161          req.write('<input type="submit" name="op" value="shutdown">')
   2.162 -        req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff<br>')
   2.163 -        req.write('<input type="radio" name="reason" value="halt">Halt<br>')
   2.164 -        req.write('<input type="radio" name="reason" value="reboot">Reboot<br>')
   2.165 +        req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
   2.166 +        req.write('<input type="radio" name="reason" value="halt">Halt')
   2.167 +        req.write('<input type="radio" name="reason" value="reboot">Reboot')
   2.168          req.write('</form>')
   2.169          
   2.170 -        req.write('<form method="post" action="%s">' % req.prePathURL())
   2.171 +        req.write('<form method="post" action="%s">' % url)
   2.172          req.write('<br><input type="submit" name="op" value="save">')
   2.173 -        req.write('To file: <input type="text" name="file">')
   2.174 +        req.write(' To file: <input type="text" name="file">')
   2.175          req.write('</form>')
   2.176          
   2.177 -        req.write('<form method="post" action="%s">' % req.prePathURL())
   2.178 +        req.write('<form method="post" action="%s">' % url)
   2.179          req.write('<br><input type="submit" name="op" value="migrate">')
   2.180 -        req.write('To host: <input type="text" name="destination">')
   2.181 +        req.write(' To host: <input type="text" name="destination">')
   2.182          req.write('</form>')
     3.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Tue Jul 13 09:04:27 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Tue Jul 13 09:05:58 2004 +0000
     3.3 @@ -81,7 +81,7 @@ class SrvDomainDir(SrvDir):
     3.4          """
     3.5          dom = dominfo.id
     3.6          domurl = "%s/%s" % (req.prePathURL(), dom)
     3.7 -        req.setResponseCode(201, "created")
     3.8 +        req.setResponseCode(http.CREATED, "created")
     3.9          req.setHeader("Location", domurl)
    3.10          if self.use_sxp(req):
    3.11              return dominfo.sxpr()
    3.12 @@ -111,8 +111,30 @@ class SrvDomainDir(SrvDir):
    3.13          #todo: return is deferred. May need ok and err callbacks.
    3.14          fn = FormFn(self.xd.domain_restore,
    3.15                      [['file', 'str']])
    3.16 -        val = fn(req.args)
    3.17 -        return val
    3.18 +        deferred = fn(req.args)
    3.19 +        deferred.addCallback(self._op_restore_cb, req)
    3.20 +        deferred.addErrback(self._op_restore_err, req)
    3.21 +        return deferred
    3.22 +
    3.23 +    def _op_restore_cb(self, dominfo, req):
    3.24 +        dom = dominfo.id
    3.25 +        domurl = "%s/%s" % (req.prePathURL(), dom)
    3.26 +        req.setResponseCode(http.CREATED)
    3.27 +        req.setHeader("Location", domurl)
    3.28 +        if self.use_sxp(req):
    3.29 +            return dominfo.sxpr()
    3.30 +        else:
    3.31 +            out = StringIO()
    3.32 +            print >> out, ('<p> Created <a href="%s">Domain %s</a></p>'
    3.33 +                           % (domurl, dom))
    3.34 +            val = out.getvalue()
    3.35 +            out.close()
    3.36 +            return val
    3.37 +
    3.38 +    def _op_restore_err(self, err, req):
    3.39 +        print 'op_create> Deferred Exception restoring domain:', err
    3.40 +        req.setResponseCode(http.BAD_REQUEST, "Error restoring domain: "+ str(err))
    3.41 +        return str(err)
    3.42          
    3.43      def render_POST(self, req):
    3.44          return self.perform(req)