Changeset - 34b111f968d6
[Not reviewed]
version_5
0 1 0
Dennis Fink - 9 years ago 2015-10-14 22:36:50
dennis.fink@c3l.lu
Don't fail if ENNSTATUS_SERVERS does not exists
1 file changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/cli/commands/config.py
Show inline comments
 
@@ -37,29 +37,32 @@ def server():
 
@click.argument('name')
 
@click.option('-i', '--ips', prompt='IPs (comma separated)')
 
@click.password_option()
 
@click.pass_obj
 
def add(obj, name, ips, password):
 

	
 
    with obj['config_file'].open() as f:
 
        config = json.load(f)
 

	
 
    name = name.lower()
 
    ips = [ip.strip() for ip in ips.split(',')]
 

	
 
    try:
 
    if name in config['ENNSTATUS_SERVERS']:
 
        try:
 
            click.confirm('Server already exits! Overwrite?', abort=True)
 
        except click.Abort as e:
 
            raise SystemExit from e
 
    except KeyError:
 
        config['ENNSTATUS_SERVERS'] = {}
 

	
 
    converted_ips = {ipaddress.ip_address(ip) for ip in ips}
 

	
 
    for ip in converted_ips:
 
        if not check_ip(ip):
 
            raise SystemExit('ip {} is not accepted!'.format(str(ip)))
 

	
 
    config['ENNSTATUS_SERVERS'][name] = {
 
        'IPS': ips,
 
        'PASSWORD': password
 
    }
 

	
0 comments (0 inline, 0 general)