def _prepare_tasks(self): self._tasks = [] for task_data in self._recipe["tasks"]: task = {} task["quit_on_fail"] = False if "quit_on_fail" in task_data: task["quit_on_fail"] = bool_it(task_data["quit_on_fail"]) if "module_dir" in task_data: task["module_dir"] = task_data["module_dir"] if "tools_dir" in task_data: task["tools_dir"] = task_data["tools_dir"] if "python" in task_data: root = RecipePath(None, self._recipe_path).get_root() path = RecipePath(root, task_data["python"]) task["python"] = path if not path.exists(): msg = "Task file '%s' not found." % path raise RecipeError(msg, task_data) self._tasks.append(task) continue task["commands"] = task_data["commands"] task["skeleton"] = [] for cmd_data in task["commands"]: cmd = {"type": cmd_data["type"]} if "host" in cmd_data: cmd["host"] = cmd_data["host"] if cmd["host"] not in self._machines: msg = "Invalid host id '%s'." % cmd["host"] raise RecipeError(msg, cmd_data) if cmd["type"] in ["test", "exec"]: if "bg_id" in cmd_data: cmd["bg_id"] = cmd_data["bg_id"] elif cmd["type"] in ["wait", "intr", "kill"]: cmd["proc_id"] = cmd_data["bg_id"] task["skeleton"].append(cmd) if self._check_task(task): raise RecipeError("Incorrect command sequence.", task_data) self._tasks.append(task)
def _process_node(self, node, handler, params): old_include_root = None if self._has_attribute(node, "source"): source = self._get_attribute(node, "source") source_rp = RecipePath(self._include_root, source) old_include_root = self._include_root self._include_root = source_rp.get_root() xmlstr = source_rp.to_str() dom_init = XmlDomTreeInit() try: dom = dom_init.parse_string(xmlstr, filename=source_rp.abs_path()) except IOError as err: msg = "Unable to resolve include: %s" % str(err) raise XmlProcessingError(msg, node) loaded_node = None try: loaded_node = dom.getElementsByTagName(node.nodeName)[0] except Exception: msg = ("No '%s' element present in included file '%s'." % (node.nodeName, source_rp.abs_path())) raise XmlProcessingError(msg, node) old_attrs = self._get_all_attributes(node) parent = node.parentNode parent.replaceChild(loaded_node, node) node = loaded_node # copy all of the original attributes to the sourced node for name, value in old_attrs.iteritems(): # do not overwrite sourced attributes if not node.hasAttribute(name): node.setAttribute(name, value) parent = super(LnstParser, self) parent._process_node(node, handler, params) if old_include_root: self._include_root = old_include_root
class RecipeParse(LnstParser): def __init__(self, recipe_filepath): super(RecipeParse, self).__init__() self._filepath = recipe_filepath self._rp = RecipePath(None, self._filepath) self._include_root = self._rp.get_root() def first_pass(self): dom_init = XmlDomTreeInit() rp = self._rp self._xml_dom = dom_init.parse_string(rp.to_str(), rp.abs_path()) first_pass = FirstPass(self) first_pass.parse(self._xml_dom) def parse_recipe(self): self.first_pass() self._trigger_event("provisioning_requirements_ready", {}) second_pass = SecondPass(self) second_pass.parse(self._xml_dom)
def __init__(self, recipe_filepath): super(RecipeParse, self).__init__() self._filepath = recipe_filepath self._rp = RecipePath(None, self._filepath) self._include_root = self._rp.get_root()