예제 #1
0
func (ibDrv *InfobloxDriver) RequestPool(r interface{}) (res map[string]interface{}, err error) {
	v := r.(*ipamsapi.RequestPoolRequest)
	log.Printf("RequestPoolRequest is '%v'\n", v)

	netviewName := ibclient.BuildNetworkViewFromRef(v.AddressSpace).Name

	var network *ibclient.Network
	var networkName string

	if opt, ok := v.Options["network-name"]; ok {
		networkName = opt
	}

	if len(v.Pool) > 0 {
		network, err = ibDrv.requestSpecificNetwork(netviewName, v.Pool, networkName)
	} else {
		var prefixLen uint
		var networkByName *ibclient.Network
		if networkName != "" {
			networkByName, err = ibDrv.objMgr.GetNetwork(netviewName, "", ibclient.EA{"Network Name": networkName})
			if err != nil {
				return
			}
		}
		if networkByName != nil {
			log.Printf("RequestNetwork: GetNetwork by name returns '%s'", *networkByName)
			network = networkByName
		} else {
			if opt, ok := v.Options["prefix-length"]; ok {
				if v, err := strconv.ParseUint(opt, 10, 8); err == nil {
					prefixLen = uint(v)
				}
			}
			network, err = ibDrv.allocateNetwork(netviewName, prefixLen, networkName)
		}
	}

	if network != nil {
		res = map[string]interface{}{"PoolID": network.Ref, "Pool": network.Cidr}
	}
	return
}
예제 #2
0
func (ibDrv *InfobloxDriver) RequestPool(r interface{}) (res map[string]interface{}, err error) {
	v := r.(*ipamsapi.RequestPoolRequest)
	log.Printf("RequestPoolRequest is '%v'\n", v)

	netviewName := ibclient.BuildNetworkViewFromRef(v.AddressSpace).Name

	var network *ibclient.Network
	if len(v.Pool) > 0 {
		network, err = ibDrv.requestSpecificNetwork(netviewName, v.Pool)
	} else {
		var prefixLen uint
		if opt, ok := v.Options["prefix-length"]; ok {
			if v, err := strconv.ParseUint(opt, 10, 8); err == nil {
				prefixLen = uint(v)
			}
		}
		network, err = ibDrv.allocateNetwork(netviewName, prefixLen)
	}

	if network != nil {
		res = map[string]interface{}{"PoolID": network.Ref, "Pool": network.Cidr}
	}
	return res, err
}