Пример #1
0
func configureContainerNetwork(config process.Env, configurer network.Configurer) error {

	_, ipNet, err := net.ParseCIDR(config["network_cidr"])
	if err != nil {
		return err
	}

	mtu, err := strconv.ParseInt(config["container_iface_mtu"], 0, 64)
	if err != nil {
		return err
	}

	err = configurer.ConfigureContainer(&network.ContainerConfig{
		Hostname:      config["id"],
		ContainerIntf: config["network_container_iface"],
		ContainerIP:   net.ParseIP(config["network_container_ip"]),
		GatewayIP:     net.ParseIP(config["network_host_ip"]),
		Subnet:        ipNet,
		Mtu:           int(mtu),
	})
	if err != nil {
		return err
	}

	return nil
}
Пример #2
0
func configureHostNetwork(config process.Env, configurer network.Configurer) error {
	_, ipNet, err := net.ParseCIDR(config["network_cidr"])
	if err != nil {
		return err
	}

	mtu, err := strconv.ParseInt(config["container_iface_mtu"], 0, 64)
	if err != nil {
		return err
	}

	// Temporary until PID is passed in as a parameter.
	var containerPid int
	_, err = fmt.Sscanf(os.Getenv("PID"), "%d", &containerPid)
	if err != nil {
		return fmt.Errorf("linux_backend: can't parse PID string from ENV: %v", err)
	}

	err = configurer.ConfigureHost(&network.HostConfig{
		HostIntf:      config["network_host_iface"],
		BridgeName:    config["bridge_iface"],
		BridgeIP:      net.ParseIP(config["network_host_ip"]),
		ContainerIntf: config["network_container_iface"],
		ContainerPid:  containerPid,
		Subnet:        ipNet,
		Mtu:           int(mtu),
	})
	if err != nil {
		return err
	}

	return nil
}