import time
from fabric.api import run, env, task, put, cd, local, sudo

env.use_ssh_config = True
env.hosts = ['iota_node']


@task(default=True)
def iri():
    run('mkdir -p /srv/private-tangle/')
    with cd('/srv/private-tangle'):
        put('.', '.')
        run('docker-compose --project-name private-tangle pull')
        run('docker-compose --project-name private-tangle up -d --force-recreate iri')


@task
def tools():
    with cd('/srv/private-tangle'):
        put('.', '.')
        run('docker-compose --project-name private-tangle pull')
        run('docker-compose --project-name private-tangle up -d --no-deps --force-recreate coordinator explorer')
        run('docker-compose --project-name private-tangle logs -f --tail 100 coordinator explorer')


@task
def stop():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle stop')

@task
def stop_coord():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle stop coordinator')


@task
def down():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle down -v')


@task
def logs():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle logs -f --tail 100')


@task
def logs_coord():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle logs -f --tail 100 coordinator')


@task
def logs_all():
    with cd('/srv/private-tangle'):
        run('docker-compose logs -f')


@task
def reset():
    # stop services and delete database
    down()
    time.sleep(1)
    run('rm -rf /srv/private-tangle/testnet_db/')

    # restart all services
    iri()
    time.sleep(5)
    tools()

[(8, 'fabric.api.task', 'task', ([], {'default': '(True)'}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (10, 'fabric.api.run', 'run', (['"""mkdir -p /srv/private-tangle/"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (65, 'time.sleep', 'time.sleep', (['(1)'], {}), False, 'import time\n'), (66, 'fabric.api.run', 'run', (['"""rm -rf /srv/private-tangle/testnet_db/"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (70, 'time.sleep', 'time.sleep', (['(5)'], {}), False, 'import time\n'), (11, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (12, 'fabric.api.put', 'put', (['"""."""', '"""."""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (13, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle pull"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (14, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle up -d --force-recreate iri"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (19, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (20, 'fabric.api.put', 'put', (['"""."""', '"""."""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (21, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle pull"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (22, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle up -d --no-deps --force-recreate coordinator explorer"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (23, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle logs -f --tail 100 coordinator explorer"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (28, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (29, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle stop"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (33, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (34, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle stop coordinator"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (39, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (40, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle down -v"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (45, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (46, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle logs -f --tail 100"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (51, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (52, 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle logs -f --tail 100 coordinator"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (57, 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), (58, 'fabric.api.run', 'run', (['"""docker-compose logs -f"""'], {}), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n')]