本文整理匯總了Golang中bosh/settings.Networks類的典型用法代碼示例。如果您正苦於以下問題:Golang Networks類的具體用法?Golang Networks怎麽用?Golang Networks使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Networks類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupDhcp
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
}
示例2: SetupDhcp
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
}
示例3: SetupDhcp
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
}
示例4: getDnsServers
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
}
示例5: getDNSServers
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
}
示例6: SetupDhcp
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
}
示例7: writeResolvConf
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
}
示例8: SetupDhcp
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
}
示例9: SetupDhcp
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
}
示例10: getDNSServers
func (net ubuntuNetManager) getDNSServers(networks boshsettings.Networks) []string {
dnsNetwork, _ := networks.DefaultNetworkFor("dns")
return dnsNetwork.DNS
}