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_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 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()
FOREVER, synchronous, ) from provisioningserver.utils.xpath import try_match_xpath from twisted.internet.defer import DeferredList maaslog = get_maas_logger("tags") log = LegacyLogger() # The nsmap that XPath expression must be compiled with. This will # ensure that expressions like //lshw:something will work correctly. tag_nsmap = { namespace: namespace for namespace in script_output_nsmap.values() } def chunk_list(items, num_chunks): """Split `items` into (at most) `num_chunks` lists. Every chunk will have at least one element in its list, which may mean that we don't actually get as many chunks as the user asked for. The final chunk (of how ever many we create) is likely to be smaller than the rest, since we always round up to the nearest integer for chunk size. """ size = ceil(len(items) / num_chunks) for i in range(0, len(items), size): yield items[i:i + size]