Package: consulate
Consulate is a Python client library and set of application for the Consul
service discovery and configuration system.InstallationConsulate is available via viapypiand can be installed with easy_install or pip:pipinstallconsulateIf you require communicating with Consul via a Unix socket, there is an extra
dependency that is installed via:pipinstallconsulate[unixsocket]Command Line UtilitiesConsulate comes with two command line utilities that make working with Consul
easier from a management perspective. Theconsulateapplication provides
a cli wrapper for common tasks performed.Thepassportapplication has been moved to a stand-alone application and
is available athttps://github.com/gmr/passport.consulateThe consulate application provides a CLI interface for registering a service,
backing up and restoring the contents of the KV database, and actions for getting,
setting, and deleting keys from the KV database.usage:consulate[-h][--api-schemeAPI_SCHEME][--api-hostAPI_HOST][--api-portAPI_PORT][--datacenterDC][--tokenTOKEN]{register,deregister,kv,run_once}...CLIutilitiesforConsuloptionalarguments:-h,--helpshowthishelpmessageandexit--api-schemeAPI_SCHEMETheschemetouseforconnectingtoConsulwith--api-hostAPI_HOSTTheconsulhosttoconnecton--api-portAPI_PORTTheconsulAPIporttoconnectto--datacenterDCThedatacentertospecifyfortheconnection--tokenTOKENACLtokenCommands:{register,deregister,kv,run_once}registerRegisteraserviceforthisnodederegisterDeregisteraserviceforthisnodekvKey/ValueDatabaseUtilitiesrun_onceLockcommandIftheCONSUL_RPC_ADDRenvironmentvariableisset,itwillbeparsedandusedfordefaultvalueswhenconnecting.Service Registration Help:usage:consulateregister[-h][-aADDRESS][-pPORT][-sSERVICE_ID][-tTAGS]name{check,httpcheck,no-check,ttl}...positionalarguments:nameTheservicenameoptionalarguments:-h,--helpshowthishelpmessageandexit-aADDRESS,--addressADDRESSSpecifyanaddress-pPORT,--portPORTSpecifyaport-sSERVICE_ID,--service-idSERVICE_IDSpecifyaserviceID-tTAGS,--tagsTAGSSpecifyacommadelimitedlistoftagsServiceCheckOptions:{check,httpcheck,no-check,ttl}checkDefineanexternalscript-basedcheckhttpcheckDefineanHTTP-basedcheckno-checkDonotenableservicemonitoringttlDefineadurationbasedTTLcheckKV Database Utilities Help:usage:consulatekv[-h]{backup,restore,ls,mkdir,get,set,rm}...optionalarguments:-h,--helpshowthishelpmessageandexitKey/ValueDatabaseUtilities:{backup,restore,ls,mkdir,get,set,rm}backupBackuptostdoutoraJSONfilerestoreRestorefromstdinoraJSONfilelsListallofthekeysmkdirCreateafoldergetGetakeyfromthedatabasesetSetakeyinthedatabasermRemoveakeyfromthedatabaseLocking Operations Help:usage:consulate[-h]run_once[-iINTERVAL]prefixcommandpositionalarguments:prefixthenameofthelockwhichwillbeheldinConsul.commandthecommandtorunoptionalarguments:-h,--helpshowthishelpmessageandexit-i,--intervalholdthelockforINTERVALsecondsAPI Usage ExamplesThe following examples highlight the usage of Consulate and does not document
the scope of the full Consulate API.Using Consulate with the Consul kv database:consul=consulate.Consul()# Set the key named release_flag to Trueconsul.kv['release_flag']=True# Get the value for the release_flag, if not set, raises AttributeErrortry:should_release_feature=consul.kv['release_flag']exceptAttributeError:should_release_feature=False# Delete the release_flag keydelconsul.kv['release_flag']# Find all keys that start with "fl"consul.kv.find('fl')# Find all keys that start with "feature_flag" terminated by "/" separatorconsul.kv.find('feature_flag',separator='/')# Check to see if a key called "foo" is setif"foo"inconsul.kv:print'Already Set'# Return all of the items in the key/value storeconsul.kv.items()Working with the Consulate.agent API:consul=consulate.Consul()# Get all of the service checks for the local agentchecks=consul.agent.checks()# Get all of the services registered with the local agentservices=consul.agent.services()# Add a service to the local agentconsul.agent.service.register('redis',port=6379,tags=['master'],ttl='10s')Fetching health information from Consul:consul=consulate.Session()# Get the health of a individual nodehealth=consul.health.node('my-node')# Get all checks that are criticalchecks=consul.heath.state('critical')For more examples, check out the Consulate documentation.