"""Consul sdb Module:maintainer: SaltStack:maturity: New:platform: allThis module allows access to Consul using an ``sdb://`` URILike all sdb modules, the Consul module requires a configuration profile tobe configured in either the minion or master configuration file. This profilerequires very little. For example:.. code-block:: yaml myconsul: driver: consul host: 127.0.0.1 port: 8500 token: b6376760-a8bb-edd5-fcda-33bc13bfc556 scheme: http consistency: default dc: dev verify: TrueThe ``driver`` refers to the Consul module, all other options are optional.For option details see: https://python-consul.readthedocs.io/en/latest/#consul"""fromsalt.exceptionsimportCommandExecutionErrortry:importconsulHAS_CONSUL=TrueexceptImportError:HAS_CONSUL=False__func_alias__={"set_":"set"}defset_(key,value,profile=None):ifnotprofile:returnFalseconn=get_conn(profile)returnconn.kv.put(key,value)defget(key,profile=None):ifnotprofile:returnFalseconn=get_conn(profile)_,result=conn.kv.get(key)returnresult["Value"]ifresultelseNone
[docs]defget_conn(profile):""" Return a client object for accessing consul """params={}forkeyin("host","port","token","scheme","consistency","dc","verify"):ifkeyinprofile:params[key]=profile[key]ifHAS_CONSUL:returnconsul.Consul(**params)else:raiseCommandExecutionError("(unable to import consul, ""module most likely not installed. PLease install python-consul)")