go-ipam
go-ipam copied to clipboard
http request is not working
I can run the container and execute cli to create prefix, but when I tried to do this with curl -X POST -H "Content-Type: application/json" -d '{"cidr": "192.168.0.0/16"}' http://localhost:9090/prefix/create
connection is not working even I have expose 9090 to host
Please update your compose.yaml as shown in #139.
After that, go-ipam is exposed to localhost:9090 as well.
Generally go-ipam is a grpc server, so it is preferred to use the go-api to access this service. Nevertheless there is a rest api, for example listPrefixes can be called like this:
curl -v -X POST -d '{}' -H 'Content-Type: application/json' localhost:9090/api.v1.IpamService/ListPrefixes
I can run this to create prefix
curl -v -X POST -d '{"cidr": "192.168.0.0/16"}' -H 'Content-Type: application/json' localhost:9090/api.v1.IpamService/CreatePrefix
but when run to acquire ip from prefix it cannot find the prefix, I checked the ListPrefix to make sure the prefix is available
curl -v -X POST -d '{"prefix": "192.168.0.0/16"}' -H 'Content-Type: application/json' http://localhost:9090/api.v1.IpamService/AcquireIP
error is HTTP/1.1 400 Bad Request < Accept-Encoding: gzip < Content-Type: application/json < Date: Sun, 17 Mar 2024 23:23:20 GMT < Content-Length: 119 <
- Connection #0 to host localhost left intact {"code":"invalid_argument","message":"NotFound: unable to find prefix for cidr: error:netip.ParsePrefix(""): no '/'"}%
You have to look into https://github.com/metal-stack/go-ipam/blob/master/proto/api/v1/ipam.proto for reference which Methods and parameters in the Requests are required. AcquireIPRequest looks like so:
message AcquireIPRequest {
string prefix_cidr = 1;
optional string ip = 2;
optional string namespace = 3;
}
This means you must call:
curl -v -X POST -d '{"prefix_cidr": "192.168.0.0/16"}' -H 'Content-Type: application/json' http://localhost:9090/api.v1.IpamService/AcquireIP
But as i said, this is not the designated way to use go-ipam. It offers a grpc api and use it as that.
It's working
If I need to use this with Etcd backend, what could be the curl command looks like
on the other hand can we use k8s etcd as our backend
It's working
If I need to use this with Etcd backend, what could be the curl command looks like
same API for all backends
You reopened this issue with an unrelated question, this might be confusing for other users searching for similar solutions
You reopened this issue with an unrelated question, this might be confusing for other users searching for similar solutions
I will close this, since it is working fine for me