github.com/imran-kn/cilium-fork@v1.6.9/pkg/client/ipam.go (about) 1 // Copyright 2016-2017 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package client 16 17 import ( 18 "github.com/cilium/cilium/api/v1/client/ipam" 19 "github.com/cilium/cilium/api/v1/models" 20 "github.com/cilium/cilium/pkg/api" 21 ) 22 23 const ( 24 AddressFamilyIPv6 = "ipv6" 25 AddressFamilyIPv4 = "ipv4" 26 ) 27 28 // IPAMAllocate allocates an IP address out of address family specific pool. 29 func (c *Client) IPAMAllocate(family, owner string, expiration bool) (*models.IPAMResponse, error) { 30 params := ipam.NewPostIPAMParams().WithTimeout(api.ClientTimeout) 31 32 if family != "" { 33 params.SetFamily(&family) 34 } 35 36 if owner != "" { 37 params.SetOwner(&owner) 38 } 39 40 params.SetExpiration(&expiration) 41 42 resp, err := c.IPAM.PostIPAM(params) 43 if err != nil { 44 return nil, Hint(err) 45 } 46 return resp.Payload, nil 47 } 48 49 // IPAMAllocateIP tries to allocate a particular IP address. 50 func (c *Client) IPAMAllocateIP(ip, owner string) error { 51 params := ipam.NewPostIPAMIPParams().WithIP(ip).WithOwner(&owner).WithTimeout(api.ClientTimeout) 52 _, err := c.IPAM.PostIPAMIP(params) 53 return Hint(err) 54 } 55 56 // IPAMReleaseIP releases a IP address back to the pool. 57 func (c *Client) IPAMReleaseIP(ip string) error { 58 params := ipam.NewDeleteIPAMIPParams().WithIP(ip).WithTimeout(api.ClientTimeout) 59 _, err := c.IPAM.DeleteIPAMIP(params) 60 return Hint(err) 61 }