Skip to content

Commit

Permalink
[config] Add subcommand to configure the status of auto-restart featu…
Browse files Browse the repository at this point in the history
…re for each container (#801)
  • Loading branch information
yozhao101 authored Feb 7, 2020
1 parent bb10686 commit 53f8904
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2468,5 +2468,41 @@ def feature_status(name, state):

config_db.mod_entry('FEATURE', name, {'status': state})

#
# 'container' group ('config container ...')
#
@config.group(name='container', invoke_without_command=False)
def container():
"""Modify configuration of containers"""
pass

#
# 'feature' group ('config container feature ...')
#
@container.group(name='feature', invoke_without_command=False)
def feature():
"""Modify configuration of container features"""
pass

#
# 'autorestart' subcommand ('config container feature autorestart ...')
#
@feature.command(name='autorestart', short_help="Configure the status of autorestart feature for specific container")
@click.argument('container_name', metavar='<container_name>', required=True)
@click.argument('autorestart_status', metavar='<autorestart_status>', required=True, type=click.Choice(["enabled", "disabled"]))
def autorestart(container_name, autorestart_status):
config_db = ConfigDBConnector()
config_db.connect()
container_feature_table = config_db.get_table('CONTAINER_FEATURE')
if not container_feature_table:
click.echo("Unable to retrieve container feature table from Config DB.")
return

if not container_feature_table.has_key(container_name):
click.echo("Unable to retrieve features for container '{}'".format(container_name))
return

config_db.mod_entry('CONTAINER_FEATURE', container_name, {'auto_restart': autorestart_status})

if __name__ == '__main__':
config()

0 comments on commit 53f8904

Please sign in to comment.