Improve robustness of LXC and libvirt plugins.
[nodemanager.git] / sliver_libvirt.py
index 209cb71..a3578eb 100644 (file)
@@ -1,6 +1,6 @@
 """LibVirt slivers"""
 
-import accounts
+import account
 import logger
 import subprocess
 import os
@@ -42,7 +42,7 @@ def debuginfo(dom):
 
 # Common Libvirt code
 
-class Sliver_Libvirt(accounts.Account):
+class Sliver_Libvirt(account.Account):
 
     def __init__(self, rec):
         self.name = rec['name']
@@ -58,11 +58,15 @@ class Sliver_Libvirt(accounts.Account):
         self.conn = getConnection(rec['type'])
         self.xid = bwlimit.get_xid(self.name)
 
+        dom = None
         try:
-            self.dom = self.conn.lookupByName(self.name)
+            dom = self.conn.lookupByName(self.name)
         except:
-            logger.log('sliver_libvirt: Domain %s does not exist ' \
-                       'UNEXPECTED: %s'%(self.name, sys.exc_info()[1]))
+            logger.log('sliver_libvirt: Domain %s does not exist. ' \
+                       'Will try to create it again.' \ % (self.name))
+            self.__class__.create(rec['name'], rec)
+            dom = self.conn.lookupByName(self.name)
+        self.dom = dom
 
     def start(self, delay=0):
         ''' Just start the sliver '''
@@ -157,5 +161,5 @@ class Sliver_Libvirt(accounts.Account):
             cgroups.write(self.name, 'cpu.shares', cpu_share)
 
         # Call the upper configure method (ssh keys...)
-        accounts.Account.configure(self, rec)
+        account.Account.configure(self, rec)