Esempio n. 1
0
        return "%s%s" % (hostname, dom_name)
    else:
        return None


if __name__ == '__main__':

    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)
Esempio n. 2
0
if __name__ == '__main__':

    docker = Client()
    hostname = getenv('HOSTNAME', None)
    if hostname:
        if '.' not in hostname:
            hostname = "{}{}".format(hostname, DOMAIN_SUFFIX)
        print("Adding {}".format(hostname))
        hosts = Hosts(HOSTS_PATH)
        my_ip = check_output([
            "/bin/sh", "-c",
            "ip -4 -f inet -o addr show eth0 | awk '{print $4}' | cut -d/ -f1"
        ])
        my_ip = my_ip.decode().strip()
        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'])