示例#1
0
def configure_docker_hostnames_to_dnsmasq():
    hostname2ip_map = {}
    cli = get_client()
    try:
        containers = cli.containers()
    except docker.client.APIError as e:
        logger.error("error when doing docker ps.")
        return

    for container in containers:
        try:
            container_info = cli.inspect_container(container)
            hostname_ip = utility.parse_hostname_ip(container_info)
            hostname2ip_map[hostname_ip[0]] = hostname_ip[1]
        except docker.client.APIError as e:
            logger.error("error when inspecting container:" + container["Id"])

    GangerDns.generate_dnsmasq_host(hostname2ip_map)
    GangerDns.restart_dns_masq()
示例#2
0
    parser.add_option(
        "-b",
        "--docker-bridge",
        dest="bridge",
        action="store",
        default="docker0",
        help="the name of docker network bridge",
    )
    parser.add_option("-s", "--dns-server", dest="dserver", action="store", help="upstream dns server name")

    # parser.add_option("", "")
    (options, args) = parser.parse_args()

    numeric_level = getattr(logging, options.log_level.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError("Invalid log level: %s" % options.log_level)
    logging.basicConfig(level=numeric_level)

    # set docker host
    docker_host = options.url

    if options.init_dns:
        gangerdns = GangerDns(options.dserver, options.bridge)
        gangerdns.configure_dnsmasq()
        GangerDns.restart_dns_masq()
    elif options.docker_description != None:
        conf = GangerConfiguration(options.docker_description)
        start_dockers(conf.get_docker_specs())
    elif options.update_dns:
        configure_docker_hostnames_to_dnsmasq()