// return ip, ipnet, err func (d *Daemon) getBridgeIPNet() (*net.IPNet, error) { client := d.etcdClient key := registry.BridgeInfoPath(d.Hostname) if resp, err := client.Get(key, false, false); err != nil { return nil, err } else { value := resp.Node.Value if ip, ipnet, err := net.ParseCIDR(value); err != nil { fmt.Printf("%v\n", value) return nil, err } else { ipnet.IP = ip return ipnet, nil } } }
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) } } }