X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_libvirt.py;h=4eb86af7dd12606303e356b3f9a8f6747c987fae;hb=refs%2Fheads%2Fpackaging;hp=1517ad5631904adb068c7b19d1b74bf77e0bff4e;hpb=62b1e16f80b701c21abab3d000e620d2afdd96d0;p=nodemanager.git diff --git a/sliver_libvirt.py b/sliver_libvirt.py index 1517ad5..4eb86af 100644 --- a/sliver_libvirt.py +++ b/sliver_libvirt.py @@ -2,6 +2,7 @@ import sys import os, os.path +import re import subprocess import pprint import random @@ -96,7 +97,19 @@ class Sliver_Libvirt(Account): else: output += Sliver_Libvirt.dom_details (dom) return output - + + def repair_veth(self): + # See workaround email, 2-14-2014, "libvirt 1.2.1 rollout" + xml = open("/etc/libvirt/lxc/%s.xml" % self.name).read() + veths = re.findall("", xml) + veths = [x[13:-3] for x in veths] + for veth in veths: + command = ["ip", "link", "delete", veth] + logger.log_call(command) + + logger.log("trying to redefine the VM") + command = ["virsh", "define", "/etc/libvirt/lxc/%s.xml" % self.name] + logger.log_call(command) def start(self, delay=0): ''' Just start the sliver ''' @@ -105,7 +118,18 @@ class Sliver_Libvirt(Account): # Check if it's running to avoid throwing an exception if the # domain was already running, create actually means start if not self.is_running(): - self.dom.create() + try: + self.dom.create() + except Exception, e: + # XXX smbaker: attempt to resolve slivers that are stuck in + # "failed to allocate free veth". + if "ailed to allocate free veth" in str(e): + logger.log("failed to allocate free veth on %s" % self.name) + self.repair_veth() + logger.log("trying dom.create again") + self.dom.create() + else: + raise else: logger.verbose('sliver_libvirt: sliver %s already started'%(self.name))