Add openvswitch to tag level
[nodemanager.git] / sliver_libvirt.py
index 56ab8ac..778eb10 100644 (file)
@@ -9,7 +9,7 @@ import libvirt
 
 from account import Account
 import logger
-import bwlimit
+import plnode.bwlimit as bwlimit
 import cgroups
 
 STATES = {
@@ -55,7 +55,7 @@ class Sliver_Libvirt(Account):
         self.rspec = {}
         self.slice_id = rec['slice_id']
         self.enabled = True
-        self.conn = getConnection(rec['type'])
+        self.conn = Sliver_Libvirt.getConnection(rec['type'])
         self.xid = bwlimit.get_xid(self.name)
 
         dom = None
@@ -63,7 +63,7 @@ class Sliver_Libvirt(Account):
             dom = self.conn.lookupByName(self.name)
         except:
             logger.log('sliver_libvirt: Domain %s does not exist. ' \
-                       'Will try to create it again.' % (self.name))
+                       'Will try to create it again.' % (self.name))
             self.__class__.create(rec['name'], rec)
             dom = self.conn.lookupByName(self.name)
         self.dom = dom
@@ -163,3 +163,28 @@ class Sliver_Libvirt(Account):
         # Call the upper configure method (ssh keys...)
         Account.configure(self, rec)
 
+    # A placeholder until we get true VirtualInterface objects
+    @staticmethod
+    def get_interfaces_xml(rec):
+        xml = """
+    <interface type='network'>
+      <source network='default'/>
+    </interface>
+"""
+        try:
+            tags = rec['rspec']['tags']
+            if 'interface' in tags:
+                interface = eval(tags['interface'])
+                if 'bridge' in interface:
+                    xml = """
+    <interface type='bridge'>
+      <source bridge='%s'/>
+      <virtualport type='openvswitch'/>
+    </interface>
+""" % interface['bridge']
+                    logger.log('sliver_libvirty.py: interface XML is: %s' % xml)
+        except:
+            logger.log('sliver_libvirt.py: ERROR parsing "interface" tag for slice %s' % rec['name'])
+            logger.log('sliver_libvirt.py: tag value: %s' % tags['interface'])
+
+        return xml