review imports in sliver_{libvirt,lxc}
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Jun 2012 21:20:37 +0000 (23:20 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Jun 2012 21:20:37 +0000 (23:20 +0200)
sliver_libvirt.py
sliver_lxc.py

index a3578eb..56ab8ac 100644 (file)
@@ -1,18 +1,16 @@
 """LibVirt slivers"""
 
-import account
-import logger
+import sys
+import os, os.path
 import subprocess
-import os
-import os.path
+import pprint
+
 import libvirt
-import sys
-import shutil
+
+from account import Account
+import logger
 import bwlimit
 import cgroups
-import pprint
-
-from string import Template
 
 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']
@@ -161,5 +161,5 @@ 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)
 
index 1b1a20c..246c5f0 100644 (file)
@@ -11,9 +11,9 @@ from string import Template
 
 import logger
 import bwlimit
-import sliver_libvirt
+from sliver_libvirt import Sliver_Libvirt
 
-class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
+class Sliver_LXC(Sliver_Libvirt):
     """This class wraps LXC commands"""
 
     SHELL = '/bin/sshsh'
@@ -28,7 +28,7 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
     def create(name, rec=None):
         ''' Create dirs, copy fs image, lxc_create '''
         logger.verbose ('sliver_lxc: %s create'%(name))
-        conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+        conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
 
         # Get the type of image from vref myplc tags specified as:
         # pldistro = lxc
@@ -122,13 +122,13 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
             dom = conn.lookupByName(name)
         except:
             dom = conn.defineXML(xml)
-        logger.verbose('lxc_create: %s -> %s'%(name, sliver_libvirt.debuginfo(dom)))
+        logger.verbose('lxc_create: %s -> %s'%(name, Sliver_Libvirt.debuginfo(dom)))
 
 
     @staticmethod
     def destroy(name):
         logger.verbose ('sliver_lxc: %s destroy'%(name))
-        conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+        conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
 
         containerDir = Sliver_LXC.CON_BASE_DIR + '/%s'%(name)