예제 #1
0
파일: utils.go 프로젝트: LogeshEswar/megamd
func updateIndex(ip string, pos uint) error {

	index := global.IPIndex{}
	res, err := index.Get(global.IPINDEXKEY)
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return err
	}

	update := global.IPIndex{
		Ip:     ip,
		Subnet: res.Subnet,
		Index:  pos,
	}

	conn, connerr := db.Conn("ipindex")
	if connerr != nil {
		log.Error("Failed to riak connection : %s", connerr)
		return connerr
	}

	serr := conn.StoreStruct(global.IPINDEXKEY, &update)
	if serr != nil {
		log.Error("Failed to store the update index value : %s", serr)
		return serr
	}
	log.Info("Docker network index update was successfully.")
	return nil
}
예제 #2
0
파일: utils.go 프로젝트: LogeshEswar/megamd
func IPRequest(subnet net.IPNet) (net.IP, uint, error) {
	bits := bitCount(subnet)
	bc := int(bits / 8)
	partial := int(math.Mod(bits, float64(8)))
	if partial != 0 {
		bc += 1
	}
	index := global.IPIndex{}
	res, err := index.Get(global.IPINDEXKEY)
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return nil, 0, err
	}

	return getIP(subnet, res.Index+1), res.Index + 1, nil
}
예제 #3
0
func (self *Server) IPInit() {

	rconn, rerr := db.Conn("ipindex")
	if rerr != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", rerr)
		os.Exit(1)
	}

	index := global.IPIndex{}
	subnet, _ := config.GetString("swarm:subnet")
	_, err := index.Get(global.IPINDEXKEY)
	if err != nil {
		data := &global.IPIndex{Ip: subnet, Subnet: subnet, Index: 1}
		res2B, _ := json.Marshal(data)
		ferr := rconn.StoreObject(global.IPINDEXKEY, string(res2B))
		if ferr != nil {
			fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", ferr)
			os.Exit(1)
		}
	}

	defer rconn.Close()
}