[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Fix vnets in xm.



# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID a43cc4e06814859cffe6ea09e07d6e87f6fec6ab
# Parent  581be7c5e9e4e1ff2ba29561478786d4b4f59465
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@xxxxxx>
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>

diff -r 581be7c5e9e4 -r a43cc4e06814 tools/python/xen/util/Brctl.py
--- a/tools/python/xen/util/Brctl.py    Fri Aug 26 10:35:36 2005
+++ b/tools/python/xen/util/Brctl.py    Fri Aug 26 10:51:10 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 581be7c5e9e4 -r a43cc4e06814 tools/python/xen/xend/XendVnet.py
--- a/tools/python/xen/xend/XendVnet.py Fri Aug 26 10:35:36 2005
+++ b/tools/python/xen/xend/XendVnet.py Fri Aug 26 10:51:10 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 581be7c5e9e4 -r a43cc4e06814 tools/python/xen/xend/server/SrvVnetDir.py
--- a/tools/python/xen/xend/server/SrvVnetDir.py        Fri Aug 26 10:35:36 2005
+++ b/tools/python/xen/xend/server/SrvVnetDir.py        Fri Aug 26 10:51:10 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 581be7c5e9e4 -r a43cc4e06814 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Fri Aug 26 10:35:36 2005
+++ b/tools/python/xen/xm/main.py       Fri Aug 26 10:51:10 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 = {

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.