cosmetic changes only, pretty printing and comments, no change in behaviour
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 12 Nov 2015 19:01:03 +0000 (20:01 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 12 Nov 2015 19:01:03 +0000 (20:01 +0100)
account.py
sliver_libvirt.py
sliver_lxc.py
slivermanager.py

index 52ebb97..9f18024 100644 (file)
@@ -73,7 +73,8 @@ def get(name):
     try:
         if name not in name_worker: name_worker[name] = Worker(name)
         return name_worker[name]
-    finally: name_worker_lock.release()
+    finally:
+        name_worker_lock.release()
 
 
 class Account:
@@ -153,9 +154,11 @@ class Account:
     # which is a static method, they need to become static as well
     # needs to be done before sliver starts (checked with vs and lxc)
     @staticmethod
-    def mount_ssh_dir (slicename): return Account._manage_ssh_dir (slicename, do_mount=True)
+    def mount_ssh_dir (slicename):
+        return Account._manage_ssh_dir (slicename, do_mount=True)
     @staticmethod
-    def umount_ssh_dir (slicename): return Account._manage_ssh_dir (slicename, do_mount=False)
+    def umount_ssh_dir (slicename):
+        return Account._manage_ssh_dir (slicename, do_mount=False)
 
     # bind mount / umount root side dir to sliver side
     @staticmethod
@@ -225,7 +228,8 @@ class Worker:
                 # this sliver has the lease, it is safe to start it
                 if not self.is_running():
                     self.start(rec)
-                else: self.configure(rec)
+                else:
+                    self.configure(rec)
             else:
                 # not having the lease, do not start it
                 self.configure(rec)
@@ -266,20 +270,28 @@ class Worker:
         else:
             account_needs_reimage = self._acct.needs_reimage(target_slicefamily)
             if account_needs_reimage:
-                logger.log("Worker.needs_reimage ({}) - account needs reimage (tmp: DRY RUN)".format(self.name))
+                logger.log("Worker.needs_reimage ({}) - account needs reimage (tmp: DRY RUN)"
+                           .format(self.name))
             else:
-                logger.verbose("Worker.needs_reimage ({}) - everything fine".format(self.name))
+                logger.verbose("Worker.needs_reimage ({}) - everything fine"
+                               .format(self.name))
             return account_needs_reimage
     
     def _destroy(self, curr_class):
         self._acct = None
         if curr_class:
             destroy_sem.acquire()
-            try: curr_class.destroy(self.name)
-            finally: destroy_sem.release()
+            try:
+                logger.verbose("account._destroy is callling destroy from {}"
+                               .format(curr_class.__name__))
+                curr_class.destroy(self.name)
+            finally:
+                destroy_sem.release()
 
     def _get_class(self):
-        try: shell = pwd.getpwnam(self.name)[6]
-        except KeyError: return None
+        try:
+            shell = pwd.getpwnam(self.name)[6]
+        except KeyError:
+            return None
         return shell_acct_class[shell]
 
index f62c1a7..e898c4b 100644 (file)
@@ -168,6 +168,7 @@ class Sliver_Libvirt(Account):
         bwlimit.ebtables("-A INPUT -i veth{} -j mark --set-mark {}"
                          .format(self.xid, self.xid))
 
+    ### this is confusing, because it seems it is not used in fact
     def stop(self):
         logger.verbose('sliver_libvirt: {} stop'.format(self.name))
 
index 320c546..9737497 100644 (file)
@@ -180,7 +180,7 @@ class Sliver_LXC(Sliver_Libvirt, Initscript):
                    'ssh-keygen -t rsa -N "" -f /home/{}/.ssh/id_rsa'.format(name)]
         logger.log_call(command)
 
-        command = ['chown', '-R', '{}.slices'.format(name), '/home/{}/.ssh'.format(name)]
+        command = ['chown', '-R', '{}:slices'.format(name), '/home/{}/.ssh'.format(name)]
         logger.log_call(command)
 
         command = ['mkdir', '{}/root/.ssh'.format(containerDir)]
index eb0a096..4a3c3eb 100644 (file)
@@ -35,10 +35,12 @@ except:
         exit(1)
 
 # just being safe
-try : from plnode.bwlimit import bwmin, bwmax
-except: bwmin, bwmax = 8, 1000*1000*1000
+try:
+    from plnode.bwlimit import bwmin, bwmax
+except:
+    bwmin, bwmax = 8, 1000*1000*1000
 
-priority=10
+priority = 10
 
 
 DEFAULT_ALLOCATION = {
@@ -136,9 +138,12 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True):
     node_id = None
     try:
         f = open('/etc/planetlab/node_id')
-        try: node_id = int(f.read())
-        finally: f.close()
-    except: logger.log_exc("slivermanager: GetSlivers failed to read /etc/planetlab/node_id")
+        try:
+            node_id = int(f.read())
+        finally:
+            f.close()
+    except:
+        logger.log_exc("slivermanager: GetSlivers failed to read /etc/planetlab/node_id")
 
     if data.has_key('node_id') and data['node_id'] != node_id: return
 
@@ -186,7 +191,7 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True):
         # if tag 'initscript_code' is set, that's what we use
         iscode = attributes.get('initscript_code', '')
         if iscode:
-            rec['initscript']=iscode
+            rec['initscript'] = iscode
         else:
             isname = attributes.get('initscript')
             if isname is not None and isname in iscripts_hash:
@@ -213,10 +218,11 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True):
                 rspec[key] = attributes[key]
 
         # also export tags in rspec so they make it to the sliver_vs.start call
-        rspec['tags']=attributes
+        rspec['tags'] = attributes
 
         database.db.deliver_record(rec)
-    if fullupdate: database.db.set_min_timestamp(data['timestamp'])
+    if fullupdate:
+        database.db.set_min_timestamp(data['timestamp'])
     # slivers are created here.
     database.db.sync()