ia64/xen-unstable

changeset 1981:930e4cde32b5

bitkeeper revision 1.1108.37.1 (4108f395VJ6nDz3Ag7FW0LiNkvflog)

More work on Domain Creation Wizzard.

Works well
author tw275@labyrinth.cl.cam.ac.uk
date Thu Jul 29 12:54:45 2004 +0000 (2004-07-29)
parents 6670d27fd5df
children 251ee97e26ea
files tools/python/xen/sv/CreateDomain.py tools/python/xen/sv/DomList.py tools/python/xen/sv/HTMLBase.py tools/python/xen/sv/Wizard.py
line diff
     1.1 --- a/tools/python/xen/sv/CreateDomain.py	Wed Jul 28 17:40:00 2004 +0000
     1.2 +++ b/tools/python/xen/sv/CreateDomain.py	Thu Jul 29 12:54:45 2004 +0000
     1.3 @@ -2,7 +2,7 @@ from xen.sv.Wizard import *
     1.4  from xen.sv.util import *
     1.5  from xen.sv.GenTabbed import PreTab
     1.6  
     1.7 -from xen.xm.create import make_config
     1.8 +from xen.xm.create import make_config, OptVals
     1.9  
    1.10  from xen.xend.XendClient import server
    1.11  
    1.12 @@ -22,94 +22,108 @@ class CreatePage0( Sheet ):
    1.13  
    1.14      def __init__( self, urlWriter ):
    1.15          Sheet.__init__( self, urlWriter, "General", 0 )
    1.16 -        self.addControl( InputControl( 'name', 'VM Name', 'VM Name:' ) )
    1.17 -        self.addControl( InputControl( 'memory', '64', 'Memory (Mb):' ) )
    1.18 -        self.addControl( InputControl( 'cpu', '0', 'CPU:' ) )
    1.19 +        self.addControl( InputControl( 'name', 'VM Name', 'VM Name:', "[\\w|\\S]+", "You must enter a name in this field" ) )
    1.20 +        self.addControl( InputControl( 'memory', '64', 'Memory (Mb):', "[\\d]+", "You must enter a number in this field" ) )
    1.21 +        self.addControl( InputControl( 'cpu', '0', 'CPU:', "[\\d]+", "You must enter a number in this feild" ) )
    1.22                          
    1.23  class CreatePage1( Sheet ):
    1.24  
    1.25      def __init__( self, urlWriter ):
    1.26          Sheet.__init__( self, urlWriter, "Setup Kernel Image", 1 )
    1.27 -        self.addControl( InputControl( 'builder', 'linux', 'Kernel Type:' ) )
    1.28 -        self.addControl( InputControl( 'kernel', '/boot/vmlinuz-2.4.26-xenU', 'Kernel Image:' ) )
    1.29 -        self.addControl( InputControl( 'extra', '', 'Kernel Command Line Parame:' ) )
    1.30 +        self.addControl( ListControl( 'builder', [('linux', 'Linux'), ('netbsd', 'NetBSD')], 'Kernel Type:' ) )
    1.31 +        self.addControl( FileControl( 'kernel', '/boot/vmlinuz-2.4.26-xenU', 'Kernel Image:' ) )
    1.32 +        self.addControl( InputControl( 'extra', '', 'Kernel Command Line Parameters:' ) )
    1.33  
    1.34  class CreatePage2( Sheet ):
    1.35  
    1.36      def __init__( self, urlWriter ):
    1.37      	Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 2 )
    1.38 -        self.addControl( InputControl( 'num_vbds', '1', 'Number of VBDs:' ) )
    1.39 +        self.addControl( InputControl( 'num_vbds', '1', 'Number of VBDs:', '[\\d]+', "You must enter a number in this field" ) )
    1.40  
    1.41  class CreatePage3( Sheet ):
    1.42  
    1.43      def __init__( self, urlWriter ):
    1.44          Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 3 )
    1.45          
    1.46 -    def write_BODY( self, request ):
    1.47 +    def write_BODY( self, request, err ):
    1.48 +        if not self.passback: self.parseForm( request )
    1.49 +    
    1.50      	previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
    1.51 +        
    1.52          num_vbds = previous_values.get( 'num_vbds' )
    1.53          
    1.54          for i in range( int( num_vbds ) ):
    1.55 -            self.addControl( InputControl( 'vbd%s_dom0' % i, '/dev/sda%i' % i, 'Device %s name:' % i  ) )
    1.56 -            self.addControl( InputControl( 'vbd%s_domU' % i, '/dev/sda%i' % i, 'Virtualized device %s:' % i ) )
    1.57 -            self.addControl( InputControl( 'vbd%s_mode' % i, 'w', 'Device %s mode:' % i ) )
    1.58 +            self.addControl( InputControl( 'vbd%s_dom0' % i, 'phy:sda%s' % str(i + 1), 'Device %s name:' % i  ) )
    1.59 +            self.addControl( InputControl( 'vbd%s_domU' % i, 'sda%s' % str(i + 1), 'Virtualized device %s:' % i ) )
    1.60 +            self.addControl( ListControl( 'vbd%s_mode' % i, [('w', 'Read + Write'), ('r', 'Read Only')], 'Device %s mode:' % i ) )
    1.61              
    1.62          self.addControl( InputControl( 'root', '/dev/sda1', 'Root device (in VM):' ) )
    1.63          
    1.64 -        Sheet.write_BODY( self, request )
    1.65 +        Sheet.write_BODY( self, request, err )
    1.66                  
    1.67  class CreatePage4( Sheet ):
    1.68  
    1.69      def __init__( self, urlWriter ):        
    1.70 -        Sheet.__init__( self, urlWriter, "Network settings", 4 )  
    1.71 +        Sheet.__init__( self, urlWriter, "Network settings", 4 )
    1.72 +        self.addControl( ListControl( 'dhcp', [('off', 'No'), ('dhcp', 'Yes')], 'Use DHCP:' ) )
    1.73          self.addControl( InputControl( 'hostname', 'hostname', 'VM Hostname:' ) )
    1.74          self.addControl( InputControl( 'ip_addr', '1.2.3.4', 'VM IP Address:' ) )
    1.75          self.addControl( InputControl( 'ip_subnet', '255.255.255.0', 'VM Subnet Mask:' ) ) 
    1.76          self.addControl( InputControl( 'ip_gateway', '1.2.3.4', 'VM Gateway:' ) )           
    1.77 -         
    1.78 +        self.addControl( InputControl( 'ip_nfs', '1.2.3.4', 'NFS Server:' ) )  
    1.79 +                 
    1.80  class CreateFinish( Sheet ):
    1.81  
    1.82      def __init__( self, urlWriter ):
    1.83          Sheet.__init__( self, urlWriter, "All Done", 5 )
    1.84          
    1.85 -    def write_BODY( self, request ):
    1.86 -    	fin_sxp = string2sxp( self.passback )
    1.87 +    def write_BODY( self, request, err ):
    1.88      
    1.89 -        xend_sxp = self.translate_sxp( fin_sxp )
    1.90 +        if not self.passback: self.parseForm( request )
    1.91 +        
    1.92 +        xend_sxp = self.translate_sxp( string2sxp( self.passback ) )
    1.93          
    1.94 -        pt = PreTab( sxp2prettystring( xend_sxp ) )
    1.95 -        pt.write_BODY( request )
    1.96 +        dom_sxp = server.xend_domain_create( xend_sxp )
    1.97          
    1.98 -        server.xend_domain_create( xend_sxp )
    1.99 -       
   1.100 +        pt = PreTab( sxp2prettystring( dom_sxp ) )
   1.101 +        pt.write_BODY( request )
   1.102 +
   1.103          request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
   1.104          request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
   1.105      
   1.106      def translate_sxp( self, fin_sxp ):
   1.107     	fin_hash = ssxp2hash( fin_sxp )
   1.108      
   1.109 +        def get( key ):
   1.110 +            ret = fin_hash.get( key )
   1.111 +            if ret:
   1.112 +                return ret
   1.113 +            else:
   1.114 +                return ""
   1.115 +        
   1.116      	vals = OptVals()
   1.117          
   1.118 -        setattr(vals, "name", 	fin_hash.get( 'name' ) )
   1.119 -        setattr(vals, "memory", fin_hash.get( 'memory' ) )
   1.120 -        setattr(vals, "cpu", 	fin_hash.get( 'cpu' ) )
   1.121 +        vals.name = 	get( 'name' )
   1.122 +        vals.memory = 	get( 'memory' )
   1.123 +        vals.cpu =  	get( 'cpu' )
   1.124          
   1.125 -        setattr(vals, "builder", 	fin_hash.get( 'builder' ) )        
   1.126 -        setattr(vals, "kernel", 	fin_hash.get( 'kernel' ) )
   1.127 -	setattr(vals, "root", 		fin_hash.get( 'root' ) )
   1.128 -        setattr(vals, "extra", 		fin_hash.get( 'extra' ) ) 
   1.129 +        vals.builder =  get( 'builder' )       
   1.130 +        vals.kernel =   get( 'kernel' )
   1.131 +	vals.root = 	get( 'root' )
   1.132 +        vals.extra = 	get( 'extra' )
   1.133 +        
   1.134 +        #setup vbds
   1.135          
   1.136          vbds = []
   1.137          
   1.138 -        for i in range( int( fin_hash.get( 'num_vbds' ) ) ):
   1.139 -            vbds.append( ( fin_hash.get('vbd%s_domU' % i ), fin_hash.get( 'vbd%s_dom0' % i ), fin_hash.get( 'vbd%s_mode' % i ) ) )
   1.140 +        for i in range( int( get( 'num_vbds' ) ) ):
   1.141 +            vbds.append( ( get( 'vbd%s_dom0' % i ), get('vbd%s_domU' % i ), get( 'vbd%s_mode' % i ) ) )
   1.142          
   1.143          vals.disk = vbds    
   1.144              
   1.145 -        vals.pci = []
   1.146 +        #misc crap
   1.147          
   1.148 -        vals.vif = []
   1.149 -        vals.nics = 1
   1.150 +        vals.pci = []
   1.151          
   1.152          vals.blkif = None
   1.153          vals.netif = None
   1.154 @@ -117,14 +131,18 @@ class CreateFinish( Sheet ):
   1.155          vals.console = None
   1.156          vals.ramdisk = None
   1.157          
   1.158 -        #todo: setup ip addr stuff
   1.159 +        #setup vifs
   1.160          
   1.161 -        vals.cmdline_ip = None
   1.162 +        vals.vif = []
   1.163 +        vals.nics = 1
   1.164 +                
   1.165 +        ip =   get( 'ip_addr' )
   1.166 +        nfs =  get( 'ip_nfs' )
   1.167 +        gate = get( 'ip_gateway' )
   1.168 +        mask = get( 'ip_subnet' )
   1.169 +        host = get( 'hostname' )
   1.170 +        dhcp = get( 'dhcp' )
   1.171 +        
   1.172 +        vals.cmdline_ip = "%s:%s:%s:%s:%s:eth0:%s" % (ip, nfs, gate, mask, host, dhcp)
   1.173          
   1.174          return make_config( vals )
   1.175 -
   1.176 -        
   1.177 -class OptVals:
   1.178 -    """Class to hold option values.
   1.179 -    """
   1.180 -    pass
   1.181 \ No newline at end of file
     2.1 --- a/tools/python/xen/sv/DomList.py	Wed Jul 28 17:40:00 2004 +0000
     2.2 +++ b/tools/python/xen/sv/DomList.py	Thu Jul 29 12:54:45 2004 +0000
     2.3 @@ -16,8 +16,9 @@ class DomList( HTMLBase ):
     2.4      	return self.write_BODY( request, head=True, long=False ) 
     2.5  
     2.6      def write_BODY( self, request, head=True, long=True ):
     2.7 -    
     2.8 -        domains = server.xend_domains()
     2.9 +        
    2.10 +        domains = map(int, server.xend_domains())
    2.11 +        domains.sort()
    2.12      
    2.13          request.write( "\n<table style='border:0px solid white' cellspacing='0' cellpadding='0' border='0' width='100%'>\n" )
    2.14          
     3.1 --- a/tools/python/xen/sv/HTMLBase.py	Wed Jul 28 17:40:00 2004 +0000
     3.2 +++ b/tools/python/xen/sv/HTMLBase.py	Thu Jul 29 12:54:45 2004 +0000
     3.3 @@ -9,13 +9,12 @@ class HTMLBase( Resource ):
     3.4  
     3.5      def render_POST( self, request ):
     3.6          self.perform( request )
     3.7 -        self.render_GET( request ) 
     3.8 +        return self.render_GET( request )
     3.9          
    3.10      def render_GET( self, request ):
    3.11          self.write_TOP( request )
    3.12          self.write_BODY( request )
    3.13          self.write_BOTTOM( request )
    3.14 -        request.finish()
    3.15          return ''
    3.16                  
    3.17      def write_BODY( self, request ):
     4.1 --- a/tools/python/xen/sv/Wizard.py	Wed Jul 28 17:40:00 2004 +0000
     4.2 +++ b/tools/python/xen/sv/Wizard.py	Thu Jul 29 12:54:45 2004 +0000
     4.3 @@ -2,7 +2,9 @@ from xen.sv.util import *
     4.4  from xen.sv.HTMLBase import HTMLBase
     4.5  from xen.xend import sxp
     4.6  
     4.7 -DEBUG = 1
     4.8 +import re
     4.9 +
    4.10 +DEBUG = 0
    4.11  
    4.12  class Wizard( HTMLBase ):
    4.13  
    4.14 @@ -27,17 +29,25 @@ class Wizard( HTMLBase ):
    4.15          else:
    4.16              currSheet = 0
    4.17              
    4.18 -        op = getVar( 'op', request )
    4.19 +        sheet = self.sheets[ currSheet ]( self.urlWriter )
    4.20 +        
    4.21 +        err = not sheet.validate( request )
    4.22 +        
    4.23 +        if not err:    
    4.24 +            op = getVar( 'op', request )
    4.25          
    4.26 -        if op == 'next':
    4.27 -            currSheet += 1
    4.28 -        elif op == 'prev':
    4.29 -             currSheet -= 1
    4.30 +            if op == 'next':
    4.31 +               currSheet += 1
    4.32 +            elif op == 'prev':
    4.33 +               currSheet -= 1
    4.34               
    4.35 -        sheet = self.sheets[ currSheet ]( self.urlWriter )    
    4.36 -            
    4.37 -        sheet.parseForm( request )
    4.38 -        sheet.write_BODY( request )
    4.39 +            sheet = self.sheets[ currSheet ]( self.urlWriter )
    4.40 +        
    4.41 +        if getVar( 'visited-sheet%s' % currSheet, request ):
    4.42 +            sheet.write_BODY( request, err )
    4.43 +        else:
    4.44 +            sheet.write_BODY( request, False )
    4.45 +
    4.46          
    4.47          request.write( "</td></tr><tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>" )
    4.48          request.write( "<td width='80%'></td><td width='20%' align='center'><p align='center'>" )
    4.49 @@ -67,10 +77,10 @@ class Sheet( HTMLBase ):
    4.50          self.feilds = []
    4.51          self.title = title
    4.52          self.location = location
    4.53 -        self.passback = "()"
    4.54 +        self.passback = None
    4.55          
    4.56      def parseForm( self, request ):
    4.57 -    	do_not_parse = [ 'mod', 'op', 'sheet' ] 
    4.58 +    	do_not_parse = [ 'mod', 'op', 'sheet', 'passback' ] 
    4.59      
    4.60      	passed_back = request.args
    4.61          
    4.62 @@ -85,11 +95,6 @@ class Sheet( HTMLBase ):
    4.63          
    4.64          if DEBUG: print last_passback
    4.65          
    4.66 -        try: 
    4.67 -            del passed_back[ 'passback' ]
    4.68 -        except:
    4.69 -            pass
    4.70 -        
    4.71          for (key, value) in passed_back.items():
    4.72              if key not in do_not_parse:
    4.73                  last_passback[ key ] = value[ len( value ) - 1 ]
    4.74 @@ -98,37 +103,66 @@ class Sheet( HTMLBase ):
    4.75          
    4.76          if DEBUG: print self.passback
    4.77          
    4.78 -    def write_BODY( self, request ):
    4.79 +    def write_BODY( self, request, err ):
    4.80 +    
    4.81 +    	if not self.passback: self.parseForm( request )
    4.82          
    4.83     	request.write( "<p>%s</p>" % self.title )
    4.84      
    4.85 -    	previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
    4.86 +    	previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
    4.87          
    4.88          request.write( "<table width='100%' cellpadding='0' cellspacing='1' border='0'>" )
    4.89          
    4.90      	for (feild, control) in self.feilds:
    4.91              control.write_Control( request, previous_values.get( feild ) )
    4.92 +            if err and not control.validate( previous_values.get( feild ) ):
    4.93 +            	control.write_Help( request )
    4.94              
    4.95          request.write( "</table>" )
    4.96              
    4.97          request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
    4.98          request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
    4.99 -        
   4.100 +        request.write( "<input type='hidden' name='visited-sheet%s' value='True'></p>" % self.location )
   4.101 +                
   4.102      def addControl( self, control ):
   4.103      	self.feilds.append( [ control.getName(), control ] )
   4.104          
   4.105 +    def validate( self, request ):
   4.106 +    
   4.107 +        if not self.passback: self.parseForm( request )
   4.108 +            
   4.109 +    	check = True
   4.110 +        
   4.111 +        previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
   4.112 +    	if DEBUG: print previous_values
   4.113 +      
   4.114 +      	for (feild, control) in self.feilds:
   4.115 +            if not control.validate( previous_values.get( feild ) ):
   4.116 +                check = False
   4.117 +                if DEBUG: print "> %s = %s" % (feild, previous_values.get( feild ))
   4.118 +
   4.119 +        return check
   4.120 +        
   4.121  class SheetControl( HTMLBase ):
   4.122  
   4.123 -    def __init__( self ):
   4.124 +    def __init__( self, reg_exp = ".*" ):
   4.125          HTMLBase.__init__( self )
   4.126          self.name = ""
   4.127 +        self.reg_exp = reg_exp 
   4.128          
   4.129      def write_Control( self, request, persistedValue ):
   4.130          request.write( "<tr colspan='2'><td>%s</td></tr>" % persistedValue )
   4.131          
   4.132 -    def validate( self ):
   4.133 -    	return True
   4.134 +    def write_Help( self, request ):
   4.135 +        request.write( "<tr><td align='right' colspan='2'><p class='small'>Text must match pattern:" )
   4.136 +        request.write( " %s</p></td></tr>" % self.reg_exp )
   4.137          
   4.138 +    def validate( self, persistedValue ):
   4.139 +    	if persistedValue is None:
   4.140 +            persistedValue = ""
   4.141 +            
   4.142 +        return not re.compile( self.reg_exp ).match( persistedValue ) is None
   4.143 +
   4.144      def getName( self ):
   4.145      	return self.name
   4.146          
   4.147 @@ -137,19 +171,24 @@ class SheetControl( HTMLBase ):
   4.148          
   4.149  class InputControl( SheetControl ):
   4.150  
   4.151 -    def __init__( self, name, defaultValue, humanText):
   4.152 -        SheetControl.__init__( self )
   4.153 +    def __init__( self, name, defaultValue, humanText,  reg_exp = ".*", help_text = "You must enter the appropriate details in this feild." ):
   4.154 +        SheetControl.__init__( self, reg_exp )
   4.155          self.setName( name )
   4.156          
   4.157          self.defaultValue = defaultValue
   4.158          self.humanText = humanText
   4.159 +        self.help_text = help_text
   4.160          
   4.161      def write_Control( self, request, persistedValue ):
   4.162      	if persistedValue is None:
   4.163              persistedValue = self.defaultValue
   4.164          
   4.165 -        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'><input type='text' name='%s' value=\"%s\"></td></tr>" % (self.humanText, self.getName(), persistedValue) )
   4.166 +        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'><input size='40'type='text' name='%s' value=\"%s\"></td></tr>" % (self.humanText, self.getName(), persistedValue) )
   4.167  
   4.168 +    def write_Help( self, request ):
   4.169 +        request.write( "<tr><td align='right' colspan='2'><p class='small'>" )
   4.170 +        request.write( " %s</p></td></tr>" % self.help_text )         
   4.171 +        
   4.172  class TextControl( SheetControl ):
   4.173  
   4.174      def __init__( self, text ):
   4.175 @@ -168,7 +207,63 @@ class SmallTextControl( SheetControl ):
   4.176      def write_Control( self, request, persistedValue ):
   4.177      	request.write( "<tr><td colspan='2'><p class='small'>%s</p></tr></td>" % self.text )
   4.178          
   4.179 -                 
   4.180 +class ListControl( SheetControl ):
   4.181 +
   4.182 +    def __init__( self, name, options, humanText ):
   4.183 +    	SheetControl.__init__( self )
   4.184 +        self.setName( name )
   4.185 +        self.options = options
   4.186 +        self.humanText = humanText
   4.187 +        
   4.188 +    def write_Control( self, request, persistedValue ):
   4.189 +        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )
   4.190 +    	request.write( "<select name='%s'>" % self.getName() )
   4.191 +        for (value, text) in self.options:
   4.192 +            if value == persistedValue:
   4.193 +            	request.write( "<option value='%s' selected>%s\n" % (value, text) )
   4.194 +            else:
   4.195 +                request.write( "<option value='%s'>%s\n" % (value, text) )
   4.196 +        request.write( "</select></td></tr>" )
   4.197 +
   4.198 +    def validate( self, persistedValue ):
   4.199 +        for (value, text) in self.options:
   4.200 +            if value == persistedValue:
   4.201 +                return True
   4.202 +                
   4.203 +        return False
   4.204 +        
   4.205 +class FileControl( InputControl ):
   4.206 +
   4.207 +    def __init__( self, name, defaultValue, humanText,  reg_exp = ".*", help_text = "You must enter the appropriate details in this feild." ):
   4.208 +	InputControl.__init__( self, name, defaultValue, humanText )
   4.209 +        
   4.210 +    def validate( self, persistedValue ):
   4.211 +        if persistedValue is None: return False
   4.212 +        try:
   4.213 +            open( persistedValue )
   4.214 +            return True
   4.215 +        except IOError, TypeError:
   4.216 +            return False
   4.217 +    
   4.218 +    def write_Help( self, request ):
   4.219 +        request.write( "<tr><td colspan='2' align='right'><p class='small'>File does not exist: you must enter a valid, absolute file path.</p></td></tr>" )
   4.220 +
   4.221 +class TickControl( SheetControl ):
   4.222 +
   4.223 +    def __init__( self, name, defaultValue, humanText ):
   4.224 +        SheetControl.__init__( self )
   4.225 +        self.setName( name )
   4.226 +        self.defaultValue = defaultValue
   4.227 +        self.humanText = humanText
   4.228 +        
   4.229 +    def write_Control( self, request, persistedValue ):
   4.230 +        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )
   4.231 +        
   4.232 +        if persistedValue == 'True':
   4.233 +    	    request.write( "<input type='checkbox' name='%s' value='True' checked>" % self.getName() )
   4.234 +        else:
   4.235 +    	    request.write( "<input type='checkbox' name='%s' value='True'>" % self.getName() )
   4.236              
   4.237 -    
   4.238 +        request.write( "</select></td></tr>" )
   4.239 +
   4.240