direct-io.hg

changeset 6447:a43cc4e06814

Fix vnets in xm.
The removal of 'xm call' to call a xend interface function directly
made the xend vnet functions inaccessible. This patch adds those functions
to xm and fixes the persistence in XmVnet to use xenstore.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Aug 26 10:51:10 2005 +0000 (2005-08-26)
parents 581be7c5e9e4
children 6bad5eb72ce0
files tools/python/xen/util/Brctl.py tools/python/xen/xend/XendVnet.py tools/python/xen/xend/server/SrvVnetDir.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/util/Brctl.py	Fri Aug 26 10:35:36 2005 +0000
     1.2 +++ b/tools/python/xen/util/Brctl.py	Fri Aug 26 10:51:10 2005 +0000
     1.3 @@ -76,6 +76,7 @@ def bridge_set(bridge, hello=None, fd=No
     1.4  def bridge_del(bridge):
     1.5      """Delete a bridge.
     1.6      """
     1.7 +    cmd(CMD_IFCONFIG, '%s down' % bridge)
     1.8      cmd(CMD_BRCTL, 'delbr %s' % bridge)
     1.9  
    1.10  def routes():
     2.1 --- a/tools/python/xen/xend/XendVnet.py	Fri Aug 26 10:35:36 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendVnet.py	Fri Aug 26 10:51:10 2005 +0000
     2.3 @@ -22,7 +22,7 @@ from xen.util import Brctl
     2.4  from xen.xend import sxp
     2.5  from xen.xend.XendError import XendError
     2.6  from xen.xend.XendLogging import log
     2.7 -from xen.xend.xenstore import XenNode, DBMap
     2.8 +from xen.xend.xenstore import XenNode, DBMap, DBVar
     2.9  
    2.10  def vnet_cmd(cmd):
    2.11      out = None
    2.12 @@ -38,17 +38,40 @@ def vnet_cmd(cmd):
    2.13  class XendVnetInfo:
    2.14      
    2.15      vifctl_ops = {'up': 'vif.add', 'down': 'vif.del'}
    2.16 +
    2.17 +    __exports__ = [
    2.18 +        DBVar('id',     ty='str'),
    2.19 +        DBVar('dbid',   ty='str'),
    2.20 +        DBVar('config', ty='sxpr'),
    2.21 +       ]
    2.22      
    2.23 -    def __init__(self, config):
    2.24 -        self.config = config
    2.25 -        self.id = sxp.child_value(config, 'id')
    2.26 -        self.id = str(self.id)
    2.27 +    def __init__(self, db, config=None):
    2.28 +        if config:
    2.29 +            self.id = sxp.child_value(config, 'id')
    2.30 +            self.id = str(self.id)
    2.31 +            self.dbid = self.id.replace(':', '-')
    2.32 +            self.db = db.addChild(self.dbid)
    2.33 +            self.config = config
    2.34 +        else:
    2.35 +            self.db = db
    2.36 +            self.importFromDB()
    2.37 +            config = self.config
    2.38 +            
    2.39          self.bridge = sxp.child_value(config, 'bridge')
    2.40          if not self.bridge:
    2.41              self.bridge = "vnet%s" % self.id
    2.42          self.vnetif = sxp.child_value(config, 'vnetif')
    2.43          if not self.vnetif:
    2.44 -            self.vnetif = "vnetif%s" % self.id
    2.45 +            self.vnetif = "vnif%s" % self.id
    2.46 +
    2.47 +    def saveToDB(self, save=False, sync=False):
    2.48 +        self.db.saveDB(save=save, sync=sync)
    2.49 +
    2.50 +    def exportToDB(self, save=False, sync=False):
    2.51 +        self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
    2.52 +
    2.53 +    def importFromDB(self):
    2.54 +        self.db.importFromDB(self, fields=self.__exports__)
    2.55  
    2.56      def sxpr(self):
    2.57          return self.config
    2.58 @@ -64,7 +87,9 @@ class XendVnetInfo:
    2.59          log.info("Deleting vnet %s", self.id)
    2.60          Brctl.vif_bridge_rem({'bridge': self.bridge, 'vif': self.vnetif})
    2.61          Brctl.bridge_del(self.bridge)
    2.62 -        return vnet_cmd(['vnet.del', self.id])
    2.63 +        val = vnet_cmd(['vnet.del', self.id])
    2.64 +        self.db.delete()
    2.65 +        return val
    2.66  
    2.67      def vifctl(self, op, vif, vmac):
    2.68          try:
    2.69 @@ -82,16 +107,18 @@ class XendVnet:
    2.70      def __init__(self):
    2.71          # Table of vnet info indexed by vnet id.
    2.72          self.vnet = {}
    2.73 -        self.dbmap = DBMap(db=XenNode(self.dbpath))
    2.74 -        self.dbmap.readDB()
    2.75 -        for vnetdb in self.dbmap.values():
    2.76 -            config = vnetdb.config
    2.77 -            info = XendVnetInfo(config)
    2.78 -            self.vnet[info.id] = info
    2.79 +        self.db = DBMap(db=XenNode(self.dbpath))
    2.80 +        self.db.readDB()
    2.81 +        for vnetdb in self.db.values():
    2.82              try:
    2.83 +                info = XendVnetInfo(vnetdb)
    2.84 +                self.vnet[info.id] = info
    2.85                  info.configure()
    2.86              except XendError, ex:
    2.87                  log.warning("Failed to configure vnet %s: %s", str(info.id), str(ex))
    2.88 +            except Exception, ex:
    2.89 +                log.exception("Vnet error")
    2.90 +                vnetdb.delete()
    2.91  
    2.92      def vnet_of_bridge(self, bridge):
    2.93          """Get the vnet for a bridge (if any).
    2.94 @@ -128,9 +155,9 @@ class XendVnet:
    2.95  
    2.96          @param config: config
    2.97          """
    2.98 -        info = XendVnetInfo(config)
    2.99 +        info = XendVnetInfo(self.db, config=config)
   2.100          self.vnet[info.id] = info
   2.101 -        self.dbmap["%s/config" % info.id] = info.sxpr()
   2.102 +        info.saveToDB()
   2.103          info.configure()
   2.104  
   2.105      def vnet_delete(self, id):
   2.106 @@ -141,7 +168,6 @@ class XendVnet:
   2.107          info = self.vnet_get(id)
   2.108          if info:
   2.109              del self.vnet[id]
   2.110 -            self.dbmap.delete(id)
   2.111              info.delete()
   2.112  
   2.113  def instance():
     3.1 --- a/tools/python/xen/xend/server/SrvVnetDir.py	Fri Aug 26 10:35:36 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvVnetDir.py	Fri Aug 26 10:51:10 2005 +0000
     3.3 @@ -19,6 +19,7 @@ from xen.xend import sxp
     3.4  from xen.xend.Args import FormFn
     3.5  from xen.xend import PrettyPrint
     3.6  from xen.xend import XendVnet
     3.7 +from xen.xend.XendError import XendError
     3.8  
     3.9  from xen.web.SrvDir import SrvDir
    3.10  
     4.1 --- a/tools/python/xen/xm/main.py	Fri Aug 26 10:35:36 2005 +0000
     4.2 +++ b/tools/python/xen/xm/main.py	Fri Aug 26 10:51:10 2005 +0000
     4.3 @@ -105,6 +105,11 @@ xm full list of subcommands:
     4.4          Limit the transmission rate of a virtual network interface
     4.5      network-list    <DomId>        List virtual network interfaces for a domain
     4.6  
     4.7 +  Vnet commands:
     4.8 +    vnet-list   [-l|--long]    list vnets
     4.9 +    vnet-create <config>       create a vnet from a config file
    4.10 +    vnet-delete <vnetid>       delete a vnet
    4.11 +
    4.12  For a short list of subcommands run 'xm help'
    4.13  For more help on xm see the xm(1) man page
    4.14  For more help on xm create, see the xmdomain.cfg(5) man page"""
    4.15 @@ -547,6 +552,47 @@ def xm_block_destroy(args):
    4.16      from xen.xend.XendClient import server
    4.17      server.xend_domain_device_destroy(dom, 'vbd', dev)
    4.18  
    4.19 +def xm_vnet_list(args):
    4.20 +    from xen.xend.XendClient import server
    4.21 +    try:
    4.22 +        (options, params) = getopt(args, 'l', ['long'])
    4.23 +    except GetoptError, opterr:
    4.24 +        err(opterr)
    4.25 +        sys.exit(1)
    4.26 +    
    4.27 +    use_long = 0
    4.28 +    for (k, v) in options:
    4.29 +        if k in ['-l', '--long']:
    4.30 +            use_long = 1
    4.31 +            
    4.32 +    if params:
    4.33 +        use_long = 1
    4.34 +        vnets = params
    4.35 +    else:
    4.36 +        vnets = server.xend_vnets()
    4.37 +    
    4.38 +    for vnet in vnets:
    4.39 +        try:
    4.40 +            if use_long:
    4.41 +                info = server.xend_vnet(vnet)
    4.42 +                PrettyPrint.prettyprint(info)
    4.43 +            else:
    4.44 +                print vnet
    4.45 +        except Exception, ex:
    4.46 +            print vnet, ex
    4.47 +
    4.48 +def xm_vnet_create(args):
    4.49 +    arg_check(args, 1, "vnet-create")
    4.50 +    conf = args[0]
    4.51 +    from xen.xend.XendClient import server
    4.52 +    server.xend_vnet_create(conf)
    4.53 +
    4.54 +def xm_vnet_delete(args):
    4.55 +    arg_check(args, 1, "vnet-delete")
    4.56 +    vnet = args[0]
    4.57 +    from xen.xend.XendClient import server
    4.58 +    server.xend_vnet_delete(vnet)
    4.59 +
    4.60  commands = {
    4.61      # console commands
    4.62      "console": xm_console,
    4.63 @@ -592,7 +638,11 @@ commands = {
    4.64      "block-refresh": xm_block_refresh,
    4.65      # network
    4.66      "network-limit": xm_network_limit,
    4.67 -    "network-list": xm_network_list
    4.68 +    "network-list": xm_network_list,
    4.69 +    # vnet
    4.70 +    "vnet-list": xm_vnet_list,
    4.71 +    "vnet-create": xm_vnet_create,
    4.72 +    "vnet-delete": xm_vnet_delete,
    4.73      }
    4.74  
    4.75  aliases = {