Skip to content

Commit

Permalink
Add CLI support for deregistering services.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Daljord Morken committed Jun 8, 2015
1 parent ff788e9 commit 3671a57
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions consulate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def add_register_args(parser):
ttl.add_argument('duration', type=int, default=10,
help='TTL duration for a service with missing check data')

def add_deregister_args(parser):
"""Add the deregister command and arguments.
:param argparse.Subparser parser: parser
"""
# Service registration
registerp = parser.add_parser('deregister',
help='Deregister a service for this node')
registerp.add_argument('service_id', help='The service registration id')

def parse_cli_args():
"""Create the argument parser and add the arguments"""
Expand All @@ -118,6 +128,7 @@ def parse_cli_args():

sparser = parser.add_subparsers(title='Commands', dest='command')
add_register_args(sparser)
add_deregister_args(sparser)
add_kv_args(sparser)
return parser.parse_args()

Expand Down Expand Up @@ -256,6 +267,18 @@ def register(consul, args):
except exceptions.ConnectionError:
connection_error()

def deregister(consul, args):
"""Handle service deregistration.
:param consulate.api_old.Consul consul: The Consul instance
:param argparser.namespace args: The cli args
"""
try:
consul.agent.service.deregister(args.service_id)
except exceptions.ConnectionError:
connection_error()

# Mapping dict to simplify the code in main()
KV_ACTIONS = {
'backup': kv_backup,
Expand All @@ -281,5 +304,7 @@ def main():
args.token, args.api_scheme, adapter)
if args.command == 'register':
register(consul, args)
elif args.command == 'deregister':
deregister(consul, args)
elif args.command == 'kv':
KV_ACTIONS[args.action](consul, args)

0 comments on commit 3671a57

Please sign in to comment.