'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,
( 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()
type = "txt"
# handle / caconicalize options
- if type is "txt":
+ if type == "txt":
if options:
raise PLCInvalidArgument, "Options are not supported for node configs"
else:
# create a dict for build.sh
optdict={}
for option in options:
- if option is "cramfs":
+ if option == "cramfs":
optdict['cramfs']=True
- elif option is 'partition':
- if type is not "usb":
+ elif option == 'partition':
+ if type != "usb":
raise PLCInvalidArgument, "option 'partition' is for USB images only"
else:
type="usb_partition"
- elif option is "serial":
+ elif option == "serial":
optdict['serial']='default'
elif option.find("serial:") == 0:
optdict['serial']=option.replace("serial:","")
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)
### 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