equinixmetal-archive / packngo

[Deprecated] A Golang client for the Equinix Metal API. (Packet is now Equinix Metal)
https://deploy.equinix.com/labs/equinix-sdk-go/
Other
79 stars 53 forks source link

Add ability to update BGPSession status #316

Closed tylerauerbeck closed 2 years ago

tylerauerbeck commented 2 years ago

After initially creating a BGP session, its status may/will likely show as down. Until you hit the discover endpoint (/devices/<uuid>/bgp/discover) or wait for the auto-update interval to pass ( 6 hours or so), the status doesn't appear to get updated automatically to reflect that actual state of the session.

It would be nice have something like a .GetStatus(), .Discover() function that allowed for triggering this update. Even if this functionality just got wrapped up into a Get() or List() function this would be helpful. The other behavior I've noticed here is that if you're polling for the state of the session (i.e. waiting for the BGPSession to be up), it doesn't necessarily represent the latest state. Some behavior I've seen looks something like:

displague commented 2 years ago

This is a feature of the API utilized by console.equinix.com.

POST /projects/{ID}/bgp/discover (no body)

The response looks like:

{"updated_at":"2022-02-02T19:01:03.943Z"}

This endpoint is not included in the documented spec.

displague commented 2 years ago

Seeing the state of the BGP service is something that must be aggregated from the session status today: client.BGPSessions.Get($device_id). One would check all sessions for Status "up" or "up,up". This requires iterating all device ids in the BGP configuration.

As pointed out in the description, a List() function can be implemented. Today the Get() method requires an ID, but by not providing an ID in the request, a list would be returned. The console uses the following request: /projects/{id}/bgp/sessions?include=device&exclude=

The format of the response is {"bgp_sessions":[...]} where each item in the array matches the BGPSession type in packngo today. Packngo does not account for the CreatedAt and UpdatedAt fields present in the API response: created_at: "2022-01-26T21:10:23Z" (and updated_at with the same format).