From e0b381aecacf16dc1212674a979af5d94288706d Mon Sep 17 00:00:00 2001 From: Imri Zvik Date: Fri, 19 May 2017 00:16:32 +0300 Subject: [PATCH] Fixes #221 - Use nextPageToken to list all snapshots --- lib/fog/compute/google/models/snapshots.rb | 12 +++++++++--- lib/fog/compute/google/requests/list_snapshots.rb | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/fog/compute/google/models/snapshots.rb b/lib/fog/compute/google/models/snapshots.rb index c759ae7134..778cb00281 100644 --- a/lib/fog/compute/google/models/snapshots.rb +++ b/lib/fog/compute/google/models/snapshots.rb @@ -5,9 +5,15 @@ class Snapshots < Fog::Collection model Fog::Compute::Google::Snapshot def all - data = service.list_snapshots - snapshots = data.body["items"] || [] - load(snapshots) + items = [] + next_page_token = nil + loop do + data = service.list_snapshots(nil, next_page_token) + items.concat(data.body["items"]) + next_page_token = data.body["nextPageToken"] + break if next_page_token.nil? || next_page_token.empty? + end + load(items) end def get(snap_id) diff --git a/lib/fog/compute/google/requests/list_snapshots.rb b/lib/fog/compute/google/requests/list_snapshots.rb index f23ee0f13e..05388d4ba2 100644 --- a/lib/fog/compute/google/requests/list_snapshots.rb +++ b/lib/fog/compute/google/requests/list_snapshots.rb @@ -8,11 +8,12 @@ def list_snapshots end class Real - def list_snapshots(project = nil) + def list_snapshots(project = nil, next_page_token = nil) api_method = @compute.snapshots.list project = @project if project.nil? parameters = { - "project" => project + "project" => project, + "pageToken" => next_page_token } request(api_method, parameters)