Merge branch 'systemd'
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 20 Jan 2014 20:02:25 +0000 (21:02 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 20 Jan 2014 20:02:25 +0000 (21:02 +0100)
cgroups.py
sliver_libvirt.py

index bbb74a3..cbdfbe2 100644 (file)
@@ -56,6 +56,8 @@ def get_cgroup_paths(subsystem="cpuset"):
         os.path.join(BASE_DIR, subsystem, 'libvirt', 'lxc'),
         # as observed on f20
         os.path.join(BASE_DIR, subsystem ),
+        # as observed on f16 libvirt 1.2.1
+        os.path.join(BASE_DIR, subsystem, 'machine'),
         ]
     # try several locations and return all the results
     # get_cgroup_path will sort it out
@@ -68,9 +70,16 @@ def get_cgroup_paths(subsystem="cpuset"):
 
 def get_cgroup_path(name, subsystem="cpuset"):
     """ Returns the base path for the cgroup with a specific name or None."""
-    return reduce(lambda a, b: b if os.path.basename(b) == name else a,
+    result = reduce(lambda a, b: b if os.path.basename(b) == name else a,
                   get_cgroup_paths(subsystem), None)
 
+    if result is None:
+        name = name + ".libvirt-lxc"
+        result = reduce(lambda a, b: b if os.path.basename(b) == name else a,
+                      get_cgroup_paths(subsystem), None)
+
+    return result
+
 def get_base_path():
     return BASE_DIR
 
index 753b0c3..cad14cb 100644 (file)
@@ -4,6 +4,7 @@ import sys
 import os, os.path
 import subprocess
 import pprint
+import random
 
 import libvirt
 
@@ -171,14 +172,19 @@ class Sliver_Libvirt(Account):
         # Call the upper configure method (ssh keys...)
         Account.configure(self, rec)
 
+    @staticmethod
+    def get_unique_vif():
+        return 'veth%s' % random.getrandbits(32)
+
     # A placeholder until we get true VirtualInterface objects
     @staticmethod
     def get_interfaces_xml(rec):
         xml = """
     <interface type='network'>
       <source network='default'/>
+      <target dev='%s'/>
     </interface>
-"""
+""" % (Sliver_Libvirt.get_unique_vif())
         try:
             tags = rec['rspec']['tags']
             if 'interface' in tags:
@@ -198,14 +204,17 @@ class Sliver_Libvirt(Account):
           <source bridge='%s'/>
           %s
           <virtualport type='openvswitch'/>
+          <target dev='%s'/>
         </interface>
-    """ % (interface['bridge'], vlanxml)
+    """ % (interface['bridge'], vlanxml, Sliver_Libvirt.get_unique_vif())
                     else:
                         tag_xml = tag_xml + """
         <interface type='network'>
           <source network='default'/>
+          <target dev='%s'/>
         </interface>
-    """
+    """ % (Sliver_Libvirt.get_unique_vif())
+
                 xml = tag_xml
                 logger.log('sliver_libvirty.py: interface XML is: %s' % xml)