当前位置: 首页>>代码示例>>Golang>>正文


Golang netconf.ApplyNetworkConfigs函数代码示例

本文整理汇总了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
}
开发者ID:hairyhenderson,项目名称:rancheros,代码行数:28,代码来源:scratch.go

示例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)
	}
}
开发者ID:liyimeng,项目名称:os,代码行数:12,代码来源:cloudinit.go

示例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 {}
}
开发者ID:pirater,项目名称:os,代码行数:53,代码来源:network.go

示例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 {}
	}
}
开发者ID:carriercomm,项目名称:os,代码行数:51,代码来源:network.go

示例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)
	}
}
开发者ID:sysuwbs,项目名称:os,代码行数:14,代码来源:network.go

示例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)
	}
}
开发者ID:un1xer,项目名称:os,代码行数:16,代码来源:network.go

示例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
}
开发者ID:UNwS,项目名称:docker-from-scratch,代码行数:41,代码来源:scratch.go

示例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 {}
}
开发者ID:Jdesk,项目名称:os,代码行数:21,代码来源:network.go

示例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)
	}
}
开发者ID:liyimeng,项目名称:os,代码行数:74,代码来源:packet.go


注:本文中的github.com/rancher/netconf.ApplyNetworkConfigs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。