Ejemplo n.º 1
0
func registryInit(cmd *cobra.Command, args []string) {

	servers := strings.Split(*etcdServers, ",")
	registryClient := etcd.NewClient(servers)

	if len(args) > 0 {
		machines = args[0]
		// just make slice if machines is not empty
		if len(machines) > 0 {
			hostNames = strings.Split(machines, ",")
		} else {
			cmd.Help()
			log.Fatal("Empty machine list specified")
		}
	} else {
		cmd.Help()
		log.Fatal("No machine list specified")
	}

	_, ipnet, err := net.ParseCIDR(globalSubnet)

	if err != nil {
		log.Fatal(err)
	}

	nets := netinfo.GetAllSubnet(ipnet, 8)

	fmt.Printf("vrouter init %s, %v\n", globalSubnet, ipnet)
	//fmt.Printf("%v\n", nets)

	//fmt.Printf("hostnames %d, %v\n", len(hostNames), hostNames)
	for i, node := range hostNames {
		key := registry.BridgeInfoPath(node)
		log.Printf("initialize config for host %s\n", node)
		if _, err := registryClient.Create(key, nets[i].String(), 0); err != nil {
			log.Printf("Error to create node: %s", err)
		}

	}
}
Ejemplo n.º 2
0
func (cmd *Command) Run(c *cobra.Command, args []string) {
	if cmd.daemonMode {
		servers := strings.Split(*cmd.etcdServers, ",")
		vrouter := cmd.daemon

		// start keepalive first
		vrouter.etcdClient = etcd.NewClient(servers)
		vrouter.KeepAlive()

		// bind and get a bridge IPNet with our iface ip
		// create the routing table entry in registry
		bridgeIPNet, err := vrouter.BindBridgeIPNet(cmd.hostip)
		if err != nil {
			log.Fatal("Failed to bind router interface: ", err)
		} else {
			log.Printf("daemon: get ipnet %v\n", bridgeIPNet)
		}

		// create bridge if we're running under linux
		// to debug on Mac OS X
		if runtime.GOOS == "linux" {
			err = vrouter.createBridgeIface(bridgeIPNet.String())
			if err != nil {
				log.Fatal(err)
			}
		}

		// monitor the routing table change
		err = vrouter.ManageRoute()
		if err != nil {
			log.Fatal(err)
		}

	} else {
		c.Help()
	}
}