ia64/xen-unstable

changeset 1477:459daba5f498

bitkeeper revision 1.959.1.2 (40cec47bY9QNauJ8KR9IhT-ZdJCb-A)

Fix domain start problem for dom create - id was an int.
Make IP default adressing tolerate eth0 not having an address.
author mjw@wray-m-3.hpl.hp.com
date Tue Jun 15 09:42:19 2004 +0000 (2004-06-15)
parents 3cf2ba082a24
children b442c789c93e 5566ee00e69b
files tools/examples/defaults tools/xenctl/lib/ip.py tools/xenmgr/lib/XendClient.py
line diff
     1.1 --- a/tools/examples/defaults	Mon Jun 14 15:51:07 2004 +0000
     1.2 +++ b/tools/examples/defaults	Tue Jun 15 09:42:19 2004 +0000
     1.3 @@ -1,3 +1,4 @@
     1.4 +import xenctl.ip
     1.5  
     1.6  ##### Edit this python file to reflect the configuration of your system
     1.7  
     1.8 @@ -45,8 +46,8 @@ cpu = vmid  # set based on vmid (mod num
     1.9  # appropriately.
    1.10  
    1.11  #vfr_ipaddr = ["111.222.333.444","222.333.444.555"]
    1.12 -vfr_ipaddr  = [xenctl.utils.add_offset_to_ip(xenctl.utils.get_current_ipaddr(),vmid),
    1.13 -	       xenctl.utils.add_offset_to_ip('169.254.1.0',vmid),]
    1.14 +vfr_ipaddr  = [xenctl.ip.add_offset_to_ip(xenctl.ip.get_current_ipaddr(),vmid),
    1.15 +	       xenctl.ip.add_offset_to_ip('169.254.1.0',vmid),]
    1.16  
    1.17  
    1.18  # STEP 6. Identify any physcial partitions or virtual disks you want the
    1.19 @@ -75,8 +76,8 @@ vbd_expert = 0
    1.20  # You can use 'extrabit' to set the runlevel and custom environment
    1.21  # variables used by custom rc scripts (e.g. VMID=, usr= )
    1.22  
    1.23 -netmask = xenctl.utils.get_current_ipmask()
    1.24 -gateway = xenctl.utils.get_current_ipgw()
    1.25 +netmask = xenctl.ip.get_current_ipmask()
    1.26 +gateway = xenctl.ip.get_current_ipgw()
    1.27  nfsserv = '169.254.1.0'  
    1.28  
    1.29  cmdline_ip = "ip="+vfr_ipaddr[0]+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
     2.1 --- a/tools/xenctl/lib/ip.py	Mon Jun 14 15:51:07 2004 +0000
     2.2 +++ b/tools/xenctl/lib/ip.py	Tue Jun 15 09:42:19 2004 +0000
     2.3 @@ -3,8 +3,44 @@ import re
     2.4  import socket
     2.5  import struct
     2.6  
     2.7 +def readlines(fd):
     2.8 +    """Version of readlines safe against EINTR.
     2.9 +    """
    2.10 +    import errno
    2.11 +    
    2.12 +    lines = []
    2.13 +    while 1:
    2.14 +        try:
    2.15 +            line = fd.readline()
    2.16 +        except IOError, ex:
    2.17 +            if ex.errno == errno.EINTR:
    2.18 +                continue
    2.19 +            else:
    2.20 +                raise
    2.21 +        if line == '': break
    2.22 +        lines.append(line)
    2.23 +    return lines
    2.24 +
    2.25 +def readline(fd):
    2.26 +    """Version of readline safe against EINTR.
    2.27 +    """
    2.28 +    while 1:
    2.29 +        try:
    2.30 +            return fd.readline()
    2.31 +        except IOError, ex:
    2.32 +            if ex.errno == errno.EINTR:
    2.33 +                continue
    2.34 +            else:
    2.35 +                raise
    2.36 +
    2.37  ##### Networking-related functions
    2.38  
    2.39 +"""Bridge for network backend.
    2.40 +When bridging is used, eth0 may not have an IP address,
    2.41 +as it may have been moved onto the bridge.
    2.42 +"""
    2.43 +NBE_BRIDGE = 'nbe-br'
    2.44 +
    2.45  def get_current_ipaddr(dev='eth0'):
    2.46      """Return a string containing the primary IP address for the given
    2.47      network interface (default 'eth0').
    2.48 @@ -16,6 +52,8 @@ def get_current_ipaddr(dev='eth0'):
    2.49                         line )
    2.50          if m:
    2.51              return m.group(1)
    2.52 +    if dev == 'eth0':
    2.53 +        return get_current_ipaddr(NBE_BRIDGE)
    2.54      return None
    2.55  
    2.56  def get_current_ipmask(dev='eth0'):
    2.57 @@ -29,6 +67,8 @@ def get_current_ipmask(dev='eth0'):
    2.58                         line )
    2.59          if m:
    2.60              return m.group(1)
    2.61 +    if dev == 'eth0':
    2.62 +        return get_current_ipmask(NBE_BRIDGE)
    2.63      return None
    2.64  
    2.65  def get_current_ipgw(dev='eth0'):
    2.66 @@ -42,30 +82,8 @@ def get_current_ipgw(dev='eth0'):
    2.67                         '\s+\S+\s+\S*G.*' + dev + '.*', line )
    2.68          if m:
    2.69              return m.group(1)
    2.70 -    return None
    2.71 -
    2.72 -def setup_vfr_rules_for_vif(dom,vif,addr):
    2.73 -    """Takes a tuple ( domain-id, vif-id, ip-addr ), where the ip-addr
    2.74 -    is expressed as a textual dotted quad, and set up appropriate routing
    2.75 -    rules in Xen. No return value.
    2.76 -    """
    2.77 -    fd = os.open( '/proc/xen/vfr', os.O_WRONLY )
    2.78 -    if ( re.search( '169\.254', addr) ):
    2.79 -        os.write( fd, 'ADD ACCEPT srcaddr=' + addr +
    2.80 -                  ' srcaddrmask=255.255.255.255' +
    2.81 -                  ' srcdom=' + str(dom) + ' srcidx=' + str(vif) +
    2.82 -                  ' dstdom=0 dstidx=0 proto=any\n' )
    2.83 -    else:
    2.84 -        os.write( fd, 'ADD ACCEPT srcaddr=' + addr +
    2.85 -                  ' srcaddrmask=255.255.255.255' +
    2.86 -                  ' srcdom=' + str(dom) + ' srcidx=' + str(vif) +
    2.87 -                  ' dst=PHYS proto=any\n' )
    2.88 -    os.write( fd, 'ADD ACCEPT dstaddr=' + addr +
    2.89 -              ' dstaddrmask=255.255.255.255' +
    2.90 -              ' src=ANY' +
    2.91 -              ' dstdom=' + str(dom) + ' dstidx=' + str(vif) +
    2.92 -              ' proto=any\n' )
    2.93 -    os.close( fd )
    2.94 +    if dev == 'eth0':
    2.95 +        return get_current_ipgw(NBE_BRIDGE)
    2.96      return None
    2.97  
    2.98  def inet_aton(addr):
     3.1 --- a/tools/xenmgr/lib/XendClient.py	Mon Jun 14 15:51:07 2004 +0000
     3.2 +++ b/tools/xenmgr/lib/XendClient.py	Tue Jun 15 09:42:19 2004 +0000
     3.3 @@ -12,7 +12,7 @@ from encode import *
     3.4  import sxp
     3.5  import PrettyPrint
     3.6  
     3.7 -DEBUG = 1
     3.8 +DEBUG = 0
     3.9  
    3.10  class Foo(httplib.HTTPResponse):
    3.11  
    3.12 @@ -55,6 +55,8 @@ def fileof(val):
    3.13  # And should accept urls for ids?
    3.14  
    3.15  def urljoin(location, root, prefix='', rest=''):
    3.16 +    prefix = str(prefix)
    3.17 +    rest = str(rest)
    3.18      base = 'http://' + location + root + prefix
    3.19      url = urlparse.urljoin(base, rest)
    3.20      return url
    3.21 @@ -68,9 +70,6 @@ def domainurl(location, root, id=''):
    3.22  def consoleurl(location, root, id=''):
    3.23      return urljoin(location, root, 'console/', id)
    3.24  
    3.25 -def vbdurl(location, root, id=''):
    3.26 -    return urljoin(location, root, 'vbd/', id)
    3.27 -
    3.28  def deviceurl(location, root, id=''):
    3.29      return urljoin(location, root, 'device/', id)
    3.30  
    3.31 @@ -155,9 +154,6 @@ class Xend:
    3.32      def consoleurl(self, id=''):
    3.33          return consoleurl(self.location, self.root, id)
    3.34  
    3.35 -    def vbdurl(self, id=''):
    3.36 -        return vbdurl(self.location, self.root, id)
    3.37 -
    3.38      def deviceurl(self, id=''):
    3.39          return deviceurl(self.location, self.root, id)
    3.40  
    3.41 @@ -283,17 +279,17 @@ class Xend:
    3.42                          {'op'       : 'vbd',
    3.43                           'vbd'      : vbd})
    3.44  
    3.45 -    def xend_domain_vbd_add(self, id, uname, dev, mode):
    3.46 -        return xend_call(self.domainurl(id),
    3.47 -                         {'op'      : 'vbd_add',
    3.48 -                          'uname'   : uname,
    3.49 -                          'dev'     : dev,
    3.50 -                          'mode'    : mode})
    3.51 +##     def xend_domain_vbd_add(self, id, uname, dev, mode):
    3.52 +##         return xend_call(self.domainurl(id),
    3.53 +##                          {'op'      : 'vbd_add',
    3.54 +##                           'uname'   : uname,
    3.55 +##                           'dev'     : dev,
    3.56 +##                           'mode'    : mode})
    3.57  
    3.58 -    def xend_domain_vbd_remove(self, id, dev):
    3.59 -        return xend_call(self.domainurl(id),
    3.60 -                         {'op'      : 'vbd_remove',
    3.61 -                          'dev'     : dev})
    3.62 +##     def xend_domain_vbd_remove(self, id, dev):
    3.63 +##         return xend_call(self.domainurl(id),
    3.64 +##                          {'op'      : 'vbd_remove',
    3.65 +##                           'dev'     : dev})
    3.66  
    3.67      def xend_consoles(self):
    3.68          return xend_get(self.consoleurl())
    3.69 @@ -301,28 +297,6 @@ class Xend:
    3.70      def xend_console(self, id):
    3.71          return xend_get(self.consoleurl(id))
    3.72  
    3.73 -    def xend_vbds(self):
    3.74 -        return xend_get(self.vbdurl())
    3.75 -
    3.76 -    def xend_vbd_create(self, conf):
    3.77 -        return xend_call(self.vbdurl(),
    3.78 -                         {'op': 'create', 'config': fileof(conf) })
    3.79 -
    3.80 -    def xend_vbd(self, id):
    3.81 -        return xend_get(self.vbdurl(id))
    3.82 -
    3.83 -    def xend_vbd_delete(self, id):
    3.84 -        return xend_call(self.vbdurl(id),
    3.85 -                         {'op': 'delete'})
    3.86 -
    3.87 -    def xend_vbd_refresh(self, id, expiry):
    3.88 -        return xend_call(self.vbdurl(id),
    3.89 -                         {'op': 'refresh', 'expiry': expiry })
    3.90 -
    3.91 -    def xend_vbd_expand(self, id, size):
    3.92 -        return xend_call(self.vbdurl(id),
    3.93 -                         {'op': 'expand', 'size': size})
    3.94 -
    3.95      def xend_vnets(self):
    3.96          return xend_get(self.vneturl())
    3.97