Exemplo n.º 1
0
func (net centosNetManager) writeIfcfgs(networks boshsettings.Networks) ([]customNetwork, error) {
	var modifiedNetworks []customNetwork

	macAddresses, err := net.detectMacAddresses()
	if err != nil {
		return modifiedNetworks, bosherr.WrapError(err, "Detecting mac addresses")
	}

	for _, aNet := range networks {
		var network, broadcast string
		network, broadcast, err = boshsys.CalculateNetworkAndBroadcast(aNet.IP, aNet.Netmask)
		if err != nil {
			return modifiedNetworks, bosherr.WrapError(err, "Calculating network and broadcast")
		}

		newNet := customNetwork{
			aNet,
			macAddresses[aNet.Mac],
			network,
			broadcast,
			true,
		}
		modifiedNetworks = append(modifiedNetworks, newNet)

		buffer := bytes.NewBuffer([]byte{})
		t := template.Must(template.New("ifcfg").Parse(centosIfcgfTemplate))

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

		err = net.fs.WriteFile(filepath.Join("/etc/sysconfig/network-scripts", "ifcfg-"+newNet.Interface), buffer.Bytes())
		if err != nil {
			return modifiedNetworks, bosherr.WrapError(err, "Writing to /etc/sysconfig/network-scripts")
		}
	}

	return modifiedNetworks, nil
}
Exemplo n.º 2
0
func (net ubuntuNetManager) writeNetworkInterfaces(networks boshsettings.Networks) ([]customNetwork, bool, error) {
	var modifiedNetworks []customNetwork

	macAddresses, err := net.detectMacAddresses()
	if err != nil {
		return modifiedNetworks, false, bosherr.WrapError(err, "Detecting mac addresses")
	}

	for _, aNet := range networks {
		network, broadcast, err := boshsys.CalculateNetworkAndBroadcast(aNet.IP, aNet.Netmask)
		if err != nil {
			return modifiedNetworks, false, bosherr.WrapError(err, "Calculating network and broadcast")
		}

		newNet := customNetwork{
			aNet,
			macAddresses[aNet.Mac],
			network,
			broadcast,
			true,
		}
		modifiedNetworks = append(modifiedNetworks, newNet)
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("network-interfaces").Parse(ubuntuNetworkInterfacesTemplate))

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

	written, err := net.fs.ConvergeFileContents("/etc/network/interfaces", buffer.Bytes())
	if err != nil {
		return modifiedNetworks, false, bosherr.WrapError(err, "Writing to /etc/network/interfaces")
	}

	return modifiedNetworks, written, nil
}