c/s/e/wrapngo: workaround for unstable pagination
The packngo API doesnt have a stable pagination. This leads to duplicate entries and invalid lists. To increase the chance of having a correct response, we sort the list by hostname and pray to the RNG gods
Change-Id: Ie31b823eac8a3fef260ea56861894976b3354d71
Reviewed-on: https://review.monogon.dev/c/monogon/+/1555
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/cloud/shepherd/equinix/wrapngo/wrapn.go b/cloud/shepherd/equinix/wrapngo/wrapn.go
index f27ff54..400556b 100644
--- a/cloud/shepherd/equinix/wrapngo/wrapn.go
+++ b/cloud/shepherd/equinix/wrapngo/wrapn.go
@@ -213,7 +213,8 @@
func (e *client) ListDevices(ctx context.Context, pid string) ([]packngo.Device, error) {
return wrap(ctx, e, func(cl *packngo.Client) ([]packngo.Device, error) {
- res, _, err := cl.Devices.List(pid, nil)
+ // to increase the chances of a stable pagination, we sort the devices by hostname
+ res, _, err := cl.Devices.List(pid, &packngo.GetOptions{SortBy: "hostname"})
return res, err
})
}