X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_libvirt.py;h=ed430885894c85a7a5312a56836caac849af9a7f;hb=37fb58922dd8b6429ccb4a2b94d4ca907ee83232;hp=a3578eb7860b8762d51b7485fa8e6bf1e2440359;hpb=6ec82e6a49df218bcbf4337d85d8d87dc8273824;p=nodemanager.git
diff --git a/sliver_libvirt.py b/sliver_libvirt.py
index a3578eb..ed43088 100644
--- a/sliver_libvirt.py
+++ b/sliver_libvirt.py
@@ -1,18 +1,16 @@
"""LibVirt slivers"""
-import account
-import logger
-import subprocess
-import os
-import os.path
-import libvirt
import sys
-import shutil
-import bwlimit
-import cgroups
+import os, os.path
+import subprocess
import pprint
-from string import Template
+import libvirt
+
+from account import Account
+import logger
+import plnode.bwlimit as bwlimit
+import cgroups
STATES = {
libvirt.VIR_DOMAIN_NOSTATE: 'no state',
@@ -26,23 +24,25 @@ STATES = {
connections = dict()
-# Helper methods
+# Common Libvirt code
-def getConnection(sliver_type):
- # TODO: error checking
- # vtype is of the form sliver.[LXC/QEMU] we need to lower case to lxc/qemu
- vtype = sliver_type.split('.')[1].lower()
- uri = vtype + '://'
- return connections.setdefault(uri, libvirt.open(uri))
+class Sliver_Libvirt(Account):
-def debuginfo(dom):
- ''' Helper method to get a "nice" output of the info struct for debug'''
- [state, maxmem, mem, ncpu, cputime] = dom.info()
- return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), STATES.get(state, state), maxmem, mem, ncpu, cputime)
+ # Helper methods
-# Common Libvirt code
+ @staticmethod
+ def getConnection(sliver_type):
+ # TODO: error checking
+ # vtype is of the form sliver.[LXC/QEMU] we need to lower case to lxc/qemu
+ vtype = sliver_type.split('.')[1].lower()
+ uri = vtype + '://'
+ return connections.setdefault(uri, libvirt.open(uri))
-class Sliver_Libvirt(account.Account):
+ @staticmethod
+ def debuginfo(dom):
+ ''' Helper method to get a "nice" output of the info struct for debug'''
+ [state, maxmem, mem, ncpu, cputime] = dom.info()
+ return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), STATES.get(state, state), maxmem, mem, ncpu, cputime)
def __init__(self, rec):
self.name = rec['name']
@@ -55,7 +55,7 @@ class Sliver_Libvirt(account.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.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
@@ -161,5 +161,48 @@ class Sliver_Libvirt(account.Account):
cgroups.write(self.name, 'cpu.shares', cpu_share)
# Call the upper configure method (ssh keys...)
- account.Account.configure(self, rec)
+ Account.configure(self, rec)
+
+ # A placeholder until we get true VirtualInterface objects
+ @staticmethod
+ def get_interfaces_xml(rec):
+ xml = """
+
+
+
+"""
+ try:
+ tags = rec['rspec']['tags']
+ if 'interface' in tags:
+ interfaces = eval(tags['interface'])
+ if not isinstance(interfaces, (list, tuple)):
+ # if interface is not a list, then make it into a singleton list
+ interfaces = [interfaces]
+ tag_xml = ""
+ for interface in interfaces:
+ if 'vlan' in interface:
+ vlanxml = "" % interface['vlan']
+ else:
+ vlanxml = ""
+ if 'bridge' in interface:
+ tag_xml = tag_xml + """
+
+
+ %s
+
+
+ """ % (interface['bridge'], vlanxml)
+ else:
+ tag_xml = tag_xml + """
+
+
+
+ """
+ xml = tag_xml
+ 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