Example #1
0
def main(args, **kwargs):
    # parse the command line arguments
    arguments = docopt(__doc__)

    # parse the configuration
    fs_config = arguments['--config']
    config = get_config(fs_config)

    # inject custom blueprints into sys.path
    if arguments.get('--blueprints') is None:
        blueprints = None
    else:
        fs_dir, fs_blueprint = path.split(path.abspath(arguments['--blueprints']))
        sys.path.insert(0, fs_dir)
        blueprints = __import__(fs_blueprint.strip('.py'))

    # inject location of the config file so jails can resolve relative paths
    config['_fs_config'] = path.dirname(path.abspath(fs_config))

    # instantiate the jail system
    jailsystem = JailSystem(_blueprints=blueprints, **config)
    jailhost = jailsystem.host

    # 'point' fabric to the jail host
    if jailhost.public_ip_addr is not None:
        ip_addr = jailhost.public_ip_addr
    else:
        ip_addr = jailhost.ip_addr

    fab.env['host_string'] = ip_addr
    fab.env['host'] = ip_addr
    fab.env['hosts'] = [ip_addr]
    fab.env['port'] = jailhost.sshd_port

    # execute the bootstrap and/or install command
    if arguments['bootstrap']:
        jailhost.bootstrap()
    if arguments['install'] or arguments['bootstrap']:
        jailhost.install()
        exit()

    if arguments['list-blueprints']:
        for name, blueprint in jailsystem.jails.items():
            if arguments['--verbose']:
                description = blueprint.__doc__
            else:
                try:
                    description = blueprint.__doc__.split('\n')[0]
                except AttributeError:
                    description = ""
            print '%s: %s' % (name, description)
        exit()

    if arguments['list-jails']:
        fab.sudo('ezjail-admin list')
        exit()

    jail_name = arguments['JAIL'][0]
    jail = jailsystem.jails[jail_name]

    # the main entry points
    if arguments['init']:
        jail.init()
    elif arguments['update']:
        jail.update()
    elif arguments['destroy']:
        jail.destroy()
    # the remainder are usually only used for debugging
    elif arguments['upload']:
        jail._upload()
    elif arguments['prepare']:
        jail._prepare()
    elif arguments['configure']:
        jail.configure()
    elif arguments['debug']:
        jail._debug()
Example #2
0
def test_dict_parser(fs_examples):
    from ezjaildeploy.util import get_config
    parsed_dict = get_config(path.join(fs_examples, 'jails.conf.sample'))
    assert parsed_dict['host']['ip_addr'] == '192.168.91.128'