本文整理汇总了Golang中github.com/rancher/netconf.ApplyNetworkConfigs函数的典型用法代码示例。如果您正苦于以下问题:Golang ApplyNetworkConfigs函数的具体用法?Golang ApplyNetworkConfigs怎么用?Golang ApplyNetworkConfigs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ApplyNetworkConfigs函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupNetworking
func setupNetworking(config *Config) error {
if config == nil {
return nil
}
if len(config.DnsConfig.Nameservers) != 0 {
if err := resolvconf.Build("/etc/resolv.conf", config.DnsConfig.Nameservers, config.DnsConfig.Search); err != nil {
return err
}
}
if config.BridgeName != "" {
log.Debugf("Creating bridge %s (%s)", config.BridgeName, config.BridgeAddress)
if err := netconf.ApplyNetworkConfigs(&netconf.NetworkConfig{
Interfaces: map[string]netconf.InterfaceConfig{
config.BridgeName: {
Address: config.BridgeAddress,
MTU: config.BridgeMtu,
Bridge: true,
},
},
}); err != nil {
return err
}
}
return nil
}
示例2: enableDoLinkLocal
func enableDoLinkLocal() {
err := netconf.ApplyNetworkConfigs(&netconf.NetworkConfig{
Interfaces: map[string]netconf.InterfaceConfig{
"eth0": {
IPV4LL: true,
},
},
})
if err != nil {
log.Errorf("Failed to apply link local on eth0: %v", err)
}
}
示例3: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
hostname, _ := cloudinit.SetHostname(cfg) // ignore error
log.Infof("Network: hostname: '%s'", hostname)
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Error(err)
}
hostname, _ = cloudinit.SetHostname(cfg) // ignore error
log.Infof("Network: hostname: '%s' (from DHCP, if not set by cloud-config)", hostname)
if hostname != "" {
hosts, err := os.Open("/etc/hosts")
defer hosts.Close()
if err != nil {
log.Fatal(err)
}
lines := bufio.NewScanner(hosts)
hostsContent := ""
for lines.Scan() {
line := strings.TrimSpace(lines.Text())
fields := strings.Fields(line)
if len(fields) > 0 && fields[0] == "127.0.1.1" {
hostsContent += "127.0.1.1 " + hostname + "\n"
continue
}
hostsContent += line + "\n"
}
if err := ioutil.WriteFile("/etc/hosts", []byte(hostsContent), 0600); err != nil {
log.Error(err)
}
}
if cfg.Rancher.Network.Dns.Override {
log.WithFields(log.Fields{"nameservers": cfg.Rancher.Network.Dns.Nameservers}).Info("Override nameservers")
if _, err := resolvconf.Build("/etc/resolv.conf", cfg.Rancher.Network.Dns.Nameservers, cfg.Rancher.Network.Dns.Search, nil); err != nil {
log.Error(err)
}
}
if f, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
} else {
f.Close()
}
sendTerm(WAIT_FOR_NETWORK)
select {}
}
示例4: Main
func Main() {
flags.Parse(os.Args[1:])
log.Infof("Running network: daemon=%v", daemon)
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
nameservers := cfg.Rancher.Network.Dns.Nameservers
search := cfg.Rancher.Network.Dns.Search
userSetDns := len(nameservers) > 0 || len(search) > 0
if !userSetDns {
nameservers = cfg.Rancher.DefaultNetwork.Dns.Nameservers
search = cfg.Rancher.DefaultNetwork.Dns.Search
}
if _, err := resolvconf.Build("/etc/resolv.conf", nameservers, search, nil); err != nil {
log.Error(err)
}
if err := hostname.SetHostnameFromCloudConfig(cfg); err != nil {
log.Error(err)
}
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Error(err)
}
userSetHostname := cfg.Hostname != ""
if err := netconf.RunDhcp(&cfg.Rancher.Network, !userSetHostname, !userSetDns); err != nil {
log.Error(err)
}
if err := hostname.SyncHostname(); err != nil {
log.Error(err)
}
if f, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
} else {
f.Close()
}
sendTerm(WAIT_FOR_NETWORK)
if daemon {
select {}
}
}
示例5: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
}
示例6: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
// Purposely ignore error
cloudinit.SetHostname(cfg)
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
}
示例7: setupNetworking
func setupNetworking(config *Config) error {
if config == nil {
return nil
}
hostname, err := os.Hostname()
if err != nil {
return err
}
tryCreateFile("/etc/hosts", `127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 `+hostname)
if len(config.DnsConfig.Nameservers) != 0 {
if _, err := resolvconf.Build("/etc/resolv.conf", config.DnsConfig.Nameservers, config.DnsConfig.Search, nil); err != nil {
return err
}
}
if config.BridgeName != "" {
log.Debugf("Creating bridge %s (%s)", config.BridgeName, config.BridgeAddress)
if err := netconf.ApplyNetworkConfigs(&netconf.NetworkConfig{
Interfaces: map[string]netconf.InterfaceConfig{
config.BridgeName: {
Address: config.BridgeAddress,
MTU: config.BridgeMtu,
Bridge: true,
},
},
}); err != nil {
return err
}
}
return nil
}
示例8: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
cloudinit.SetHostname(cfg) // ignore error
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
if _, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
}
sendTerm(WAIT_FOR_NETWORK)
select {}
}
示例9: enablePacketNetwork
func enablePacketNetwork(cfg *rancherConfig.RancherConfig) {
bootStrapped := false
for _, v := range cfg.Network.Interfaces {
if v.Address != "" {
if err := netconf.ApplyNetworkConfigs(&cfg.Network); err != nil {
logrus.Errorf("Failed to bootstrap network: %v", err)
return
}
bootStrapped = true
break
}
}
if !bootStrapped {
return
}
c := metadata.NewClient(http.DefaultClient)
m, err := c.Metadata.Get()
if err != nil {
logrus.Errorf("Failed to get Packet metadata: %v", err)
return
}
bondCfg := netconf.InterfaceConfig{
Addresses: []string{},
BondOpts: map[string]string{
"lacp-rate": "1",
"xmit_hash_policy": "layer3+4",
"downdelay": "200",
"updelay": "200",
"miimon": "100",
"mode": "4",
},
}
netCfg := netconf.NetworkConfig{
Interfaces: map[string]netconf.InterfaceConfig{},
}
for _, iface := range m.Network.Interfaces {
netCfg.Interfaces["mac="+iface.Mac] = netconf.InterfaceConfig{
Bond: "bond0",
}
}
for _, addr := range m.Network.Addresses {
bondCfg.Addresses = append(bondCfg.Addresses, fmt.Sprintf("%s/%d", addr.Address, addr.Cidr))
if addr.Gateway != "" {
if addr.AddressFamily == 4 {
if addr.Public {
bondCfg.Gateway = addr.Gateway
}
} else {
bondCfg.GatewayIpv6 = addr.Gateway
}
}
if addr.AddressFamily == 4 && strings.HasPrefix(addr.Gateway, "10.") {
bondCfg.PostUp = append(bondCfg.PostUp, "ip route add 10.0.0.0/8 via "+addr.Gateway)
}
}
netCfg.Interfaces["bond0"] = bondCfg
bytes, _ := yaml.Marshal(netCfg)
logrus.Debugf("Generated network config: %s", string(bytes))
cc := rancherConfig.CloudConfig{
Rancher: rancherConfig.RancherConfig{
Network: netCfg,
},
}
if err := rancherConfig.WriteToFile(cc, rancherConfig.CloudConfigNetworkFile); err != nil {
logrus.Errorf("Failed to save config file %s: %v", rancherConfig.CloudConfigNetworkFile, err)
}
}