go-ipam icon indicating copy to clipboard operation
go-ipam copied to clipboard

http request is not working

Open rgangaderan opened this issue 3 months ago • 3 comments

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

rgangaderan avatar Mar 17 '24 12:03 rgangaderan

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

majst01 avatar Mar 17 '24 13:03 majst01

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 '/'"}%

rgangaderan avatar Mar 17 '24 23:03 rgangaderan

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.

majst01 avatar Mar 18 '24 06:03 majst01

It's working

If I need to use this with Etcd backend, what could be the curl command looks like

rgangaderan avatar Apr 21 '24 21:04 rgangaderan

on the other hand can we use k8s etcd as our backend

rgangaderan avatar Apr 21 '24 21:04 rgangaderan

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

majst01 avatar Apr 22 '24 05:04 majst01

You reopened this issue with an unrelated question, this might be confusing for other users searching for similar solutions

majst01 avatar Apr 22 '24 05:04 majst01

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

rgangaderan avatar Apr 23 '24 23:04 rgangaderan