1""" 2Idem Support 3============ 4 5This util provides access to an idem-ready hub 6 7.. versionadded:: 3002 8""" 9import logging 10import sys 11 12try: 13 import pop.hub 14 15 HAS_POP = True, None 16except ImportError as e: 17 HAS_POP = False, str(e) 18 19log = logging.getLogger(__name__) 20 21__virtualname__ = "idem" 22 23 24def __virtual__(): 25 if sys.version_info < (3, 6): 26 return False, "idem only works on python3.6 and later" 27 if not HAS_POP[0]: 28 return HAS_POP 29 return __virtualname__ 30 31 32def hub(): 33 """ 34 Create a hub with idem ready to go and completely loaded 35 """ 36 if "idem.hub" not in __context__: 37 log.debug("Creating the POP hub") 38 hub = pop.hub.Hub() 39 40 log.debug("Initializing the loop") 41 hub.pop.loop.create() 42 43 log.debug("Loading subs onto hub") 44 hub.pop.sub.add(dyne_name="config") 45 # We aren't collecting grains at all but some exec modules depend on the sub being on the hub 46 hub.pop.sub.add(dyne_name="grains") 47 hub.pop.sub.add(dyne_name="idem") 48 49 log.debug("Reading idem config options") 50 hub.config.integrate.load(["acct", "idem"], "idem", parse_cli=False, logs=False) 51 52 __context__["idem.hub"] = hub 53 54 return __context__["idem.hub"] 55