#!/bin/python

hosts = [
        "ip-172-30-1-204.ap-northeast-1.compute.internal",
        "ip-172-30-1-224.ap-northeast-1.compute.internal"
        ]



#https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

import os
import sys
import subprocess
import stat

param = sys.argv
param.append("")

#print(param)

if param[1][-1] == "2" :
    oldpath = param[0]
    #param[0] = "/usr/bin/docker"
    param[0] = "docker"
    os.system('chmod -x '+oldpath)


    param[1] = param[1][0:-1]
    for host in hosts:
        os.environ["DOCKER_HOST"]=host
        subprocess.call(" ".join(param).split())

    os.system('chmod +x '+oldpath)

else:
    param[0] = "/usr/bin/docker"
    subprocess.call(" ".join(param).split())



