ia64/xen-unstable

changeset 1788:61599b006364

bitkeeper revision 1.1086 (40f5687be0DDpSYX0TNiliScPeVkTA)

Merge ssh://xenbk@gandalf.hpl.hp.com//var/bk/xeno-unstable.bk
into labyrinth.cl.cam.ac.uk:/auto/anfs/scratch/labyrinth/iap10/xeno-clone/xeno.bk
author iap10@labyrinth.cl.cam.ac.uk
date Wed Jul 14 17:08:11 2004 +0000 (2004-07-14)
parents 002fc84add90 9c6eeedea833
children 91ce6ba4ab3e 565101380290 f48ee6e94073
files .rootkeys tools/examples/xmdefaults tools/examples/xmnetbsd tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendConsole.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/console.py tools/python/xen/xm/create.py tools/python/xen/xm/destroy.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/.rootkeys	Wed Jul 14 16:41:41 2004 +0000
     1.2 +++ b/.rootkeys	Wed Jul 14 17:08:11 2004 +0000
     1.3 @@ -368,6 +368,7 @@ 40c9c469ZqILEQ8x6yWy0_51jopiCg tools/pyt
     1.4  40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py
     1.5  40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py
     1.6  40cf2937gKQcATgXKGtNeWb1PDH5nA tools/python/xen/xm/create.py
     1.7 +40f552eariuUSB9TWqCPnDLz5zvxMw tools/python/xen/xm/destroy.py
     1.8  40e41cd2w0I4En6qrJn4em8HkK_oxQ tools/python/xen/xm/help.py
     1.9  40cf2937isyS250zyd0Q2GuEDoNXfQ tools/python/xen/xm/main.py
    1.10  40cf2937PSslwBliN1g7ofDy2H_RhA tools/python/xen/xm/opts.py
     2.1 --- a/tools/examples/xmdefaults	Wed Jul 14 16:41:41 2004 +0000
     2.2 +++ b/tools/examples/xmdefaults	Wed Jul 14 17:08:11 2004 +0000
     2.3 @@ -91,8 +91,11 @@ root = "/dev/sda1 ro"
     2.4  extra = "4 VMID=%d usr=/dev/sda6" % vmid
     2.5  
     2.6  #----------------------------------------------------------------------------
     2.7 -# Set according to whether you want the domain  restarted when it exits.
     2.8 -# The default is False.
     2.9 -#autorestart = True
    2.10 +# Set according to whether you want the domain restarted when it exits.
    2.11 +# The default is 'onreboot', which restarts the domain when it shuts down
    2.12 +# with exit code reboot.
    2.13 +# Other values are 'always', and 'never'.
    2.14 +
    2.15 +#restart = 'onreboot'
    2.16  
    2.17  #============================================================================
     3.1 --- a/tools/examples/xmnetbsd	Wed Jul 14 16:41:41 2004 +0000
     3.2 +++ b/tools/examples/xmnetbsd	Wed Jul 14 17:08:11 2004 +0000
     3.3 @@ -94,8 +94,10 @@ extra = "4 VMID=%d bootdev=xennet0" % vm
     3.4  
     3.5  
     3.6  #----------------------------------------------------------------------------
     3.7 -# Set according to whether you want the domain  restarted when it exits.
     3.8 -# The default is False.
     3.9 -#autorestart = True
    3.10 -
    3.11 +# Set according to whether you want the domain restarted when it exits.
    3.12 +# The default is 'onreboot', which restarts the domain when it shuts down
    3.13 +# with exit code reboot.
    3.14 +# Other values are 'always', and 'never'.
    3.15 +#
    3.16 +#restart = 'onreboot'
    3.17  #============================================================================
     4.1 --- a/tools/python/xen/xend/XendClient.py	Wed Jul 14 16:41:41 2004 +0000
     4.2 +++ b/tools/python/xen/xend/XendClient.py	Wed Jul 14 17:08:11 2004 +0000
     4.3 @@ -256,9 +256,10 @@ class Xend:
     4.4                           {'op'      : 'shutdown',
     4.5                            'reason'  : reason })
     4.6  
     4.7 -    def xend_domain_destroy(self, id):
     4.8 +    def xend_domain_destroy(self, id, reason):
     4.9          return xend_call(self.domainurl(id),
    4.10 -                         {'op'      : 'destroy' })
    4.11 +                         {'op'      : 'destroy',
    4.12 +                          'reason'  : reason })
    4.13  
    4.14      def xend_domain_save(self, id, filename):
    4.15          return xend_call(self.domainurl(id),
     5.1 --- a/tools/python/xen/xend/XendConsole.py	Wed Jul 14 16:41:41 2004 +0000
     5.2 +++ b/tools/python/xen/xend/XendConsole.py	Wed Jul 14 17:08:11 2004 +0000
     5.3 @@ -154,8 +154,8 @@ class XendConsole:
     5.4          self.refresh()
     5.5          return self.console.values()
     5.6      
     5.7 -    def console_create(self, dom):
     5.8 -        consinfo = daemon.console_create(dom)
     5.9 +    def console_create(self, dom, console_port=None):
    5.10 +        consinfo = daemon.console_create(dom, console_port=console_port)
    5.11          info = self._new_console(consinfo)
    5.12          return info
    5.13      
     6.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Jul 14 16:41:41 2004 +0000
     6.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Jul 14 17:08:11 2004 +0000
     6.3 @@ -378,9 +378,9 @@ class XendDomain:
     6.4      
     6.5      def domain_shutdown(self, id, reason='poweroff'):
     6.6          """Shutdown domain (nicely).
     6.7 -         - poweroff: domain will restart if has autorestart set.
     6.8 -         - reboot: domain will restart.
     6.9 -         - halt: domain will not restart (even if has autorestart set).
    6.10 +         - poweroff: restart according to exit code and restart mode
    6.11 +         - reboot:   restart on exit
    6.12 +         - halt:     do not restart
    6.13  
    6.14           Returns immediately.
    6.15  
    6.16 @@ -388,12 +388,13 @@ class XendDomain:
    6.17          @param reason: shutdown type: poweroff, reboot, suspend, halt
    6.18          """
    6.19          dom = int(id)
    6.20 +        id = str(id)
    6.21          if dom <= 0:
    6.22              return 0
    6.23          if reason == 'halt':
    6.24              self.domain_restart_cancel(id)
    6.25          else:
    6.26 -            self.domain_restart_schedule(id, reason)
    6.27 +            self.domain_restart_schedule(id, reason, set=1)
    6.28          eserver.inject('xend.domain.shutdown', [id, reason])
    6.29          if reason == 'halt':
    6.30              reason = 'poweroff'
    6.31 @@ -401,21 +402,24 @@ class XendDomain:
    6.32          self.refresh_schedule()
    6.33          return val
    6.34  
    6.35 -    def domain_restart_schedule(self, id, reason):
    6.36 +    def domain_restart_schedule(self, id, reason, set=0):
    6.37          """Schedule a restart for a domain if it needs one.
    6.38  
    6.39          @param id:     domain id
    6.40          @param reason: shutdown reason
    6.41          """
    6.42 +        print 'domain_restart_schedule>', id, reason, set
    6.43          dominfo = self.domain.get(id)
    6.44 -        if not dominfo or id in self.restarts:
    6.45 -            # Don't schedule if unknown or already there.
    6.46 +        if not dominfo:
    6.47 +            return
    6.48 +        if id in self.restarts:
    6.49              return
    6.50 -        restart = ((reason == 'reboot') or
    6.51 -                   (reason == 'poweroff' and dominfo.autorestart))
    6.52 +        if set and reason == 'reboot':
    6.53 +            dominfo.restart_mode = XendDomainInfo.RESTART_ALWAYS
    6.54 +        restart = dominfo.restart_needed(reason)
    6.55          if restart:
    6.56 -            # Clear autorestart flag to avoid multiple restarts.
    6.57 -            dominfo.autorestart = 0
    6.58 +            # Avoid multiple restarts.
    6.59 +            dominfo.restart_mode = XendDomainInfo.RESTART_NEVER
    6.60              self.restarts[id] = dominfo.config
    6.61              print 'Scheduling restart for domain:', id, dominfo.name
    6.62              self.domain_restarts_schedule()
    6.63 @@ -427,7 +431,7 @@ class XendDomain:
    6.64          """
    6.65          dominfo = self.domain.get(id)
    6.66          if dominfo:
    6.67 -            dominfo.autorestart = 0
    6.68 +            dominfo.restart_mode = XendDomainInfo.RESTART_NEVER
    6.69          if id in self.restarts:
    6.70              del self.restarts[id]
    6.71  
    6.72 @@ -474,13 +478,18 @@ class XendDomain:
    6.73              val = xc.domain_destroy(dom=dom)
    6.74          return val       
    6.75  
    6.76 -    def domain_destroy(self, id):
    6.77 +    def domain_destroy(self, id, reason='halt'):
    6.78          """Terminate domain immediately.
    6.79 -        Cancels any restart for the domain.
    6.80 +        - halt:   cancel any restart for the domain
    6.81 +        - reboot  schedule a restart for the domain
    6.82  
    6.83          @param id: domain id
    6.84          """
    6.85 -        self.domain_restart_cancel(id)
    6.86 +        id = str(id)
    6.87 +        if reason == 'halt':
    6.88 +            self.domain_restart_cancel(id)
    6.89 +        elif reason == 'reboot':
    6.90 +            self.domain_restart_schedule(id, reason, set=1)
    6.91          val = self.final_domain_destroy(id)
    6.92          self.refresh_schedule()
    6.93          return val
     7.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Jul 14 16:41:41 2004 +0000
     7.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Jul 14 17:08:11 2004 +0000
     7.3 @@ -50,6 +50,16 @@ shutdown_reasons = {
     7.4      DOMAIN_REBOOT  : "reboot",
     7.5      DOMAIN_SUSPEND : "suspend" }
     7.6  
     7.7 +RESTART_ALWAYS   = 'always'
     7.8 +RESTART_ONREBOOT = 'onreboot'
     7.9 +RESTART_NEVER    = 'never'
    7.10 +
    7.11 +restart_modes = [
    7.12 +    RESTART_ALWAYS,
    7.13 +    RESTART_ONREBOOT,
    7.14 +    RESTART_NEVER,
    7.15 +    ]
    7.16 +
    7.17  def shutdown_reason(code):
    7.18      """Get a shutdown reason from a code.
    7.19  
    7.20 @@ -117,7 +127,12 @@ def lookup_disk_uname(uname):
    7.21  def make_disk(dom, uname, dev, mode, recreate=0):
    7.22      """Create a virtual disk device for a domain.
    7.23  
    7.24 -    @returns Deferred
    7.25 +    @param dom:      domain id
    7.26 +    @param uname:    device to export
    7.27 +    @param dev:      device name in domain
    7.28 +    @param mode:     read/write mode
    7.29 +    @param recreate: recreate flag (after xend restart)
    7.30 +    @return: deferred
    7.31      """
    7.32      segments = lookup_disk_uname(uname)
    7.33      if not segments:
    7.34 @@ -234,7 +249,6 @@ def vm_create(config):
    7.35      returns Deferred
    7.36      raises VmError for invalid configuration
    7.37      """
    7.38 -    print 'vm_create>'
    7.39      vm = XendDomainInfo()
    7.40      return vm.construct(config)
    7.41  
    7.42 @@ -289,28 +303,21 @@ def append_deferred(dlist, v):
    7.43  
    7.44  def _vm_configure1(val, vm):
    7.45      d = vm.create_devices()
    7.46 -    #print '_vm_configure1> made devices...'
    7.47      def cbok(x):
    7.48 -        #print '_vm_configure1> cbok', x
    7.49          return x
    7.50      d.addCallback(cbok)
    7.51      d.addCallback(_vm_configure2, vm)
    7.52 -    #print '_vm_configure1<'
    7.53      return d
    7.54  
    7.55  def _vm_configure2(val, vm):
    7.56 -    #print '>callback _vm_configure2...'
    7.57      d = vm.configure_fields()
    7.58      def cbok(results):
    7.59 -        #print '_vm_configure2> cbok', results
    7.60          return vm
    7.61      def cberr(err):
    7.62 -        #print '_vm_configure2> cberr', err
    7.63          vm.destroy()
    7.64          return err
    7.65      d.addCallback(cbok)
    7.66      d.addErrback(cberr)
    7.67 -    #print '<_vm_configure2'
    7.68      return d
    7.69  
    7.70  class XendDomainInfo:
    7.71 @@ -341,7 +348,8 @@ class XendDomainInfo:
    7.72          #todo: set to migrate info if migrating
    7.73          self.migrate = None
    7.74          #Whether to auto-restart
    7.75 -        self.autorestart = 0
    7.76 +        self.restart_mode = RESTART_ONREBOOT
    7.77 +        self.console_port = None
    7.78  
    7.79      def setdom(self, dom):
    7.80          self.dom = int(dom)
    7.81 @@ -381,8 +389,7 @@ class XendDomainInfo:
    7.82              state = run + block + stop + susp + crash
    7.83              sxpr.append(['state', state])
    7.84              if self.info['shutdown']:
    7.85 -                reasons = ["poweroff", "reboot", "suspend"]
    7.86 -                reason = reasons[self.info['shutdown_reason']]
    7.87 +                reason = shutdown_reason(self.info['shutdown_reason'])
    7.88                  sxpr.append(['shutdown_reason', reason])
    7.89              sxpr.append(['cpu', self.info['cpu']])
    7.90              sxpr.append(['cpu_time', self.info['cpu_time']/1e9])
    7.91 @@ -397,9 +404,13 @@ class XendDomainInfo:
    7.92          self.config = config
    7.93          try:
    7.94              self.name = sxp.child_value(config, 'name')
    7.95 -            self.memory = int(sxp.child_value(config, 'memory', '128'))
    7.96 -            if sxp.child(config, 'autorestart', None):
    7.97 -                self.autorestart = 1
    7.98 +            if self.name is None:
    7.99 +                raise VmError('missing domain name')
   7.100 +            self.memory = int(sxp.child_value(config, 'memory'))
   7.101 +            if self.memory is None:
   7.102 +                raise VmError('missing memory size')
   7.103 +            self.configure_console()
   7.104 +            self.configure_restart()
   7.105              self.configure_backends()
   7.106              image = sxp.child_value(config, 'image')
   7.107              if image is None:
   7.108 @@ -413,7 +424,6 @@ class XendDomainInfo:
   7.109              image_handler(self, image)
   7.110              deferred = self.configure()
   7.111              def cbok(x):
   7.112 -                print 'vm_create> cbok', x
   7.113                  return x
   7.114              def cberr(err):
   7.115                  self.destroy()
   7.116 @@ -424,7 +434,6 @@ class XendDomainInfo:
   7.117              # Catch errors, cleanup and re-raise.
   7.118              self.destroy()
   7.119              raise
   7.120 -        print 'vm_create<'
   7.121          return deferred
   7.122  
   7.123      def config_devices(self, name):
   7.124 @@ -514,7 +523,6 @@ class XendDomainInfo:
   7.125      def cleanup(self):
   7.126          """Cleanup vm resources: release devices.
   7.127          """
   7.128 -        print 'cleanup>', self.dom
   7.129          self.state = self.STATE_TERMINATED
   7.130          self.release_devices()
   7.131  
   7.132 @@ -526,7 +534,6 @@ class XendDomainInfo:
   7.133      def release_devices(self):
   7.134          """Release all vm devices.
   7.135          """
   7.136 -        print 'release_devices>', self.dom
   7.137          self.release_vifs()
   7.138          self.release_vbds()
   7.139          self.devices = {}
   7.140 @@ -534,7 +541,6 @@ class XendDomainInfo:
   7.141      def release_vifs(self):
   7.142          """Release vm virtual network devices (vifs).
   7.143          """
   7.144 -        print 'release_vifs>', self.dom
   7.145          if self.dom is None: return
   7.146          ctrl = xend.netif_get(self.dom)
   7.147          if ctrl:
   7.148 @@ -543,7 +549,6 @@ class XendDomainInfo:
   7.149      def release_vbds(self):
   7.150          """Release vm virtual block devices (vbds).
   7.151          """
   7.152 -        print 'release_vbds>', self.dom
   7.153          if self.dom is None: return
   7.154          ctrl = xend.blkif_get(self.dom)
   7.155          if ctrl:
   7.156 @@ -574,7 +579,7 @@ class XendDomainInfo:
   7.157          memory = self.memory
   7.158          name = self.name
   7.159          cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
   7.160 -        print 'init_domain>', memory, name, cpu
   7.161 +        #print 'init_domain>', memory, name, cpu
   7.162          dom = xc.domain_create(mem_kb= memory * 1024, name= name, cpu= cpu)
   7.163          if dom <= 0:
   7.164              raise VmError('Creating domain failed: name=%s memory=%d'
   7.165 @@ -589,7 +594,7 @@ class XendDomainInfo:
   7.166              print 'Warning: kernel cmdline too long'
   7.167          dom = self.dom
   7.168          buildfn = getattr(xc, '%s_build' % ostype)
   7.169 -        print 'build_domain>', ostype, dom, kernel, cmdline, ramdisk
   7.170 +        #print 'build_domain>', ostype, dom, kernel, cmdline, ramdisk
   7.171          flags = 0
   7.172          if self.netif_backend: flags |= SIF_NET_BE_DOMAIN
   7.173          if self.blkif_backend: flags |= SIF_BLK_BE_DOMAIN
   7.174 @@ -612,16 +617,13 @@ class XendDomainInfo:
   7.175          cmdline kernel commandline
   7.176          vifs_n  number of network interfaces
   7.177          """
   7.178 -        print 'create_domain>', ostype, kernel
   7.179          if not self.recreate:
   7.180              if not os.path.isfile(kernel):
   7.181                  raise VmError('Kernel image does not exist: %s' % kernel)
   7.182              if ramdisk and not os.path.isfile(ramdisk):
   7.183                  raise VmError('Kernel ramdisk does not exist: %s' % ramdisk)
   7.184 -        print 'create-domain> init_domain...'
   7.185          self.init_domain()
   7.186 -        print 'create_domain>', 'dom=', self.dom
   7.187 -        self.console = xendConsole.console_create(self.dom)
   7.188 +        self.console = xendConsole.console_create(self.dom, console_port=self.console_port)
   7.189          self.build_domain(ostype, kernel, ramdisk, cmdline, vifs_n)
   7.190          self.image = kernel
   7.191          self.ramdisk = ramdisk
   7.192 @@ -633,7 +635,6 @@ class XendDomainInfo:
   7.193          returns Deferred
   7.194          raises VmError for invalid devices
   7.195          """
   7.196 -        print '>create_devices'
   7.197          dlist = []
   7.198          devices = sxp.children(self.config, 'device')
   7.199          index = {}
   7.200 @@ -650,7 +651,6 @@ class XendDomainInfo:
   7.201              append_deferred(dlist, v)
   7.202              index[dev_name] = dev_index + 1
   7.203          deferred = defer.DeferredList(dlist, fireOnOneErrback=1)
   7.204 -        print '<create_devices'
   7.205          return deferred
   7.206  
   7.207      def device_create(self, dev_config):
   7.208 @@ -686,6 +686,30 @@ class XendDomainInfo:
   7.209              self.config.remove(['device', dev_config])
   7.210          dev.destroy()
   7.211  
   7.212 +    def configure_console(self):
   7.213 +        x = sxp.child_value(self.config, 'console')
   7.214 +        if x:
   7.215 +            try:
   7.216 +                port = int(x)
   7.217 +            except:
   7.218 +                raise VmError('invalid console:' + str(x))
   7.219 +            self.console_port = port
   7.220 +
   7.221 +    def configure_restart(self):
   7.222 +        r = sxp.child_value(self.config, 'restart', RESTART_ONREBOOT)
   7.223 +        if r not in restart_modes:
   7.224 +            raise VmError('invalid restart mode: ' + str(r))
   7.225 +        self.restart_mode = r;
   7.226 +
   7.227 +    def restart_needed(self, reason):
   7.228 +        if self.restart_mode == RESTART_NEVER:
   7.229 +            return 0
   7.230 +        if self.restart_mode == RESTART_ALWAYS:
   7.231 +            return 1
   7.232 +        if self.restart_mode == RESTART_ONREBOOT:
   7.233 +            return reason == 'reboot'
   7.234 +        return 0
   7.235 +
   7.236      def configure_backends(self):
   7.237          """Set configuration flags if the vm is a backend for netif of blkif.
   7.238          """
   7.239 @@ -807,7 +831,7 @@ def vm_image_netbsd(vm, image):
   7.240      args = sxp.child_value(image, "args")
   7.241      if args:
   7.242          cmdline += " " + args
   7.243 -    ramdisk = sxp.child_value(image, "ramdisk")
   7.244 +    ramdisk = sxp.child_value(image, "ramdisk", '')
   7.245      vifs = vm.config_devices("vif")
   7.246      vm.create_domain("netbsd", kernel, ramdisk, cmdline, len(vifs))
   7.247      return vm
   7.248 @@ -830,7 +854,6 @@ def vm_dev_vif(vm, val, index):
   7.249          dev = xend.netif_dev(vm.dom, vif)
   7.250          dev.vifctl('up', vmname=vm.name)
   7.251          vm.add_device('vif', dev)
   7.252 -        print 'vm_dev_vif> created', dev
   7.253          return id
   7.254      defer.addCallback(fn)
   7.255      return defer
     8.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Wed Jul 14 16:41:41 2004 +0000
     8.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Wed Jul 14 17:08:11 2004 +0000
     8.3 @@ -50,7 +50,10 @@ class SrvDomain(SrvDir):
     8.4          return val
     8.5  
     8.6      def op_destroy(self, op, req):
     8.7 -        val = self.xd.domain_destroy(self.dom.id)
     8.8 +        fn = FormFn(self.xd.domain_destroy,
     8.9 +                    [['dom', 'int'],
    8.10 +                     ['reason', 'str']])
    8.11 +        val = fn(req.args, {'dom': self.dom.id})
    8.12          req.setHeader("Location", "%s/.." % req.prePathURL())
    8.13          return val
    8.14  
    8.15 @@ -220,7 +223,12 @@ class SrvDomain(SrvDir):
    8.16          req.write('<form method="post" action="%s">' % url)
    8.17          req.write('<input type="submit" name="op" value="unpause">')
    8.18          req.write('<input type="submit" name="op" value="pause">')
    8.19 +        req.write('</form>')
    8.20 +
    8.21 +        req.write('<form method="post" action="%s">' % url)
    8.22          req.write('<input type="submit" name="op" value="destroy">')
    8.23 +        req.write('<input type="radio" name="reason" value="halt" checked>Halt')
    8.24 +        req.write('<input type="radio" name="reason" value="reboot">Reboot')
    8.25          req.write('</form>')
    8.26  
    8.27          req.write('<form method="post" action="%s">' % url)
     9.1 --- a/tools/python/xen/xend/server/console.py	Wed Jul 14 16:41:41 2004 +0000
     9.2 +++ b/tools/python/xen/xend/server/console.py	Wed Jul 14 17:08:11 2004 +0000
     9.3 @@ -6,6 +6,7 @@ from twisted.protocols import telnet
     9.4  
     9.5  from xen.lowlevel import xu
     9.6  
     9.7 +from xen.xend.XendError import XendError
     9.8  from xen.xend import EventServer
     9.9  eserver = EventServer.instance()
    9.10  
    9.11 @@ -77,6 +78,9 @@ class ConsoleControllerFactory(controlle
    9.12      def createInstance(self, dom, console_port=None):
    9.13          if console_port is None:
    9.14              console_port = CONSOLE_PORT_BASE + dom
    9.15 +        for c in self.getInstances():
    9.16 +            if c.console_port == console_port:
    9.17 +                raise XendError('console port in use: ' + str(console_port))
    9.18          console = ConsoleController(self, dom, console_port)
    9.19          self.addInstance(console)
    9.20          eserver.inject('xend.console.create',
    10.1 --- a/tools/python/xen/xm/create.py	Wed Jul 14 16:41:41 2004 +0000
    10.2 +++ b/tools/python/xen/xm/create.py	Wed Jul 14 17:08:11 2004 +0000
    10.3 @@ -68,38 +68,46 @@ gopts.opt('load', short='L', val='FILE',
    10.4            use='Domain saved state to load.')
    10.5  
    10.6  gopts.opt('dryrun', short='n',
    10.7 -         fn=set_true, default=0,
    10.8 -         use="""Dry run - print the config but don't create the domain.
    10.9 +          fn=set_true, default=0,
   10.10 +          use="""Dry run - print the config but don't create the domain.
   10.11  The defaults file is loaded and the SXP configuration is created and printed.         
   10.12  """)
   10.13  
   10.14  gopts.opt('console_autoconnect', short='c',
   10.15 -         fn=set_true, default=0,
   10.16 -         use="Connect to console after domain is created.")
   10.17 +          fn=set_true, default=0,
   10.18 +          use="Connect to console after domain is created.")
   10.19  
   10.20  gopts.var('name', val='NAME',
   10.21            fn=set_value, default=None,
   10.22            use="Domain name.")
   10.23  
   10.24  gopts.var('kernel', val='FILE',
   10.25 -         fn=set_value, default=None,
   10.26 -         use="Path to kernel image.")
   10.27 +          fn=set_value, default=None,
   10.28 +          use="Path to kernel image.")
   10.29  
   10.30  gopts.var('ramdisk', val='FILE',
   10.31 -         fn=set_value, default='',
   10.32 -         use="Path to ramdisk.")
   10.33 +          fn=set_value, default='',
   10.34 +          use="Path to ramdisk.")
   10.35  
   10.36  gopts.var('builder', val='FUNCTION',
   10.37 -         fn=set_value, default='linux',
   10.38 -         use="Function to use to build the domain.")
   10.39 +          fn=set_value, default='linux',
   10.40 +          use="Function to use to build the domain.")
   10.41  
   10.42  gopts.var('memory', val='MEMORY',
   10.43 -         fn=set_value, default=128,
   10.44 -         use="Domain memory in MB.")
   10.45 +          fn=set_value, default=128,
   10.46 +          use="Domain memory in MB.")
   10.47 +
   10.48 +gopts.var('console', val='PORT',
   10.49 +          fn=set_int, default=None,
   10.50 +          use="Console port to use. Default is 9600 + domain id.")
   10.51  
   10.52 -gopts.var('autorestart', val='no|yes',
   10.53 -         fn=set_bool, default=0,
   10.54 -         use="Whether to restart the domain on exit.")
   10.55 +gopts.var('restart', val='onreboot|always|never',
   10.56 +          fn=set_value, default=None,
   10.57 +          use="""Whether the domain should be restarted on exit.
   10.58 +         - onreboot: restart on exit with shutdown code reboot
   10.59 +         - always:   always restart on exit, ignore exit code
   10.60 +         - never:    never restart on exit, ignore exit code
   10.61 +         """)
   10.62  
   10.63  gopts.var('blkif', val='no|yes',
   10.64            fn=set_bool, default=0,
   10.65 @@ -110,27 +118,27 @@ gopts.var('netif', val='no|yes',
   10.66            use="Make the domain a network interface backend.")
   10.67  
   10.68  gopts.var('disk', val='phy:DEV,VDEV,MODE',
   10.69 -         fn=append_value, default=[],
   10.70 -         use="""Add a disk device to a domain. The physical device is DEV,
   10.71 +          fn=append_value, default=[],
   10.72 +          use="""Add a disk device to a domain. The physical device is DEV,
   10.73           which is exported to the domain as VDEV. The disk is read-only if MODE
   10.74           is 'r', read-write if MODE is 'w'.
   10.75           The option may be repeated to add more than one disk.
   10.76           """)
   10.77  
   10.78  gopts.var('pci', val='BUS,DEV,FUNC',
   10.79 -         fn=append_value, default=[],
   10.80 -         use="""Add a PCI device to a domain, using given params (in hex).
   10.81 +          fn=append_value, default=[],
   10.82 +          use="""Add a PCI device to a domain, using given params (in hex).
   10.83           For example '-pci c0,02,1a'.
   10.84           The option may be repeated to add more than one pci device.
   10.85           """)
   10.86  
   10.87  gopts.var('ipaddr', val="IPADDR",
   10.88 -         fn=append_value, default=[],
   10.89 -         use="Add an IP address to the domain.")
   10.90 +          fn=append_value, default=[],
   10.91 +          use="Add an IP address to the domain.")
   10.92  
   10.93  gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT",
   10.94 -         fn=append_value, default=[],
   10.95 -         use="""Add a network interface with the given MAC address and bridge.
   10.96 +          fn=append_value, default=[],
   10.97 +          use="""Add a network interface with the given MAC address and bridge.
   10.98           The vif is configured by calling the given configuration script.
   10.99           If mac is not specified a random MAC address is used.
  10.100           If bridge is not specified the default bridge is used.
  10.101 @@ -140,53 +148,53 @@ gopts.var('vif', val="mac=MAC,bridge=BRI
  10.102           """)
  10.103  
  10.104  gopts.var('nics', val="NUM",
  10.105 -         fn=set_int, default=1,
  10.106 -         use="""Set the number of network interfaces.
  10.107 +          fn=set_int, default=1,
  10.108 +          use="""Set the number of network interfaces.
  10.109           Use the vif option to define interface parameters, otherwise
  10.110           defaults are used. Specifying vifs will increase the
  10.111           number of interfaces as needed.
  10.112           """)
  10.113  
  10.114  gopts.var('root', val='DEVICE',
  10.115 -         fn=set_value, default='',
  10.116 -         use="""Set the root= parameter on the kernel command line.
  10.117 +          fn=set_value, default='',
  10.118 +          use="""Set the root= parameter on the kernel command line.
  10.119           Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
  10.120  
  10.121  gopts.var('extra', val="ARGS",
  10.122 -         fn=set_value, default='',
  10.123 -         use="Set extra arguments to append to the kernel command line.")
  10.124 +          fn=set_value, default='',
  10.125 +          use="Set extra arguments to append to the kernel command line.")
  10.126  
  10.127  gopts.var('ip', val='IPADDR',
  10.128 -         fn=set_value, default='',
  10.129 -         use="Set the kernel IP interface address.")
  10.130 +          fn=set_value, default='',
  10.131 +          use="Set the kernel IP interface address.")
  10.132  
  10.133  gopts.var('gateway', val="IPADDR",
  10.134 -         fn=set_value, default='',
  10.135 -         use="Set the kernel IP gateway.")
  10.136 +          fn=set_value, default='',
  10.137 +          use="Set the kernel IP gateway.")
  10.138  
  10.139  gopts.var('netmask', val="MASK",
  10.140 -         fn=set_value, default = '',
  10.141 -         use="Set the kernel IP netmask.")
  10.142 +          fn=set_value, default = '',
  10.143 +          use="Set the kernel IP netmask.")
  10.144  
  10.145  gopts.var('hostname', val="NAME",
  10.146 -         fn=set_value, default='',
  10.147 -         use="Set the kernel IP hostname.")
  10.148 +          fn=set_value, default='',
  10.149 +          use="Set the kernel IP hostname.")
  10.150  
  10.151  gopts.var('interface', val="INTF",
  10.152 -         fn=set_value, default="eth0",
  10.153 -         use="Set the kernel IP interface name.")
  10.154 +          fn=set_value, default="eth0",
  10.155 +          use="Set the kernel IP interface name.")
  10.156  
  10.157  gopts.var('dhcp', val="off|dhcp",
  10.158 -         fn=set_value, default='off',
  10.159 -         use="Set the kernel dhcp option.")
  10.160 +          fn=set_value, default='off',
  10.161 +          use="Set the kernel dhcp option.")
  10.162  
  10.163  gopts.var('nfs_server', val="IPADDR",
  10.164 -         fn=set_value, default=None,
  10.165 -         use="Set the address of the NFS server for NFS root.")
  10.166 +          fn=set_value, default=None,
  10.167 +          use="Set the address of the NFS server for NFS root.")
  10.168  
  10.169  gopts.var('nfs_root', val="PATH",
  10.170 -         fn=set_value, default=None,
  10.171 -         use="Set the path of the root NFS directory.")
  10.172 +          fn=set_value, default=None,
  10.173 +          use="Set the path of the root NFS directory.")
  10.174  
  10.175  def strip(pre, s):
  10.176      """Strip prefix 'pre' if present.
  10.177 @@ -240,7 +248,7 @@ def randomMAC():
  10.178      The remaining 3 fields are random, with the first bit of the first
  10.179      random field set 0.
  10.180  
  10.181 -    returns array of 6 ints
  10.182 +    returns MAC address string
  10.183      """
  10.184      mac = [ 0xaa, 0x00, 0x00,
  10.185              random.randint(0x00, 0x7f),
  10.186 @@ -294,8 +302,10 @@ def make_config(vals):
  10.187          config.append(['backend', ['blkif']])
  10.188      if vals.netif:
  10.189          config.append(['backend', ['netif']])
  10.190 -    if vals.autorestart:
  10.191 -        config.append(['autorestart'])
  10.192 +    if vals.restart:
  10.193 +        config.append(['restart', vals.restart])
  10.194 +    if vals.console:
  10.195 +        config.append(['console', vals.console])
  10.196      
  10.197      configure_image(config, vals)
  10.198      config_devs = []
  10.199 @@ -345,6 +355,7 @@ def preprocess_vifs(opts, vals):
  10.200  
  10.201  def preprocess_ip(opts, vals):
  10.202      setip = (vals.hostname or vals.netmask
  10.203 +             or vals.nfs_server
  10.204               or vals.gateway or vals.dhcp or vals.interface)
  10.205      if not setip: return
  10.206      dummy_nfs_server = '1.2.3.4'
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/python/xen/xm/destroy.py	Wed Jul 14 17:08:11 2004 +0000
    11.3 @@ -0,0 +1,40 @@
    11.4 +# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    11.5 +
    11.6 +"""Destroy a domain.
    11.7 +"""
    11.8 +
    11.9 +from xen.xend.XendClient import server
   11.10 +from xen.xm.opts import *
   11.11 +
   11.12 +gopts = Opts(use="""[options] [DOM]
   11.13 +
   11.14 +Destroy a domain, optionally restarting it.
   11.15 +""")
   11.16 +
   11.17 +gopts.opt('help', short='h',
   11.18 +         fn=set_true, default=0,
   11.19 +         use="Print this help.")
   11.20 +
   11.21 +gopts.opt('reboot', short='R',
   11.22 +          fn=set_true, default=0,
   11.23 +          use='Destroy and restart.')
   11.24 +
   11.25 +def main(argv):
   11.26 +    opts = gopts
   11.27 +    args = opts.parse(argv)
   11.28 +    if opts.vals.help:
   11.29 +        opts.usage()
   11.30 +        return
   11.31 +    if len(args) < 1: opts.err('Missing domain')
   11.32 +    dom = args[0]
   11.33 +    try:
   11.34 +        domid = int(dom)
   11.35 +    except:
   11.36 +        opts.err('Invalid domain: ' + dom)
   11.37 +    if opts.vals.reboot:
   11.38 +        mode = 'reboot'
   11.39 +    else:
   11.40 +        mode = 'halt'
   11.41 +    server.xend_domain_destroy(domid, mode)
   11.42 +    
   11.43 +        
    12.1 --- a/tools/python/xen/xm/main.py	Wed Jul 14 16:41:41 2004 +0000
    12.2 +++ b/tools/python/xen/xm/main.py	Wed Jul 14 17:08:11 2004 +0000
    12.3 @@ -11,7 +11,7 @@ from xen.xend import PrettyPrint
    12.4  from xen.xend import sxp
    12.5  from xen.xend.XendClient import XendError, server
    12.6  from xen.xend.XendClient import main as xend_client_main
    12.7 -from xen.xm import create, shutdown
    12.8 +from xen.xm import create, destroy, shutdown
    12.9  
   12.10  class Prog:
   12.11      """Base class for sub-programs.
   12.12 @@ -268,13 +268,10 @@ class ProgDestroy(Prog):
   12.13      info = """Terminate a domain immediately."""
   12.14  
   12.15      def help(self, args):
   12.16 -        print args[0], 'DOM'
   12.17 -        print '\nTerminate domain DOM immediately.'
   12.18 +        destroy.main([args[0], '-h'])
   12.19  
   12.20      def main(self, args):
   12.21 -        if len(args) < 2: self.err("%s: Missing domain" % args[0])
   12.22 -        dom = args[1]
   12.23 -        server.xend_domain_destroy(dom)
   12.24 +        destroy.main(args)
   12.25  
   12.26  xm.prog(ProgDestroy)
   12.27