dobs: add paging logic for regions with many volumes
@@ -128,12 +128,23 @@ func (d *driver) Volumes(
ctx types.Context,
opts *types.VolumesOpts) ([]*types.Volume, error) {
- doVolumes, _, err := d.client.Storage.ListVolumes(ctx, nil)
+ region := d.mustRegion(ctx)
+ if region == nil || *region == "" {
+ return nil, goof.New("No region provided or configured")
+ }
+
+ listOpts := &godo.ListVolumeParams{
+ ListOptions: &godo.ListOptions{PerPage: 200},
+ Region: *region,
+ }
+
+ var volumes []*types.Volume
+ for {
+ doVolumes, resp, err := d.client.Storage.ListVolumes(ctx, listOpts)
if err != nil {
return nil, err
}
- var volumes []*types.Volume
for _, vol := range doVolumes {
volume, err := d.toTypesVolume(ctx, &vol, opts.Attachments)
if err != nil {
@@ -142,6 +153,18 @@ func (d *driver) Volumes(
volumes = append(volumes, volume)
}
+ if resp.Links == nil || resp.Links.IsLastPage() {
+ break
+ }
+
+ page, err := resp.Links.CurrentPage()
+ if err != nil {
+ return nil, err
+ }
+
+ listOpts.ListOptions.Page = page + 1
+ }
+
return volumes, nil
}
@@ -166,7 +189,6 @@ func (d *driver) VolumeInspectByName(
ctx types.Context,
volumeName string,
opts *types.VolumeInspectOpts) (*types.Volume, error) {
-
region := d.mustRegion(ctx)
if region == nil || *region == "" {
return nil, goof.New("No region provided or configured")
