コード例 #1
0
func (ibDrv *InfobloxDriver) RequestAddress(r interface{}) (map[string]interface{}, error) {
	v := r.(*ipamsapi.RequestAddressRequest)
	network := ibclient.BuildNetworkFromRef(v.PoolID)

	macAddr := v.Options[netlabel.MacAddress]
	if len(macAddr) == 0 {
		macAddr = ibclient.MACADDR_ZERO
		log.Printf("RequestAddressRequest contains empty MAC Address. '%s' will be used.\n", macAddr)
	}

	fixedAddr, _ := ibDrv.objMgr.GetFixedAddress(network.NetviewName, network.Cidr, "", macAddr)
	if fixedAddr != nil {
		if v.Address != "" {
			if fixedAddr.IPAddress != v.Address {
				log.Printf("Requested MAC address '%s' is already associated with a difference IP address '%s' (requested: '%s')",
					macAddr, fixedAddr.IPAddress, v.Address)

				return nil, nil
			}
		}
	}

	if fixedAddr == nil {
		fixedAddr, _ = ibDrv.objMgr.AllocateIP(network.NetviewName, network.Cidr, v.Address, macAddr, "")
	}

	return map[string]interface{}{"Address": fmt.Sprintf("%s/%s", fixedAddr.IPAddress, getPrefixLength(network.Cidr))}, nil
}
コード例 #2
0
func (ibDrv *InfobloxDriver) ReleaseAddress(r interface{}) (map[string]interface{}, error) {
	v := r.(*ipamsapi.ReleaseAddressRequest)
	log.Printf("Releasing Address '%s' from Pool '%s'\n", v.Address, v.PoolID)
	network := ibclient.BuildNetworkFromRef(v.PoolID)
	ref, _ := ibDrv.objMgr.ReleaseIP(network.NetviewName, network.Cidr, v.Address, "")
	if ref == "" {
		log.Printf("***** IP Cannot be deleted '%s'! *******\n", v.Address)
	}

	return map[string]interface{}{}, nil
}
コード例 #3
0
func (ibDrv *InfobloxDriver) RequestAddress(r interface{}) (map[string]interface{}, error) {
	v := r.(*ipamsapi.RequestAddressRequest)

	macAddr := v.Options[netlabel.MacAddress]
	if len(macAddr) == 0 {
		log.Printf("RequestAddressRequest contains empty MAC Address. '00:00:00:00:00:00' will be used.\n")
	}
	network := ibclient.BuildNetworkFromRef(v.PoolID)
	fixedAddr, _ := ibDrv.objMgr.AllocateIP(network.NetviewName, network.Cidr, macAddr)

	return map[string]interface{}{"Address": fmt.Sprintf("%s/%s", fixedAddr.IPAddress, getPrefixLength(network.Cidr))}, nil
}
コード例 #4
0
func (ibDrv *InfobloxDriver) ReleasePool(r interface{}) (map[string]interface{}, error) {
	v := r.(*ipamsapi.ReleasePoolRequest)

	if len(v.PoolID) > 0 {
		networkFromRef := ibclient.BuildNetworkFromRef(v.PoolID)
		network, err := ibDrv.objMgr.GetNetwork(networkFromRef.NetviewName, networkFromRef.Cidr, nil)
		if err != nil {
			return map[string]interface{}{}, err
		}

		// if network has a valid looking "Network Name" EA, assume that
		// it is shared with others - hence not deleted.
		if n, ok := network.Ea["Network Name"]; ok && n != "" {
			return map[string]interface{}{}, nil
		}

		ref, _ := ibDrv.objMgr.DeleteNetwork(v.PoolID, networkFromRef.NetviewName)
		if len(ref) > 0 {
			log.Printf("Network %s deleted from Infoblox\n", v.PoolID)
		}
	}

	return map[string]interface{}{}, nil
}