oops, too much messing about
[nodemanager.git] / sliver_vs.py
index 1d90f16..c4dfadb 100644 (file)
@@ -84,11 +84,10 @@ class Sliver_VS(vserver.VServer, Account, Initscript):
         logger.verbose('sliver_vs: %s: create'%name)
         vref = rec['vref']
         if vref is None:
-            logger.log("sliver_vs: %s: ERROR - no vref attached, this is unexpected"%(name))
             # added by caglar
             # band-aid for short period as old API doesn't have GetSliceFamily function
-            #return
             vref = "planetlab-f8-i386"
+            logger.log("sliver_vs: %s: ERROR - no vref attached, using hard-wired default %s"%(name,vref))
 
         # used to look in /etc/planetlab/family,
         # now relies on the 'GetSliceFamily' extra attribute in GetSlivers()
@@ -99,7 +98,7 @@ class Sliver_VS(vserver.VServer, Account, Initscript):
             logger.log ("sliver_vs: %s: ERROR Could not create sliver - vreference image %s not found"%(name,vref))
             return
 
-        # guess arch
+        # compute guest personality
         try:
             (x,y,arch)=vref.split('-')
         # mh, this of course applies when 'vref' is e.g. 'netflow'
@@ -107,11 +106,7 @@ class Sliver_VS(vserver.VServer, Account, Initscript):
         except:
             arch='i386'
 
-        def personality (arch):
-            personality="linux32"
-            if arch.find("64")>=0:
-                personality="linux64"
-            return personality
+        def personality (arch): return "linux64" if arch.find("64") >=0 else "linux32"
 
         command=[]
         # be verbose
@@ -134,8 +129,15 @@ class Sliver_VS(vserver.VServer, Account, Initscript):
 
     @staticmethod
     def destroy(name):
+        # need to umount before we trash, otherwise we end up with sequels in 
+        # /vservers/slicename/ (namely in home/ )
+        # also because this is a static method we cannot check for 'omf_control'
+        # but it is no big deal as umount_ssh_dir checks before it umounts..
+        Account.umount_ssh_dir(name)
+        logger.log("sliver_vs: destroying %s"%name)
         logger.log_call(['/bin/bash','-x','/usr/sbin/vuserdel', name, ])
 
+
     def configure(self, rec):
         # in case we update nodemanager..
         self.install_and_enable_vinit()
@@ -150,28 +152,29 @@ class Sliver_VS(vserver.VServer, Account, Initscript):
 
         Account.configure(self, rec)  # install ssh keys
 
+    # remember configure() always gets called *before* start()
     def start(self, delay=0):
         if self.rspec['enabled'] <= 0:
             logger.log('sliver_vs: not starting %s, is not enabled'%self.name)
+            return
+        logger.log('sliver_vs: %s: starting in %d seconds' % (self.name, delay))
+        time.sleep(delay)
+        # the generic /etc/init.d/vinit script is permanently refreshed, and enabled
+        self.install_and_enable_vinit()
+        # expose .ssh for omf_friendly slivers
+        if 'omf_control' in self.rspec['tags']:
+            Account.mount_ssh_dir(self.name)
+        # if a change has occured in the slice initscript, reflect this in /etc/init.d/vinit.slice
+        self.refresh_slice_vinit()
+        child_pid = os.fork()
+        if child_pid == 0:
+            # VServer.start calls fork() internally,
+            # so just close the nonstandard fds and fork once to avoid creating zombies
+            tools.close_nonstandard_fds()
+            vserver.VServer.start(self)
+            os._exit(0)
         else:
-            logger.log('sliver_vs: %s: starting in %d seconds' % (self.name, delay))
-            time.sleep(delay)
-            # the generic /etc/init.d/vinit script is permanently refreshed, and enabled
-            self.install_and_enable_vinit()
-            # expose .ssh for omf_friendly slivers
-            if 'omf_control' in self.rspec['tags']:
-                self.expose_ssh_dir()
-            # if a change has occured in the slice initscript, reflect this in /etc/init.d/vinit.slice
-            self.refresh_slice_vinit()
-            child_pid = os.fork()
-            if child_pid == 0:
-                # VServer.start calls fork() internally,
-                # so just close the nonstandard fds and fork once to avoid creating zombies
-                tools.close_nonstandard_fds()
-                vserver.VServer.start(self)
-                os._exit(0)
-            else:
-                os.waitpid(child_pid, 0)
+            os.waitpid(child_pid, 0)
 
     def stop(self):
         logger.log('sliver_vs: %s: stopping' % self.name)