From c86c819870a87d2a07ee032fd079dff89dc2f733 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 3 Oct 2023 11:56:06 -0400 Subject: [PATCH] Fix missing paging on models `#all` methods Most of the models' `#all` methods are missing paging which limits the number of results to a maximum of 500. --- lib/fog/compute/google/models/addresses.rb | 25 +++++++++++----- lib/fog/compute/google/models/disk_types.rb | 24 ++++++++++----- lib/fog/compute/google/models/disks.rb | 24 ++++++++++----- lib/fog/compute/google/models/firewalls.rb | 13 ++++++-- .../compute/google/models/forwarding_rules.rb | 26 +++++++++------- .../compute/google/models/global_addresses.rb | 13 ++++++-- .../google/models/global_forwarding_rules.rb | 13 ++++++-- .../google/models/http_health_checks.rb | 15 ++++++++-- lib/fog/compute/google/models/images.rb | 23 +++++++++----- .../google/models/instance_group_managers.rb | 26 ++++++++++------ .../compute/google/models/instance_groups.rb | 24 ++++++++++----- .../google/models/instance_templates.rb | 15 ++++++++-- .../compute/google/models/machine_types.rb | 25 +++++++++++----- lib/fog/compute/google/models/networks.rb | 15 ++++++++-- lib/fog/compute/google/models/operations.rb | 30 ++++++++++++++----- lib/fog/compute/google/models/regions.rb | 15 ++++++++-- lib/fog/compute/google/models/routes.rb | 15 ++++++++-- .../compute/google/models/ssl_certificates.rb | 15 ++++++++-- lib/fog/compute/google/models/subnetworks.rb | 24 ++++++++++----- .../google/models/target_http_proxies.rb | 15 ++++++++-- .../google/models/target_https_proxies.rb | 15 ++++++++-- .../compute/google/models/target_instances.rb | 24 ++++++++++----- lib/fog/compute/google/models/target_pools.rb | 24 ++++++++++----- lib/fog/compute/google/models/url_maps.rb | 15 ++++++++-- lib/fog/compute/google/models/zones.rb | 15 ++++++++-- 25 files changed, 355 insertions(+), 133 deletions(-) diff --git a/lib/fog/compute/google/models/addresses.rb b/lib/fog/compute/google/models/addresses.rb index 2232bdab8b..69f66f0a10 100644 --- a/lib/fog/compute/google/models/addresses.rb +++ b/lib/fog/compute/google/models/addresses.rb @@ -11,16 +11,25 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n :order_by => order_by, :page_token => page_token } - - if region - data = service.list_addresses(region, **opts).items || [] - else - data = [] - service.list_aggregated_addresses(**opts).items.each_value do |scoped_list| - data.concat(scoped_list.addresses) if scoped_list && scoped_list.addresses + items = [] + next_page_token = nil + loop do + if region + data = service.list_addresses(region, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_addresses(**opts) + data.items.each_value do |scoped_list| + items.concat(scoped_list.addresses) if scoped_list && scoped_list.addresses + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, region = nil) diff --git a/lib/fog/compute/google/models/disk_types.rb b/lib/fog/compute/google/models/disk_types.rb index 88021d89cc..e2ac936bf9 100644 --- a/lib/fog/compute/google/models/disk_types.rb +++ b/lib/fog/compute/google/models/disk_types.rb @@ -12,15 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil, :order_by => order_by, :page_token => page_token } - if zone - data = service.list_disk_types(zone, **opts).items - else - data = [] - service.list_aggregated_disk_types(**opts).items.each_value do |scoped_lst| - data.concat(scoped_lst.disk_types) if scoped_lst && scoped_lst.disk_types + items = [] + next_page_token = nil + loop do + if zone + data = service.list_disk_types(zone, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_disk_types(**opts) + data.items.each_value do |scoped_lst| + items.concat(scoped_lst.disk_types) if scoped_lst && scoped_lst.disk_types + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/disks.rb b/lib/fog/compute/google/models/disks.rb index f71d540a47..325508a1f1 100644 --- a/lib/fog/compute/google/models/disks.rb +++ b/lib/fog/compute/google/models/disks.rb @@ -12,15 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, :order_by => order_by, :page_token => page_token } - if zone - data = service.list_disks(zone, **opts).items || [] - else - data = [] - service.list_aggregated_disks(**opts).items.each_value do |scoped_list| - data.concat(scoped_list.disks) if scoped_list.disks + items = [] + next_page_token = nil + loop do + if zone + data = service.list_disks(zone, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_disks(**opts) + data.items.each_value do |scoped_list| + items.concat(scoped_list.disks) if scoped_list && scoped_list.disks + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/firewalls.rb b/lib/fog/compute/google/models/firewalls.rb index 3cdc8605bf..c5cd850df2 100644 --- a/lib/fog/compute/google/models/firewalls.rb +++ b/lib/fog/compute/google/models/firewalls.rb @@ -5,8 +5,17 @@ class Firewalls < Fog::Collection model Fog::Compute::Google::Firewall def all(opts = {}) - data = service.list_firewalls(**opts).to_h[:items] - load(data || []) + items = [] + next_page_token = nil + loop do + data = service.list_firewalls(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/forwarding_rules.rb b/lib/fog/compute/google/models/forwarding_rules.rb index 3c61367ed2..b53f807bd1 100644 --- a/lib/fog/compute/google/models/forwarding_rules.rb +++ b/lib/fog/compute/google/models/forwarding_rules.rb @@ -11,19 +11,25 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n :order_by => order_by, :page_token => page_token } - - if region - data = service.list_forwarding_rules(region, **opts).items || [] - else - data = [] - service.list_aggregated_forwarding_rules(**opts).items - .each_value do |scoped_list| - if scoped_list && scoped_list.forwarding_rules - data.concat(scoped_list.forwarding_rules) + items = [] + next_page_token = nil + loop do + if region + data = service.list_forwarding_rules(region, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_forwarding_rules(**opts) + data.items.each_value do |scoped_list| + items.concat(scoped_list.forwarding_rules) if scoped_list && scoped_list.forwarding_rules end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, region = nil) diff --git a/lib/fog/compute/google/models/global_addresses.rb b/lib/fog/compute/google/models/global_addresses.rb index ebb05579e8..29ab993efd 100644 --- a/lib/fog/compute/google/models/global_addresses.rb +++ b/lib/fog/compute/google/models/global_addresses.rb @@ -5,8 +5,17 @@ class GlobalAddresses < Fog::Collection model Fog::Compute::Google::GlobalAddress def all(options = {}) - data = service.list_global_addresses(**options).to_h[:items] || [] - load(data) + items = [] + next_page_token = nil + loop do + data = service.list_global_addresses(**options) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + options[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/global_forwarding_rules.rb b/lib/fog/compute/google/models/global_forwarding_rules.rb index c44845832e..46fe5f9a6d 100644 --- a/lib/fog/compute/google/models/global_forwarding_rules.rb +++ b/lib/fog/compute/google/models/global_forwarding_rules.rb @@ -5,8 +5,17 @@ class GlobalForwardingRules < Fog::Collection model Fog::Compute::Google::GlobalForwardingRule def all(opts = {}) - data = service.list_global_forwarding_rules(**opts).to_h[:items] || [] - load(data) + items = [] + next_page_token = nil + loop do + data = service.list_global_forwarding_rules(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/http_health_checks.rb b/lib/fog/compute/google/models/http_health_checks.rb index eedc3f2102..eb373b785c 100644 --- a/lib/fog/compute/google/models/http_health_checks.rb +++ b/lib/fog/compute/google/models/http_health_checks.rb @@ -4,9 +4,18 @@ class Google class HttpHealthChecks < Fog::Collection model Fog::Compute::Google::HttpHealthCheck - def all(_filters = {}) - data = service.list_http_health_checks.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_http_health_checks(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/images.rb b/lib/fog/compute/google/models/images.rb index 1bfeea99ca..9f72d21e85 100644 --- a/lib/fog/compute/google/models/images.rb +++ b/lib/fog/compute/google/models/images.rb @@ -24,12 +24,21 @@ class Images < Fog::Collection windows-sql-cloud ).freeze - def all - data = all_projects.map do |project| + def all(opts = {}) + items = [] + all_projects.each do |project| begin - images = service.list_images(project).items || [] - # Keep track of the project in which we found the image(s) - images.map { |img| img.to_h.merge(:project => project) } + next_page_token = nil + loop do + opts[:page_token] = next_page_token + data = service.list_images(project, **opts) + images = data.items&.map(&:to_h) || [] + # Keep track of the project in which we found the image(s) + images.each { |img| img.merge!(:project => project) } + items.concat(images) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + end rescue ::Google::Apis::ClientError => e raise e unless e.status_code == 404 # Not everyone has access to every Global Project. Requests @@ -37,9 +46,7 @@ def all next end end - data = data.flatten - - load(data) + load(items) end # Only return the non-deprecated list of images diff --git a/lib/fog/compute/google/models/instance_group_managers.rb b/lib/fog/compute/google/models/instance_group_managers.rb index 17844160aa..833357f8b5 100644 --- a/lib/fog/compute/google/models/instance_group_managers.rb +++ b/lib/fog/compute/google/models/instance_group_managers.rb @@ -12,17 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil, :order_by => order_by, :page_token => page_token } - - if zone - data = service.list_instance_group_managers(zone, **opts).items || [] - else - data = [] - service.list_aggregated_instance_group_managers(**opts).items.each_value do |group| - data.concat(group.instance_group_managers) if group.instance_group_managers + items = [] + next_page_token = nil + loop do + if zone + data = service.list_instance_group_managers(zone, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_instance_group_managers(**opts) + data.items.each_value do |group| + items.concat(group.instance_group_managers) if group && group.instance_group_managers + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/instance_groups.rb b/lib/fog/compute/google/models/instance_groups.rb index 8518604e47..cdb3a34dc1 100644 --- a/lib/fog/compute/google/models/instance_groups.rb +++ b/lib/fog/compute/google/models/instance_groups.rb @@ -11,17 +11,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil :order_by => order_by, :page_token => page_token } - - if zone - data = service.list_instance_groups(zone).items || [] - else - data = [] - service.list_aggregated_instance_groups(opts).items.each_value do |group| - data.concat(group.instance_groups) if group && group.instance_groups + items = [] + next_page_token = nil + loop do + if zone + data = service.list_instance_groups(zone) + next_items = data.items || [] + items.concat(next_items) + else + data = service.list_aggregated_instance_groups(opts) + data.items.each_value do |group| + items.concat(group.instance_groups) if group && group.instance_groups + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h)) + load(items.map(&:to_h)) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/instance_templates.rb b/lib/fog/compute/google/models/instance_templates.rb index d211c918e6..5844246467 100644 --- a/lib/fog/compute/google/models/instance_templates.rb +++ b/lib/fog/compute/google/models/instance_templates.rb @@ -4,9 +4,18 @@ class Google class InstanceTemplates < Fog::Collection model Fog::Compute::Google::InstanceTemplate - def all - data = service.list_instance_templates.items || [] - load(data.map(&:to_h)) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_instance_templates(**opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items.map(&:to_h)) end def get(identity) diff --git a/lib/fog/compute/google/models/machine_types.rb b/lib/fog/compute/google/models/machine_types.rb index 06cb08e883..38d79a7a1a 100644 --- a/lib/fog/compute/google/models/machine_types.rb +++ b/lib/fog/compute/google/models/machine_types.rb @@ -11,16 +11,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil :order_by => order_by, :page_token => page_token } - - if zone - data = service.list_machine_types(zone, **opts).items - else - data = [] - service.list_aggregated_machine_types(**opts).items.each_value do |scoped_list| - data.concat(scoped_list.machine_types) if scoped_list && scoped_list.machine_types + items = [] + next_page_token = nil + loop do + if zone + data = service.list_machine_types(zone, **opts) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_machine_types(**opts) + data.items.each_value do |scoped_list| + items.concat(scoped_list.machine_types) if scoped_list && scoped_list.machine_types + end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data.map(&:to_h) || []) + load(items.map(&:to_h) || []) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/networks.rb b/lib/fog/compute/google/models/networks.rb index c8922f079e..d0a2b8d80e 100644 --- a/lib/fog/compute/google/models/networks.rb +++ b/lib/fog/compute/google/models/networks.rb @@ -4,9 +4,18 @@ class Google class Networks < Fog::Collection model Fog::Compute::Google::Network - def all - data = service.list_networks.to_h[:items] - load(data || []) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_networks(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/operations.rb b/lib/fog/compute/google/models/operations.rb index 9ea4c9847b..4677c367e8 100644 --- a/lib/fog/compute/google/models/operations.rb +++ b/lib/fog/compute/google/models/operations.rb @@ -12,16 +12,30 @@ def all(zone: nil, region: nil, filter: nil, max_results: nil, :order_by => order_by, :page_token => page_token } - - if zone - data = service.list_zone_operations(zone, **opts).to_h[:items] - elsif region - data = service.list_region_operations(region, **opts).to_h[:items] - else - data = service.list_global_operations(**opts).to_h[:items] + items = [] + next_page_token = nil + loop do + if zone + data = service.list_zone_operations(zone, **opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + elsif region + data = service.list_region_operations(region, **opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_global_operations(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data || []) + load(items) end def get(identity, zone = nil, region = nil) diff --git a/lib/fog/compute/google/models/regions.rb b/lib/fog/compute/google/models/regions.rb index 1f8613e78f..1a06563d5f 100644 --- a/lib/fog/compute/google/models/regions.rb +++ b/lib/fog/compute/google/models/regions.rb @@ -4,9 +4,18 @@ class Google class Regions < Fog::Collection model Fog::Compute::Google::Region - def all - data = service.list_regions.to_h - load(data[:items] || []) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_regions(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/routes.rb b/lib/fog/compute/google/models/routes.rb index 2b6c35e4ea..070a5b5460 100644 --- a/lib/fog/compute/google/models/routes.rb +++ b/lib/fog/compute/google/models/routes.rb @@ -4,9 +4,18 @@ class Google class Routes < Fog::Collection model Fog::Compute::Google::Route - def all - data = service.list_routes.to_h - load(data[:items] || []) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_routes(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/ssl_certificates.rb b/lib/fog/compute/google/models/ssl_certificates.rb index 97c51f056c..e748042337 100644 --- a/lib/fog/compute/google/models/ssl_certificates.rb +++ b/lib/fog/compute/google/models/ssl_certificates.rb @@ -14,9 +14,18 @@ def get(identity) nil end - def all(_filters = {}) - data = service.list_ssl_certificates.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_ssl_certificates(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end end end diff --git a/lib/fog/compute/google/models/subnetworks.rb b/lib/fog/compute/google/models/subnetworks.rb index 7f85d6e45a..6e176ccbc4 100644 --- a/lib/fog/compute/google/models/subnetworks.rb +++ b/lib/fog/compute/google/models/subnetworks.rb @@ -11,16 +11,24 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n :order_by => order_by, :page_token => page_token } - - if region - data = service.list_subnetworks(region, **filters).to_h[:items] || [] - else - data = [] - service.list_aggregated_subnetworks(**filters).to_h[:items].each_value do |region_obj| - data.concat(region_obj[:subnetworks]) if region_obj[:subnetworks] + items = [] + next_page_token = nil + loop do + if region + data = service.list_subnetworks(region, **filters) + next_items = data.items || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_subnetworks(**filters) + data.items.each_value do |region_obj| + items.concat(region_obj.subnetworks) if region_obj && region_obj.subnetworks + end end + break if next_page_token.nil? || next_page_token.empty? + filters[:page_token] = next_page_token end - load(data) + load(items.map(&:to_h)) end def get(identity, region = nil) diff --git a/lib/fog/compute/google/models/target_http_proxies.rb b/lib/fog/compute/google/models/target_http_proxies.rb index e88f9e8813..93070c8e79 100644 --- a/lib/fog/compute/google/models/target_http_proxies.rb +++ b/lib/fog/compute/google/models/target_http_proxies.rb @@ -4,9 +4,18 @@ class Google class TargetHttpProxies < Fog::Collection model Fog::Compute::Google::TargetHttpProxy - def all(_filters = {}) - data = service.list_target_http_proxies.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_target_http_proxies(*opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/target_https_proxies.rb b/lib/fog/compute/google/models/target_https_proxies.rb index 3dda59d6e0..b5948adb78 100644 --- a/lib/fog/compute/google/models/target_https_proxies.rb +++ b/lib/fog/compute/google/models/target_https_proxies.rb @@ -4,9 +4,18 @@ class Google class TargetHttpsProxies < Fog::Collection model Fog::Compute::Google::TargetHttpsProxy - def all(_filters = {}) - data = service.list_target_https_proxies.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_target_https_proxies(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/target_instances.rb b/lib/fog/compute/google/models/target_instances.rb index 333e7cb921..35d3020a18 100644 --- a/lib/fog/compute/google/models/target_instances.rb +++ b/lib/fog/compute/google/models/target_instances.rb @@ -13,17 +13,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, :page_token => page_token } - if zone - data = service.list_target_instances(zone, **opts).to_h[:items] || [] - else - data = [] - service.list_aggregated_target_instances(**opts).items.each_value do |scoped_list| - unless scoped_list.nil? || scoped_list.target_instances.nil? - data += scoped_list.target_instances.map(&:to_h) + items = [] + next_page_token = nil + loop do + if zone + data = service.list_target_instances(zone, **opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + else + data = service.list_aggregated_target_instances(**opts) + data.items.each_value do |scoped_list| + items.concat(scoped_list.target_instances.map(&:to_h)) if scoped_list && scoped_list.target_instances end + next_page_token = data.next_page_token end + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data) + load(items) end def get(identity, zone = nil) diff --git a/lib/fog/compute/google/models/target_pools.rb b/lib/fog/compute/google/models/target_pools.rb index 4f15ea7375..daf0b1d914 100644 --- a/lib/fog/compute/google/models/target_pools.rb +++ b/lib/fog/compute/google/models/target_pools.rb @@ -11,17 +11,25 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n :order_by => order_by, :page_token => page_token } - if region.nil? - data = [] - service.list_aggregated_target_pools(**opts).items.each_value do |lst| - unless lst.nil? || lst.target_pools.nil? - data += lst.to_h[:target_pools] + items = [] + next_page_token = nil + loop do + if region.nil? + data = service.list_aggregated_target_pools(**opts) + data.items.each_value do |lst| + items.concat(lst.to_h[:target_pools]) if lst && lst.target_pools end + next_page_token = data.next_page_token + else + data = service.list_target_pools(region, **opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token end - else - data = service.list_target_pools(region, **opts).to_h[:items] + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token end - load(data) + load(items) end def get(identity, region = nil) diff --git a/lib/fog/compute/google/models/url_maps.rb b/lib/fog/compute/google/models/url_maps.rb index 841132f9d3..1088785cff 100644 --- a/lib/fog/compute/google/models/url_maps.rb +++ b/lib/fog/compute/google/models/url_maps.rb @@ -4,9 +4,18 @@ class Google class UrlMaps < Fog::Collection model Fog::Compute::Google::UrlMap - def all - data = service.list_url_maps.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_url_maps(**opts) + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity) diff --git a/lib/fog/compute/google/models/zones.rb b/lib/fog/compute/google/models/zones.rb index 5c128af34f..bb00c39dee 100644 --- a/lib/fog/compute/google/models/zones.rb +++ b/lib/fog/compute/google/models/zones.rb @@ -4,9 +4,18 @@ class Google class Zones < Fog::Collection model Fog::Compute::Google::Zone - def all - data = service.list_zones.to_h[:items] || [] - load(data) + def all(opts = {}) + items = [] + next_page_token = nil + loop do + data = service.list_zones + next_items = data.to_h[:items] || [] + items.concat(next_items) + next_page_token = data.next_page_token + break if next_page_token.nil? || next_page_token.empty? + opts[:page_token] = next_page_token + end + load(items) end def get(identity)