Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #221 - Use nextPageToken to list all snapshots #222

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/fog/compute/google/models/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/fog/compute/google/requests/list_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down