+ 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 (filedir,0777)
+ except:
+ raise PLCPermissionDenied, "Could not create dir %s"%filedir
+
+ return filename
+
+ # Build the command line to be executed
+ # according the node type
+ def build_command(self, node_type, build_sh_spec, node_image, type, floppy_file, log_file):
+
+ command = ""
+
+ # regular node, make build's arguments
+ # and build the full command line to be called
+ if node_type == 'regular':
+
+ build_sh_options=""
+ if "cramfs" in build_sh_spec:
+ type += "_cramfs"
+ if "serial" in build_sh_spec:
+ build_sh_options += " -s %s"%build_sh_spec['serial']
+
+ for karg in build_sh_spec['kargs']:
+ build_sh_options += ' -k "%s"'%karg
+
+ log_file="%s.log"%node_image
+
+ command = '%s -f "%s" -o "%s" -t "%s" %s &> %s' % (self.BOOTCDBUILD,
+ floppy_file,
+ node_image,
+ type,
+ build_sh_options,
+ log_file)
+ # dummynet node
+ elif node_type == 'dummynet':
+ # the build script expect the following parameters:
+ # the package base directory
+ # the working directory
+ # the full path of the configuration file
+ # the name of the resulting image file
+ # the type of the generated image
+ # the name of the log file
+ command = "%s -b %s -w %s -f %s -o %s -t %s -l %s" \
+ % (self.BOOTCDBUILD, self.BOOTCDDIR, self.WORKDIR,
+ floppy_file, node_image, type, log_file)
+ command = "touch %s %s; echo 'dummynet build script not yet supported'" \
+ % (log_file, node_image)
+
+ if self.DEBUG:
+ print "The build command line is %s" % command
+
+ return command
+
+ def call(self, auth, node_id_or_hostname, action, filename, options = []):
+
+ self.trash=[]
+
+ ### compute file suffix and type
+ if action.find("-iso") >= 0 :
+ suffix=".iso"
+ type = "iso"
+ elif action.find("-usb") >= 0:
+ suffix=".usb"
+ type = "usb"
+ else:
+ suffix=".txt"
+ type = "txt"
+
+ # check for node existence and get node_type
+ nodes = Nodes(self.api, [node_id_or_hostname])
+ if not nodes:
+ raise PLCInvalidArgument, "No such node %r"%node_id_or_hostname
+ node = nodes[0]
+
+ if self.DEBUG: print "%s required on node %s. Node type is: %s" \
+ % (action, node['node_id'], node['node_type'])
+
+ # check the required action against the node type
+ node_type = node['node_type']
+ if action not in allowed_actions[node_type]:
+ raise PLCInvalidArgument, "Action %s not valid for %s nodes, valid actions are %s" \
+ % (action, node_type, "|".join(allowed_actions[node_type]))
+
+ # handle / canonicalize options
+ if type == "txt":
+ if options:
+ raise PLCInvalidArgument, "Options are not supported for node configs"
+ else:
+ # create a dict for build.sh
+ build_sh_spec={'kargs':[]}
+ for option in options:
+ if option == "cramfs":
+ build_sh_spec['cramfs']=True
+ elif option == 'partition':
+ if type != "usb":
+ raise PLCInvalidArgument, "option 'partition' is for USB images only"
+ else:
+ type="usb_partition"
+ elif option == "serial":
+ build_sh_spec['serial']='default'
+ elif option.find("serial:") == 0:
+ build_sh_spec['serial']=option.replace("serial:","")
+ elif option == "no-hangcheck":
+ build_sh_spec['kargs'].append('hcheck_reboot0')
+ else:
+ raise PLCInvalidArgument, "unknown option %s"%option