def get_summary_yaml(self, params): """Return the node summary YAML formatted.""" node = self.get_object(params) # Produce a "clean" composite details document. details_template = dict.fromkeys(script_output_nsmap.values()) for script_result in ( ScriptResult.objects.filter( script_name__in=script_output_nsmap.keys(), status=SCRIPT_STATUS.PASSED, script_set__node=node, ) .only( "status", "script_name", "updated", "stdout", "script__id", "script_set__node", ) .order_by("script_name", "-updated") .distinct("script_name") ): namespace = script_output_nsmap[script_result.name] details_template[namespace] = script_result.stdout probed_details = merge_details_cleanly(details_template) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath("/*/*")) == 0: return "" else: return XMLToYAML( etree.tostring(probed_details, encoding=str, pretty_print=True) ).convert()
def get_context_data(self, **kwargs): context = super(NodeView, self).get_context_data(**kwargs) node = self.get_object() context['can_edit'] = self.request.user.has_perm( NODE_PERMISSION.EDIT, node) if node.status in (NODE_STATUS.COMMISSIONING, NODE_STATUS.READY): messages.info(self.request, NODE_BOOT_INFO) if node.power_type == POWER_TYPE.DEFAULT: messages.error(self.request, NO_POWER_SET) context['error_text'] = (node.error if node.status == NODE_STATUS.FAILED_TESTS else None) context['status_text'] = ( node.error if node.status != NODE_STATUS.FAILED_TESTS else None) kernel_opts = node.get_effective_kernel_options() context['kernel_opts'] = { 'is_global': kernel_opts[0] is None, 'is_tag': isinstance(kernel_opts[0], Tag), 'tag': kernel_opts[0], 'value': kernel_opts[1] } # Produce a "clean" composite details document. probed_details = merge_details_cleanly( get_single_probed_details(node.system_id)) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath('/*/*')) == 0: context["probed_details"] = None else: context["probed_details"] = etree.tostring(probed_details, encoding=unicode, pretty_print=True) return context
def get_context_data(self, **kwargs): context = super(NodeView, self).get_context_data(**kwargs) node = self.get_object() context['can_edit'] = self.request.user.has_perm( NODE_PERMISSION.EDIT, node) if node.status in (NODE_STATUS.COMMISSIONING, NODE_STATUS.READY): messages.info(self.request, NODE_BOOT_INFO) if node.power_type == POWER_TYPE.DEFAULT: messages.error(self.request, NO_POWER_SET) context['error_text'] = ( node.error if node.status == NODE_STATUS.FAILED_TESTS else None) context['status_text'] = ( node.error if node.status != NODE_STATUS.FAILED_TESTS else None) kernel_opts = node.get_effective_kernel_options() context['kernel_opts'] = { 'is_global': kernel_opts[0] is None, 'is_tag': isinstance(kernel_opts[0], Tag), 'tag': kernel_opts[0], 'value': kernel_opts[1] } # Produce a "clean" composite details document. probed_details = merge_details_cleanly( get_single_probed_details(node.system_id)) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath('/*/*')) == 0: context["probed_details"] = None else: context["probed_details"] = etree.tostring( probed_details, encoding=unicode, pretty_print=True) return context
def get_summary_xml(self, params): """Return the node summary XML formatted.""" node = self.get_object(params) # Produce a "clean" composite details document. details_template = dict.fromkeys(script_output_nsmap.values()) for script_result in node.get_latest_script_results.filter( script_name__in=script_output_nsmap.keys(), status=SCRIPT_STATUS.PASSED, script_set__node=node).only( 'script_name', 'updated', 'stdout', 'script__id', 'script_set__node').order_by( 'script_name', '-updated').distinct('script_name'): namespace = script_output_nsmap[script_result.name] details_template[namespace] = script_result.stdout probed_details = merge_details_cleanly(details_template) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath('/*/*')) == 0: return '' else: return etree.tostring(probed_details, encoding=str, pretty_print=True)
def dehydrate_summary_output(self, obj, data): """Dehydrate the machine summary output.""" # Produce a "clean" composite details document. probed_details = merge_details_cleanly(get_single_probed_details(obj)) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath('/*/*')) == 0: data['summary_xml'] = None data['summary_yaml'] = None else: data['summary_xml'] = etree.tostring(probed_details, encoding=str, pretty_print=True) data['summary_yaml'] = XMLToYAML( etree.tostring(probed_details, encoding=str, pretty_print=True)).convert() return data
def get_summary_yaml(self, params): """Return the node summary YAML formatted.""" node = self.get_object(params) # Produce a "clean" composite details document. details_template = dict.fromkeys(script_output_nsmap.values()) for hw_type in self._script_results.get(node.id, {}).values(): for script_result in hw_type: if (script_result.name in script_output_nsmap and script_result.status == SCRIPT_STATUS.PASSED): namespace = script_output_nsmap[script_result.name] details_template[namespace] = script_result.stdout probed_details = merge_details_cleanly(details_template) # We check here if there's something to show instead of after # the call to get_single_probed_details() because here the # details will be guaranteed well-formed. if len(probed_details.xpath('/*/*')) == 0: return '' else: return XMLToYAML( etree.tostring(probed_details, encoding=str, pretty_print=True)).convert()