Beispiel #1
0
func (p centos) SetupDhcp(networks boshsettings.Networks) (err error) {
	dnsServers := []string{}
	dnsNetwork, found := networks.DefaultNetworkFor("dns")
	if found {
		for i := len(dnsNetwork.Dns) - 1; i >= 0; i-- {
			dnsServers = append(dnsServers, dnsNetwork.Dns[i])
		}
	}

	type dhcpConfigArg struct {
		DnsServers []string
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(CENTOS_DHCP_CONFIG_TEMPLATE))

	err = t.Execute(buffer, dhcpConfigArg{dnsServers})
	if err != nil {
		err = bosherr.WrapError(err, "Generating config from template")
		return
	}

	written, err := p.fs.WriteToFile("/etc/dhcp/dhclient.conf", buffer.String())
	if err != nil {
		err = bosherr.WrapError(err, "Writing to /etc/dhcp/dhclient.conf")
		return
	}

	if written {
		// Ignore errors here, just run the commands
		p.cmdRunner.RunCommand("service", "network", "restart")
	}

	return
}
func (net centosNetManager) SetupDhcp(networks boshsettings.Networks) error {
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")

	type dhcpConfigArg struct {
		DNSServers []string
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))

	err := t.Execute(buffer, dhcpConfigArg{dnsNetwork.DNS})
	if err != nil {
		return bosherr.WrapError(err, "Generating config from template")
	}

	written, err := net.fs.ConvergeFileContents("/etc/dhcp/dhclient.conf", buffer.Bytes())
	if err != nil {
		return bosherr.WrapError(err, "Writing to /etc/dhcp/dhclient.conf")
	}

	if written {
		net.restartNetwork()
	}

	return err
}
Beispiel #3
0
func (p ubuntu) SetupDhcp(networks boshsettings.Networks) (err error) {
	dnsServers := []string{}
	dnsNetwork, found := networks.DefaultNetworkFor("dns")
	if found {
		for i := len(dnsNetwork.Dns) - 1; i >= 0; i-- {
			dnsServers = append(dnsServers, dnsNetwork.Dns[i])
		}
	}

	type dhcpConfigArg struct {
		DnsServers []string
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(DHCP_CONFIG_TEMPLATE))

	err = t.Execute(buffer, dhcpConfigArg{dnsServers})
	if err != nil {
		return
	}

	written, err := p.fs.WriteToFile("/etc/dhcp3/dhclient.conf", buffer.String())
	if err != nil {
		return
	}

	if written {
		// Ignore errors here, just run the commands
		p.cmdRunner.RunCommand("pkill", "dhclient3")
		p.cmdRunner.RunCommand("/etc/init.d/networking", "restart")
	}

	return
}
func (net ubuntu) getDnsServers(networks boshsettings.Networks) (dnsServers []string) {
	dnsNetwork, found := networks.DefaultNetworkFor("dns")
	if found {
		for i := len(dnsNetwork.Dns) - 1; i >= 0; i-- {
			dnsServers = append(dnsServers, dnsNetwork.Dns[i])
		}
	}

	return
}
Beispiel #5
0
func (net centosNetManager) getDNSServers(networks boshsettings.Networks) []string {
	var dnsServers []string
	dnsNetwork, found := networks.DefaultNetworkFor("dns")
	if found {
		for i := len(dnsNetwork.DNS) - 1; i >= 0; i-- {
			dnsServers = append(dnsServers, dnsNetwork.DNS[i])
		}
	}
	return dnsServers
}
func (net ubuntuNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
	net.logger.Debug(ubuntuNetManagerLogTag, "Configuring DHCP networking")

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(ubuntuDHCPConfigTemplate))

	// Keep DNS servers in the order specified by the network
	// because they are added by a *single* DHCP's prepend command
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")
	dnsServersList := strings.Join(dnsNetwork.DNS, ", ")
	err := t.Execute(buffer, dnsServersList)
	if err != nil {
		return bosherr.WrapError(err, "Generating config from template")
	}

	dhclientConfigFile := net.dhclientConfigFile()
	written, err := net.fs.ConvergeFileContents(dhclientConfigFile, buffer.Bytes())
	if err != nil {
		return bosherr.WrapError(err, "Writing to %s", dhclientConfigFile)
	}

	if written {
		args := net.restartNetworkArguments()

		net.logger.Debug(ubuntuNetManagerLogTag, "Restarting network interfaces")

		_, _, _, err := net.cmdRunner.RunCommand("ifdown", args...)
		if err != nil {
			net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifdown failure: %s", err)
		}

		_, _, _, err = net.cmdRunner.RunCommand("ifup", args...)
		if err != nil {
			net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifup failure: %s", err)
		}
	}

	addresses := []boship.InterfaceAddress{
		// eth0 is hard coded in AWS and OpenStack stemcells.
		// TODO: abstract hardcoded network interface name to the NetManager
		boship.NewResolvingInterfaceAddress("eth0", net.ipResolver),
	}

	go func() {
		net.addressBroadcaster.BroadcastMACAddresses(addresses)
		if errCh != nil {
			errCh <- nil
		}
	}()

	return nil
}
func (net centosNetManager) writeResolvConf(networks boshsettings.Networks) error {
	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("resolv-conf").Parse(centosResolvConfTemplate))

	// Keep DNS servers in the order specified by the network
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")
	dnsServersArg := dnsConfigArg{dnsNetwork.DNS}

	err := t.Execute(buffer, dnsServersArg)
	if err != nil {
		return bosherr.WrapError(err, "Generating config from template")
	}

	err = net.fs.WriteFile("/etc/resolv.conf", buffer.Bytes())
	if err != nil {
		return bosherr.WrapError(err, "Writing to /etc/resolv.conf")
	}

	return nil
}
func (net centosNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")

	type dhcpConfigArg struct {
		DNSServers []string
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))

	err := t.Execute(buffer, dhcpConfigArg{dnsNetwork.DNS})
	if err != nil {
		return bosherr.WrapError(err, "Generating config from template")
	}

	written, err := net.fs.ConvergeFileContents("/etc/dhcp/dhclient.conf", buffer.Bytes())
	if err != nil {
		return bosherr.WrapError(err, "Writing to /etc/dhcp/dhclient.conf")
	}

	if written {
		net.restartNetwork()
	}

	addresses := []boship.InterfaceAddress{
		// eth0 is hard coded in AWS and OpenStack stemcells.
		// TODO: abstract hardcoded network interface name to the NetManager
		boship.NewResolvingInterfaceAddress("eth0", net.ipResolver),
	}

	go func() {
		net.addressBroadcaster.BroadcastMACAddresses(addresses)
		if errCh != nil {
			errCh <- nil
		}
	}()

	return err
}
func (net centosNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
	net.logger.Debug(centosNetManagerLogTag, "Configuring DHCP networking")

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))

	// Keep DNS servers in the order specified by the network
	// because they are added by a *single* DHCP's prepend command
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")
	dnsServersList := strings.Join(dnsNetwork.DNS, ", ")
	err := t.Execute(buffer, dnsServersList)
	if err != nil {
		return bosherr.WrapError(err, "Generating config from template")
	}

	written, err := net.fs.ConvergeFileContents("/etc/dhcp/dhclient.conf", buffer.Bytes())
	if err != nil {
		return bosherr.WrapError(err, "Writing to /etc/dhcp/dhclient.conf")
	}

	if written {
		net.restartNetwork()
	}

	addresses := []boship.InterfaceAddress{
		// eth0 is hard coded in AWS and OpenStack stemcells.
		// TODO: abstract hardcoded network interface name to the NetManager
		boship.NewResolvingInterfaceAddress("eth0", net.ipResolver),
	}

	go func() {
		net.addressBroadcaster.BroadcastMACAddresses(addresses)
		if errCh != nil {
			errCh <- nil
		}
	}()

	return err
}
func (net ubuntuNetManager) getDNSServers(networks boshsettings.Networks) []string {
	dnsNetwork, _ := networks.DefaultNetworkFor("dns")
	return dnsNetwork.DNS
}