コード例 #1
0
ファイル: server_metadata.py プロジェクト: AnishSid/calamari
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
コード例 #2
0
ファイル: salt_remote.py プロジェクト: ceph/calamari
import logging
import re
import gevent

from calamari_common.remote.base import Remote, Unavailable, AUTH_REJECTED, AUTH_NEW, AUTH_ACCEPTED
from calamari_common.salt_wrapper import master_config, _create_loader, client_config, MasterPillarUtil, LocalClient, condition_kwarg, \
    SaltEventSource, Key
from calamari_common.config import CalamariConfig
from calamari_common.types import SERVER, NotFound


log = logging.getLogger('calamari.remote.salt')
config = CalamariConfig()
salt_config = client_config(config.get('cthulhu', 'salt_config_path'))


# Issue up to this many disk I/Os to load grains at once
CONCURRENT_GRAIN_LOADS = 16


class SaltRemote(Remote):
    def run_job_sync(self, fqdn, cmd, args, timeout=None):
        client = LocalClient(config.get('cthulhu', 'salt_config_path'))
        results = client.cmd(fqdn, cmd, args, timeout=timeout)
        if results:
            if isinstance(fqdn, list):
                return results
            else:
                return results[fqdn]
        else:
コード例 #3
0
from calamari_common.salt_wrapper import client_config
from calamari_common.config import CalamariConfig

# A config instance for use from within the manager service
config = CalamariConfig()

# A salt config instance for places we'll need the sock_dir
salt_config = client_config(config.get('cthulhu', 'salt_config_path'))