All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Wray <mike.wray@hp.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] Fix vnets in xm
Date: Fri, 26 Aug 2005 09:10:24 +0100	[thread overview]
Message-ID: <430ECE70.1050207@hp.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

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>

[-- Attachment #2: xm-vnet-2005-08-26.diff --]
[-- Type: text/plain, Size: 6731 bytes --]

diff -r 9fb0bad776dd tools/python/xen/util/Brctl.py
--- a/tools/python/xen/util/Brctl.py	Thu Aug 25 18:49:48 2005
+++ b/tools/python/xen/util/Brctl.py	Fri Aug 26 08:58:30 2005
@@ -76,6 +76,7 @@
 def bridge_del(bridge):
     """Delete a bridge.
     """
+    cmd(CMD_IFCONFIG, '%s down' % bridge)
     cmd(CMD_BRCTL, 'delbr %s' % bridge)
 
 def routes():
diff -r 9fb0bad776dd tools/python/xen/xend/XendVnet.py
--- a/tools/python/xen/xend/XendVnet.py	Thu Aug 25 18:49:48 2005
+++ b/tools/python/xen/xend/XendVnet.py	Fri Aug 26 08:58:30 2005
@@ -22,7 +22,7 @@
 from xen.xend import sxp
 from xen.xend.XendError import XendError
 from xen.xend.XendLogging import log
-from xen.xend.xenstore import XenNode, DBMap
+from xen.xend.xenstore import XenNode, DBMap, DBVar
 
 def vnet_cmd(cmd):
     out = None
@@ -38,17 +38,40 @@
 class XendVnetInfo:
     
     vifctl_ops = {'up': 'vif.add', 'down': 'vif.del'}
+
+    __exports__ = [
+        DBVar('id',     ty='str'),
+        DBVar('dbid',   ty='str'),
+        DBVar('config', ty='sxpr'),
+       ]
     
-    def __init__(self, config):
-        self.config = config
-        self.id = sxp.child_value(config, 'id')
-        self.id = str(self.id)
+    def __init__(self, db, config=None):
+        if config:
+            self.id = sxp.child_value(config, 'id')
+            self.id = str(self.id)
+            self.dbid = self.id.replace(':', '-')
+            self.db = db.addChild(self.dbid)
+            self.config = config
+        else:
+            self.db = db
+            self.importFromDB()
+            config = self.config
+            
         self.bridge = sxp.child_value(config, 'bridge')
         if not self.bridge:
             self.bridge = "vnet%s" % self.id
         self.vnetif = sxp.child_value(config, 'vnetif')
         if not self.vnetif:
-            self.vnetif = "vnetif%s" % self.id
+            self.vnetif = "vnif%s" % self.id
+
+    def saveToDB(self, save=False, sync=False):
+        self.db.saveDB(save=save, sync=sync)
+
+    def exportToDB(self, save=False, sync=False):
+        self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
+
+    def importFromDB(self):
+        self.db.importFromDB(self, fields=self.__exports__)
 
     def sxpr(self):
         return self.config
@@ -64,7 +87,9 @@
         log.info("Deleting vnet %s", self.id)
         Brctl.vif_bridge_rem({'bridge': self.bridge, 'vif': self.vnetif})
         Brctl.bridge_del(self.bridge)
-        return vnet_cmd(['vnet.del', self.id])
+        val = vnet_cmd(['vnet.del', self.id])
+        self.db.delete()
+        return val
 
     def vifctl(self, op, vif, vmac):
         try:
@@ -82,16 +107,18 @@
     def __init__(self):
         # Table of vnet info indexed by vnet id.
         self.vnet = {}
-        self.dbmap = DBMap(db=XenNode(self.dbpath))
-        self.dbmap.readDB()
-        for vnetdb in self.dbmap.values():
-            config = vnetdb.config
-            info = XendVnetInfo(config)
-            self.vnet[info.id] = info
+        self.db = DBMap(db=XenNode(self.dbpath))
+        self.db.readDB()
+        for vnetdb in self.db.values():
             try:
+                info = XendVnetInfo(vnetdb)
+                self.vnet[info.id] = info
                 info.configure()
             except XendError, ex:
                 log.warning("Failed to configure vnet %s: %s", str(info.id), str(ex))
+            except Exception, ex:
+                log.exception("Vnet error")
+                vnetdb.delete()
 
     def vnet_of_bridge(self, bridge):
         """Get the vnet for a bridge (if any).
@@ -128,9 +155,9 @@
 
         @param config: config
         """
-        info = XendVnetInfo(config)
+        info = XendVnetInfo(self.db, config=config)
         self.vnet[info.id] = info
-        self.dbmap["%s/config" % info.id] = info.sxpr()
+        info.saveToDB()
         info.configure()
 
     def vnet_delete(self, id):
@@ -141,7 +168,6 @@
         info = self.vnet_get(id)
         if info:
             del self.vnet[id]
-            self.dbmap.delete(id)
             info.delete()
 
 def instance():
diff -r 9fb0bad776dd tools/python/xen/xend/server/SrvVnetDir.py
--- a/tools/python/xen/xend/server/SrvVnetDir.py	Thu Aug 25 18:49:48 2005
+++ b/tools/python/xen/xend/server/SrvVnetDir.py	Fri Aug 26 08:58:30 2005
@@ -19,6 +19,7 @@
 from xen.xend.Args import FormFn
 from xen.xend import PrettyPrint
 from xen.xend import XendVnet
+from xen.xend.XendError import XendError
 
 from xen.web.SrvDir import SrvDir
 
diff -r 9fb0bad776dd tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py	Thu Aug 25 18:49:48 2005
+++ b/tools/python/xen/xm/main.py	Fri Aug 26 08:58:30 2005
@@ -104,6 +104,11 @@
     network-limit   <DomId> <Vif> <Credit> <Period>
         Limit the transmission rate of a virtual network interface
     network-list    <DomId>        List virtual network interfaces for a domain
+
+  Vnet commands:
+    vnet-list   [-l|--long]    list vnets
+    vnet-create <config>       create a vnet from a config file
+    vnet-delete <vnetid>       delete a vnet
 
 For a short list of subcommands run 'xm help'
 For more help on xm see the xm(1) man page
@@ -546,6 +551,47 @@
 
     from xen.xend.XendClient import server
     server.xend_domain_device_destroy(dom, 'vbd', dev)
+
+def xm_vnet_list(args):
+    from xen.xend.XendClient import server
+    try:
+        (options, params) = getopt(args, 'l', ['long'])
+    except GetoptError, opterr:
+        err(opterr)
+        sys.exit(1)
+    
+    use_long = 0
+    for (k, v) in options:
+        if k in ['-l', '--long']:
+            use_long = 1
+            
+    if params:
+        use_long = 1
+        vnets = params
+    else:
+        vnets = server.xend_vnets()
+    
+    for vnet in vnets:
+        try:
+            if use_long:
+                info = server.xend_vnet(vnet)
+                PrettyPrint.prettyprint(info)
+            else:
+                print vnet
+        except Exception, ex:
+            print vnet, ex
+
+def xm_vnet_create(args):
+    arg_check(args, 1, "vnet-create")
+    conf = args[0]
+    from xen.xend.XendClient import server
+    server.xend_vnet_create(conf)
+
+def xm_vnet_delete(args):
+    arg_check(args, 1, "vnet-delete")
+    vnet = args[0]
+    from xen.xend.XendClient import server
+    server.xend_vnet_delete(vnet)
 
 commands = {
     # console commands
@@ -592,7 +638,11 @@
     "block-refresh": xm_block_refresh,
     # network
     "network-limit": xm_network_limit,
-    "network-list": xm_network_list
+    "network-list": xm_network_list,
+    # vnet
+    "vnet-list": xm_vnet_list,
+    "vnet-create": xm_vnet_create,
+    "vnet-delete": xm_vnet_delete,
     }
 
 aliases = {

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2005-08-26  8:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-26  8:10 Mike Wray [this message]
2005-08-26 10:54 ` [PATCH] Fix vnets in xm Christian Limpach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=430ECE70.1050207@hp.com \
    --to=mike.wray@hp.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.