up_secs, _ = raw_time.split()
return float(up_secs)
- @property
def kernel_security(self):
# type: () -> Dict[str, str]
"""Determine the security features enabled in the kernel - SELinux, AppArmor"""
"description": "Linux Security Module framework is not available"
}
+ @property
+ def kernel_parameters(self):
+ # type: () -> Dict[str, str]
+ """Get kernel parameters required/used in Ceph clusters"""
+
+ k_param = {}
+ out, _, _ = call_throws(['sysctl', '-a'])
+ if out:
+ param_list = out.split('\n')
+ param_dict = { param.split(" = ")[0]:param.split(" = ")[-1] for param in param_list}
+
+ # return only desired parameters
+ if 'net.ipv4.ip_nonlocal_bind' in param_dict:
+ k_param['net.ipv4.ip_nonlocal_bind'] = param_dict['net.ipv4.ip_nonlocal_bind']
+
+ return k_param
+
def dump(self):
# type: () -> str
"""Return the attributes of this HostFacts object as json"""
self.daemons = {} # type: Dict[str, Dict[str, orchestrator.DaemonDescription]]
self.last_daemon_update = {} # type: Dict[str, datetime.datetime]
self.devices = {} # type: Dict[str, List[inventory.Device]]
+ self.facts = {} # type: Dict[str, Dict[str, Any]]
+ self.last_facts_update = {} # type: Dict[str, datetime.datetime]
self.osdspec_previews = {} # type: Dict[str, List[Dict[str, Any]]]
self.networks = {} # type: Dict[str, Dict[str, List[str]]]
self.last_device_update = {} # type: Dict[str, datetime.datetime]
self.daemons[host] = dm
self.last_daemon_update[host] = datetime.datetime.utcnow()
+ def update_host_facts(self, host, facts):
+ # type: (str, Dict[str, Dict[str, Any]]) -> None
+ self.facts[host] = facts
+ self.last_facts_update[host] = datetime.datetime.utcnow()
+
def update_host_devices_networks(self, host, dls, nets):
# type: (str, List[inventory.Device], Dict[str,List[str]]) -> None
self.devices[host] = dls
del self.daemons[host]
if host in self.devices:
del self.devices[host]
+ if host in self.facts:
+ del self.facts[host]
+ if host in self.last_facts_update:
+ del self.last_facts_update[host]
if host in self.osdspec_previews:
del self.osdspec_previews[host]
if host in self.loading_osdspec_preview:
return True
return False
+ def host_needs_facts_refresh(self, host):
+ # type: (str) -> bool
+ if host in self.mgr.offline_hosts:
+ logger.debug(f'Host "{host}" marked as offline. Skipping gather facts refresh')
+ return False
+ cutoff = datetime.datetime.utcnow() - datetime.timedelta(
+ seconds=self.mgr.facts_cache_timeout)
+ if host not in self.last_facts_update or self.last_facts_update[host] < cutoff:
+ return True
+ return False
+
def host_had_daemon_refresh(self, host: str) -> bool:
"""
... at least once.
'default': 10 * 60,
'desc': 'seconds to cache service (daemon) inventory',
},
+ {
+ 'name': 'facts_cache_timeout',
+ 'type': 'secs',
+ 'default': 1 * 60,
+ 'desc': 'seconds to cache host facts data',
+ },
{
'name': 'host_check_interval',
'type': 'secs',
self.ssh_config_file = None # type: Optional[str]
self.device_cache_timeout = 0
self.daemon_cache_timeout = 0
+ self.facts_cache_timeout = 0
self.host_check_interval = 0
self.mode = ''
self.container_image_base = ''
@forall_hosts
def refresh(host):
+
if self.mgr.cache.host_needs_check(host):
r = self._check_host(host)
if r is not None:
if r:
failures.append(r)
+ if self.mgr.cache.host_needs_facts_refresh(host):
+ self.log.info(('refreshing %s facts' % host))
+ r = self._refresh_facts(host)
+ if r:
+ failures.append(r)
+
if self.mgr.cache.host_needs_osdspec_preview_refresh(host):
self.log.debug(f"refreshing OSDSpec previews for {host}")
r = self._refresh_host_osdspec_previews(host)
self.mgr.cache.save_host(host)
return None
+ def _refresh_facts(self, host):
+ try:
+ out, err, code = self.mgr._run_cephadm(
+ host, cephadmNoImage, 'gather-facts', [],
+ error_ok=True, no_fsid=True)
+
+ if code:
+ return 'host %s gather-facts returned %d: %s' % (
+ host, code, err)
+ except Exception as e:
+ return 'host %s gather facts failed: %s' % (host, e)
+ self.log.debug('Refreshed host %s facts' % (host))
+ self.mgr.cache.update_host_facts(host, json.loads(''.join(out)))
+
def _refresh_host_devices(self, host) -> Optional[str]:
try:
out, err, code = self.mgr._run_cephadm(