Changeset - 8908001845c4
[Not reviewed]
feature-cli
0 1 0
Dennis Fink - 9 years ago 2015-10-24 01:04:30
dennis.fink@c3l.lu
Add servers subcommand to config command

This allows to add/delte more servers at once
1 file changed with 36 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/cli/commands/config.py
Show inline comments
 
import json
 
import ipaddress
 
import subprocess
 

	
 
from pprint import pprint
 

	
 
@@ -67,6 +68,7 @@ def add(obj, name, ips, password, bridge
 
        except KeyError:
 
            config['ENNSTATUS_BRIDGE_PROGRAM'] = [name]
 

	
 
    click.echo('%s password: %s' % (name, password))
 
    with obj['config_file'].open(mode='w', encoding='utf-8') as f:
 
        json.dump(config, f, indent=4, sort_keys=True)
 

	
 
@@ -98,3 +100,37 @@ def delete(obj, name):
 
        filename.unlink()
 
    except FileNotFoundError:
 
        pass
 

	
 

	
 
@config.group(short_help='Configure more servers at once')
 
def servers():
 
    pass
 

	
 

	
 
@servers.command('add', short_help='Add servers')
 
@click.argument('names', nargs=-1, required=True)
 
@click.option('-i', '--ips', prompt='IPs (comma separated)')
 
@click.option('--bridgeprogram/--no-bridgeprogram', default=False)
 
@click.pass_context
 
def adds(ctx, names, ips, bridgeprogram):
 

	
 
    for name in names:
 
        password = subprocess.check_output(['pwgen', '8', '1'])
 
        password = password.decode('utf-8')
 
        password = password.strip()
 
        ctx.invoke(
 
            add,
 
            name=name,
 
            ips=ips,
 
            password=password,
 
            bridgeprogram=bridgeprogram
 
        )
 

	
 

	
 
@servers.command('delete', short_help='Delete servers')
 
@click.argument('names', nargs=-1, required=True)
 
@click.pass_context
 
def dels(ctx, names):
 

	
 
    for name in names:
 
        ctx.invoke(delete, name=name)
0 comments (0 inline, 0 general)