Ejemplo n.º 1
0
 def __init__(self):
     """Initialize server manifest."""
     super().__init__()
     self.log = CustomLog(MANIFEST_SVC_NAME)
     server_type = Conf.get(GLOBAL_CONF, NODE_TYPE_KEY)
     # import pdb; pdb.set_trace()
     Platform.validate_server_type_support(self.log, ResourceMapError,
                                           server_type)
     self.field_mapping = {
         'id': 'uid',
         'class': 'type',
         'description': 'description',
         'product': 'product',
         'serial': 'serial_number',
         'vendor': 'manufacturer',
         'part_number': 'part_number',
         'model_number': 'model_number',
         'physid': 'physical_id',
         'version': 'version',
         'logicalname': 'logical_name'
     }
     self.class_mapping = {
         'memory': 'hw>memory[%s]>%s',
         'disk': 'hw>disk[%s]>%s',
         'storage': 'hw>storage[%s]>%s',
         'system': 'hw>system[%s]>%s',
         'processor': 'hw>cpu[%s]>%s',
         'network': 'hw>nw_port[%s]>%s',
         'power': 'hw>psu[%s]>%s',
         'volume': 'hw>volume[%s]>%s',
         'bus': 'hw>bus[%s]>%s',
         'bridge': 'hw>bridge[%s]>%s',
         'display': 'hw>display[%s]>%s',
         'input': 'hw>input[%s]>%s',
         'generic': 'hw>generic[%s]>%s'
     }
     self.kv_dict = {}
     sw_resources = {
         'os': self.get_os_server_info,
         'cortx_sw_services': self.get_cortx_service_info,
         'external_sw_services': self.get_external_service_info
     }
     fw_resources = {'bmc': self.get_bmc_version_info}
     # Extracting resource type for 'self.class_mapping' dictionary values
     # and adding to hw_resources for function mapping.
     hw_resources = {value[len('hw>'):-len('[%s]>%s')]: \
         self.get_hw_resources_info for value in self.class_mapping.values()}
     self.server_resources = {
         "hw": hw_resources,
         "sw": sw_resources,
         "fw": fw_resources
     }
     self.service = Service()
     self.platform = Platform()
     self.resource_indexing_map = ServerResourceMap.resource_indexing_map\
         ["manifest"]
Ejemplo n.º 2
0
    def get_server_health_info(self):
        """Returns overall server information"""
        unhealthy_resource_found = False
        server_details = Platform().get_server_details()
        # Currently only one instance of server is considered
        server = []
        info = {}
        info["make"] = server_details["Board Mfg"]
        info["model"] = server_details["Product Name"]
        try:
            build_instance = BuildInfo()
            info["product_family"] = build_instance.get_attribute("NAME")
            info["version"] = build_instance.get_attribute("VERSION")
            info["build"] = build_instance.get_attribute("BUILD")
        except Exception as err:
            logger.error(
                self.log.svc_log(f"Unable to get build info due to {err}"))
        info["resource_usage"] = {}
        info["resource_usage"]["cpu_usage"] = self.get_cpu_overall_usage()
        info["resource_usage"]["disk_usage"] = self.get_disk_overall_usage()
        info["resource_usage"]["memory_usage"] = self.get_memory_overall_usage(
        )

        for res_type in self.server_resources:
            info.update({res_type: {}})
            for fru, method in self.server_resources[res_type].items():
                try:
                    info[res_type].update({fru: method()})
                    unhealthy_resource_found = self._is_any_resource_unhealthy(
                        fru, info[res_type])
                except Exception as err:
                    logger.error(
                        self.log.svc_log(f"{err.__class__.__name__}:{err}"))
                    info[res_type].update({fru: None})

        info["uid"] = socket.getfqdn()
        info["last_updated"] = int(time.time())
        info["health"] = {}
        info["health"][
            "status"] = "OK" if not unhealthy_resource_found else "Degraded"
        health_desc = 'good' if info["health"]["status"] == 'OK' else 'bad'
        info["health"]["description"] = f"Server is in {health_desc} health."
        info["health"]["recommendation"] = const.DEFAULT_RECOMMENDATION \
            if info["health"]["status"] != "OK" else "NA"
        info["health"]["specifics"] = []
        server.append(info)
        return server