def load_hosts(self): for host_name in self.storage.hosts[2]: stor_node = self.storage.get("hosts/" + host_name, expected_format=None) host = Host(host_name) self.hosts[host.name] = host lshw_xml = stor_node.get('lshw', expected_format='xml') if lshw_xml is None: host.hw_info = None else: try: host.hw_info = get_hw_info(lshw_xml) except: host.hw_info = None info = self.parse_meminfo(stor_node.get('meminfo')) host.mem_total = info['MemTotal'] host.mem_free = info['MemFree'] host.swap_total = info['SwapTotal'] host.swap_free = info['SwapFree'] loadavg = stor_node.get('loadavg') host.load_5m = None if loadavg is None else float( loadavg.strip().split()[1]) ipa = self.storage.get('hosts/%s/ipa' % host.name) ip_rr_s = r"\d+:\s+(?P<adapter>.*?)\s+inet\s+(?P<ip>\d+\.\d+\.\d+\.\d+)/(?P<size>\d+)" info = collections.defaultdict(lambda: []) for line in ipa.split("\n"): match = re.match(ip_rr_s, line) if match is not None: info[match.group('adapter')].append( (IPAddress(match.group('ip')), int(match.group('size')))) for adapter, ips_with_sizes in info.items(): for ip, sz in ips_with_sizes: if self.public_net is not None and ip in self.public_net: host.public_net = NetworkAdapter(adapter, ip) if self.cluster_net is not None and ip in self.cluster_net: host.cluster_net = NetworkAdapter(adapter, ip) interfaces = getattr(self.jstorage.hosts, host_name).interfaces for name, adapter_dct in interfaces.items(): adapter_dct = adapter_dct.copy() dev = adapter_dct.pop('dev') adapter = NetworkAdapter(dev, None) adapter.__dict__.update(adapter_dct) host.net_adapters[dev] = adapter net_stats = self.get_node_net_stats(host.name) perf_adapters = [host.cluster_net, host.public_net] + list( host.net_adapters.values()) for net in perf_adapters: if net is not None and net.name is not None: net.perf_stats = net_stats.get(net.name) host.uptime = float(stor_node.get('uptime').split()[0])
def load_hosts(self): for host_name in self.storage.hosts[2]: stor_node = self.storage.get("hosts/" + host_name, expected_format=None) host = Host(host_name) self.hosts[host.name] = host lshw_xml = stor_node.get('lshw', expected_format='xml') if lshw_xml is None: host.hw_info = None else: try: host.hw_info = get_hw_info(lshw_xml) except: host.hw_info = None info = self.parse_meminfo(stor_node.get('meminfo')) host.mem_total = info['MemTotal'] host.mem_free = info['MemFree'] host.swap_total = info['SwapTotal'] host.swap_free = info['SwapFree'] loadavg = stor_node.get('loadavg') host.load_5m = None if loadavg is None else float(loadavg.strip().split()[1]) ipa = self.storage.get('hosts/%s/ipa' % host.name) ip_rr_s = r"\d+:\s+(?P<adapter>.*?)\s+inet\s+(?P<ip>\d+\.\d+\.\d+\.\d+)/(?P<size>\d+)" info = collections.defaultdict(lambda: []) for line in ipa.split("\n"): match = re.match(ip_rr_s, line) if match is not None: info[match.group('adapter')].append( (IPAddress(match.group('ip')), int(match.group('size')))) for adapter, ips_with_sizes in info.items(): for ip, sz in ips_with_sizes: if self.public_net is not None and ip in self.public_net: host.public_net = NetworkAdapter(adapter, ip) if self.cluster_net is not None and ip in self.cluster_net: host.cluster_net = NetworkAdapter(adapter, ip) interfaces = getattr(self.jstorage.hosts, host_name).interfaces for name, adapter_dct in interfaces.items(): adapter_dct = adapter_dct.copy() dev = adapter_dct.pop('dev') adapter = NetworkAdapter(dev, None) adapter.__dict__.update(adapter_dct) host.net_adapters[dev] = adapter net_stats = self.get_node_net_stats(host.name) perf_adapters = [host.cluster_net, host.public_net] + list(host.net_adapters.values()) for net in perf_adapters: if net is not None and net.name is not None: net.perf_stats = net_stats.get(net.name) host.uptime = float(stor_node.get('uptime').split()[0])