def _get_grains(self, fqdn): pillar_util = MasterPillarUtil(fqdn, 'glob', use_cached_grains=True, grains_fallback=False, opts=salt_config) try: return pillar_util.get_minion_grains()[fqdn] except KeyError: raise GrainsNotFound(fqdn)
def get_heartbeat_period(self, fqdn): pillar_util = MasterPillarUtil([fqdn], 'list', grains_fallback=False, pillar_fallback=False, opts=salt_config) try: return pillar_util.get_minion_pillar()[fqdn]['schedule']['ceph.heartbeat']['seconds'] except KeyError: # Just in case salt pillar is unavailable for some reason, a somewhat sensible # guess. It's really an error, but I don't want to break the world in this case. fallback_contact_period = 60 log.warn("Missing period in minion '{0}' pillar".format(fqdn)) return fallback_contact_period
def get_remote_grains(fqdns): """ Return a dict of FQDN to grain dictionary for remote servers. Any servers for which grains are not found will appear in the result with an empty grains dictionary """ salt_config = client_config(config.get('cthulhu', 'salt_config_path')) pillar_util = MasterPillarUtil('', 'glob', use_cached_grains=True, grains_fallback=False, opts=salt_config) fqdn_to_grains = {} def _lookup_one(fqdn): log.debug(">> resolving grains for server {0}".format(fqdn)) cache_grains, cache_pillar = pillar_util._get_cached_minion_data(fqdn) if fqdn not in cache_grains: fqdn_to_grains[fqdn] = {} else: fqdn_to_grains[fqdn] = cache_grains[fqdn] log.debug("<< resolving grains for server {0}".format(fqdn)) p = gevent.pool.Pool(CONCURRENT_GRAIN_LOADS) p.map(_lookup_one, fqdns) return fqdn_to_grains
def get_heartbeat_period(self, fqdn): pillar_util = MasterPillarUtil([fqdn], 'list', grains_fallback=False, pillar_fallback=False, opts=salt_config) try: return pillar_util.get_minion_pillar( )[fqdn]['schedule']['ceph.heartbeat']['seconds'] except KeyError: # Just in case salt pillar is unavailable for some reason, a somewhat sensible # guess. It's really an error, but I don't want to break the world in this case. fallback_contact_period = 60 log.warn("Missing period in minion '{0}' pillar".format(fqdn)) return fallback_contact_period
def get_remote_metadata(self, fqdns): pillar_util = MasterPillarUtil('', 'glob', use_cached_grains=True, grains_fallback=False, opts=salt_config) fqdn_to_grains = {} def _lookup_one(fqdn): log.debug(">> resolving grains for server {0}".format(fqdn)) cache_grains, cache_pillar = pillar_util._get_cached_minion_data( fqdn) if fqdn not in cache_grains: fqdn_to_grains[fqdn] = {} else: fqdn_to_grains[fqdn] = cache_grains[fqdn] log.debug("<< resolving grains for server {0}".format(fqdn)) p = gevent.pool.Pool(CONCURRENT_GRAIN_LOADS) p.map(_lookup_one, fqdns) return fqdn_to_grains