def delete_host(hostname): hosts = Hosts(HOSTS_PATH) hosts.remove_one(hostname) hosts.write(HOSTS_PATH) return bottle.redirect(bottle.request.headers.get('Referer', '/').strip())
docker = Client() hostname = getenv('HOSTNAME', None) if hostname: if '.' not in hostname: hostname = "%s%s" % (hostname, DOMAIN_SUFFIX) print "Adding %s" % hostname hosts = Hosts(HOSTS_PATH) my_ip = commands.getoutput("ip -4 -f inet -o addr show eth0 | awk '{print $4}' | cut -d/ -f1") hosts.set_one(hostname, my_ip) hosts.write(HOSTS_PATH) print "Go to http://%s/" % hostname for event in docker.events(): event = json.loads(event) if 'status' not in event: continue if event['status'] == 'start': hostname = get_hostname(event['id']) if hostname is None: continue print "Adding %s" % hostname hosts = Hosts(HOSTS_PATH) hosts.set_one(hostname, get_ip(event['id'])) hosts.write(HOSTS_PATH) elif event['status'] == 'die': hostname = get_hostname(event['id']) print "Removing %s" % hostname hosts = Hosts(HOSTS_PATH) hosts.remove_one(hostname) hosts.write(HOSTS_PATH)
print("My IP: {}".format(my_ip)) hosts.set_one(hostname, my_ip) hosts.write(HOSTS_PATH) print("Go to http://%s/" % hostname) for event in docker.events(): event = json.loads(event) if 'status' not in event: continue if event['status'] == 'start': hostname = get_hostname(event['id']) if hostname is None: print( "ERR: Event 'start' received but no hostname found for {}". format(event['id'])) continue container_ip = get_ip(event['id']) if not container_ip: print("ERR: Could not find IP address for {}".format(hostname)) continue print("Adding {} as {}".format(hostname, container_ip)) hosts = Hosts(HOSTS_PATH) hosts.set_one(hostname, container_ip) hosts.write(HOSTS_PATH) elif event['status'] == 'die': hostname = get_hostname(event['id']) print("Removing {}".format(hostname)) hosts = Hosts(HOSTS_PATH) hosts.remove_one(hostname) hosts.write(HOSTS_PATH)