Skip to content

Commit

Permalink
Fixes fog#221 - Use nextPageToken to list all snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
imriz committed May 18, 2017
1 parent 98db230 commit f3b15d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 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,14 @@ 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
begin
data = service.list_snapshots(nil, next_page_token)
items.concat(data.body["items"])
next_page_token = data.body['nextPageToken']
end until next_page_token.nil? || next_page_token.empty?
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

0 comments on commit f3b15d7

Please sign in to comment.