svn merge -c 8998 ./branches/dummynet-4.2-2 ./trunk/
[plcapi.git] / PLC / Methods / GetBootMedium.py
index 8f6c49b..4e66c5c 100644 (file)
@@ -22,6 +22,18 @@ boot_medium_actions = [ 'node-preview',
                         'generic-usb',
                         ]
 
+# compute a new key
+# xxx used by GetDummyBoxMedium
+def compute_key():
+    # Generate 32 random bytes
+    bytes = random.sample(xrange(0, 256), 32)
+    # Base64 encode their string representation
+    key = base64.b64encode("".join(map(chr, bytes)))
+    # Boot Manager cannot handle = in the key
+    # XXX this sounds wrong, as it might prevent proper decoding
+    key = key.replace("=", "")
+    return key
+
 class GetBootMedium(Method):
     """
     This method is a redesign based on former, supposedly dedicated, 
@@ -149,12 +161,7 @@ class GetBootMedium(Method):
         ( host, domain ) = self.split_hostname (node)
 
         if renew_key:
-            # Generate 32 random bytes
-            bytes = random.sample(xrange(0, 256), 32)
-            # Base64 encode their string representation
-            node['key'] = base64.b64encode("".join(map(chr, bytes)))
-            # XXX Boot Manager cannot handle = in the key
-            node['key'] = node['key'].replace("=", "")
+            node['key'] = compute_key()
             # Save it
             node.sync()
 
@@ -281,6 +288,8 @@ class GetBootMedium(Method):
             nodename = temp
             
         ### handle filename
+        # allow to set filename to None or any other empty value
+        if not filename: filename=''
         filename = filename.replace ("%d",self.WORKDIR)
         filename = filename.replace ("%n",nodename)
         filename = filename.replace ("%s",suffix)
@@ -301,11 +310,14 @@ class GetBootMedium(Method):
 
             ### we can now safely create the file, 
             ### either we are admin or under a controlled location
-            if not os.path.exists(os.path.dirname(filename)):
-                try:
-                    os.makedirs (os.path.dirname(filename),0777)
-                except:
-                    raise PLCPermissionDenied, "Could not create dir %s"%os.path.dirname(filename)
+            filedir=os.path.dirname(filename)
+            # dirname does not return "." for a local filename like its shell counterpart
+            if filedir:
+                if not os.path.exists(filedir):
+                    try:
+                        os.makedirs (dirname,0777)
+                    except:
+                        raise PLCPermissionDenied, "Could not create dir %s"%dirname
 
         
         ### generic media