handling generic images - %a in filename gets replaced by arch
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 23 Apr 2008 15:53:15 +0000 (15:53 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 23 Apr 2008 15:53:15 +0000 (15:53 +0000)
PLC/Methods/GetBootMedium.py

index 0e76035..94651b7 100644 (file)
@@ -80,6 +80,7 @@ class GetBootMedium(Method):
         - %v : the bootcd version string (e.g. 4.0)
         - %p : the PLC name
         - %f : the nodefamily
+        - %a : arch
         With the file-based return mechanism, the method returns the full pathname 
         of the result file; 
         ** WARNING **
@@ -223,6 +224,9 @@ class GetBootMedium(Method):
         except:
             (pldistro,arch) = ("planetlab","i386")
             
+        if not node:
+            return (pldistro,arch)
+
         known_archs = [ 'i386', 'x86_64' ]
         nodegroupnames = [ ng['name'] for ng in NodeGroups (self.api, node['nodegroup_ids'],['name'])]
         # (1) if groupname == arch, nodefamily becomes pldistro-groupname
@@ -305,12 +309,6 @@ class GetBootMedium(Method):
                 raise PLCInvalidArgument, "No such node %r"%node_id_or_hostname
             node = nodes[0]
             nodename = node['hostname']
-            # get nodefamily
-            (pldistro,arch) = self.get_nodefamily(node)
-            self.nodefamily="%s-%s"%(pldistro,arch)
-            # apply on globals
-            for attr in [ "BOOTCDDIR", "BOOTCDBUILD", "GENERICDIR" ]:
-                setattr(self,attr,getattr(self,attr).replace("@NODEFAMILY@",self.nodefamily))
 
         else:
             node = None
@@ -318,6 +316,13 @@ class GetBootMedium(Method):
             tempbytes = random.sample (xrange(0,256), 8);
             def hexa2 (c): return chr((c>>4)+65) + chr ((c&16)+65)
             nodename = "".join(map(hexa2,tempbytes))
+
+        # get nodefamily
+        (pldistro,arch) = self.get_nodefamily(node)
+        self.nodefamily="%s-%s"%(pldistro,arch)
+        # apply on globals
+        for attr in [ "BOOTCDDIR", "BOOTCDBUILD", "GENERICDIR" ]:
+            setattr(self,attr,getattr(self,attr).replace("@NODEFAMILY@",self.nodefamily))
             
         ### handle filename
         # allow to set filename to None or any other empty value
@@ -327,14 +332,12 @@ class GetBootMedium(Method):
         filename = filename.replace ("%s",suffix)
         filename = filename.replace ("%p",self.api.config.PLC_NAME)
         # let's be cautious
-        try:
-            filename = filename.replace ("%f", self.nodefamily)
-        except:
-            pass
-        try:
-            filename = filename.replace ("%v",self.bootcd_version())
-        except:
-            pass
+        try: filename = filename.replace ("%f", self.nodefamily)
+        except: pass
+        try: filename = filename.replace ("%a", arch)
+        except: pass
+        try: filename = filename.replace ("%v",self.bootcd_version())
+        except: pass
 
         ### Check filename location
         if filename != '':