Skip to content
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
189 changes: 189 additions & 0 deletions google-cloud-compute/lib/google/cloud/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,69 @@ def self.backend_services_available? version: :v1
false
end

##
# Create a new client object for CrossSiteNetworks.
#
# By default, this returns an instance of
# [Google::Cloud::Compute::V1::CrossSiteNetworks::Rest::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-compute-v1/latest/Google-Cloud-Compute-V1-CrossSiteNetworks-Rest-Client)
# for a REST client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the CrossSiteNetworks service is
# supported by that API version, and the corresponding gem is available, the
# appropriate versioned client will be returned.
#
# Raises an exception if the currently installed versioned client gem for the
# given API version does not support the CrossSiteNetworks service.
# You can determine whether the method will succeed by calling
# {Google::Cloud::Compute.cross_site_networks_available?}.
#
# ## About CrossSiteNetworks
#
# The CrossSiteNetworks API.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [::Object] A client object for the specified version.
#
def self.cross_site_networks version: :v1, &block
require "google/cloud/compute/#{version.to_s.downcase}"

package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
service_module = Google::Cloud::Compute.const_get(package_name).const_get(:CrossSiteNetworks)
service_module.const_get(:Rest).const_get(:Client).new(&block)
end

##
# Determines whether the CrossSiteNetworks service is supported by the current client.
# If true, you can retrieve a client object by calling {Google::Cloud::Compute.cross_site_networks}.
# If false, that method will raise an exception. This could happen if the given
# API version does not exist or does not support the CrossSiteNetworks service,
# or if the versioned client gem needs an update to support the CrossSiteNetworks service.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [boolean] Whether the service is available.
#
def self.cross_site_networks_available? version: :v1
require "google/cloud/compute/#{version.to_s.downcase}"
package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
return false unless package_name
service_module = Google::Cloud::Compute.const_get package_name
return false unless service_module.const_defined? :CrossSiteNetworks
service_module = service_module.const_get :CrossSiteNetworks
return false unless service_module.const_defined? :Rest
service_module = service_module.const_get :Rest
service_module.const_defined? :Client
rescue ::LoadError
false
end

##
# Create a new client object for DiskTypes.
#
Expand Down Expand Up @@ -739,6 +802,69 @@ def self.forwarding_rules_available? version: :v1
false
end

##
# Create a new client object for FutureReservations.
#
# By default, this returns an instance of
# [Google::Cloud::Compute::V1::FutureReservations::Rest::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-compute-v1/latest/Google-Cloud-Compute-V1-FutureReservations-Rest-Client)
# for a REST client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the FutureReservations service is
# supported by that API version, and the corresponding gem is available, the
# appropriate versioned client will be returned.
#
# Raises an exception if the currently installed versioned client gem for the
# given API version does not support the FutureReservations service.
# You can determine whether the method will succeed by calling
# {Google::Cloud::Compute.future_reservations_available?}.
#
# ## About FutureReservations
#
# The FutureReservations API.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [::Object] A client object for the specified version.
#
def self.future_reservations version: :v1, &block
require "google/cloud/compute/#{version.to_s.downcase}"

package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
service_module = Google::Cloud::Compute.const_get(package_name).const_get(:FutureReservations)
service_module.const_get(:Rest).const_get(:Client).new(&block)
end

##
# Determines whether the FutureReservations service is supported by the current client.
# If true, you can retrieve a client object by calling {Google::Cloud::Compute.future_reservations}.
# If false, that method will raise an exception. This could happen if the given
# API version does not exist or does not support the FutureReservations service,
# or if the versioned client gem needs an update to support the FutureReservations service.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [boolean] Whether the service is available.
#
def self.future_reservations_available? version: :v1
require "google/cloud/compute/#{version.to_s.downcase}"
package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
return false unless package_name
service_module = Google::Cloud::Compute.const_get package_name
return false unless service_module.const_defined? :FutureReservations
service_module = service_module.const_get :FutureReservations
return false unless service_module.const_defined? :Rest
service_module = service_module.const_get :Rest
service_module.const_defined? :Client
rescue ::LoadError
false
end

##
# Create a new client object for GlobalAddresses.
#
Expand Down Expand Up @@ -6535,6 +6661,69 @@ def self.vpn_tunnels_available? version: :v1
false
end

##
# Create a new client object for WireGroups.
#
# By default, this returns an instance of
# [Google::Cloud::Compute::V1::WireGroups::Rest::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-compute-v1/latest/Google-Cloud-Compute-V1-WireGroups-Rest-Client)
# for a REST client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the WireGroups service is
# supported by that API version, and the corresponding gem is available, the
# appropriate versioned client will be returned.
#
# Raises an exception if the currently installed versioned client gem for the
# given API version does not support the WireGroups service.
# You can determine whether the method will succeed by calling
# {Google::Cloud::Compute.wire_groups_available?}.
#
# ## About WireGroups
#
# The WireGroups API.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [::Object] A client object for the specified version.
#
def self.wire_groups version: :v1, &block
require "google/cloud/compute/#{version.to_s.downcase}"

package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
service_module = Google::Cloud::Compute.const_get(package_name).const_get(:WireGroups)
service_module.const_get(:Rest).const_get(:Client).new(&block)
end

##
# Determines whether the WireGroups service is supported by the current client.
# If true, you can retrieve a client object by calling {Google::Cloud::Compute.wire_groups}.
# If false, that method will raise an exception. This could happen if the given
# API version does not exist or does not support the WireGroups service,
# or if the versioned client gem needs an update to support the WireGroups service.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @return [boolean] Whether the service is available.
#
def self.wire_groups_available? version: :v1
require "google/cloud/compute/#{version.to_s.downcase}"
package_name = Google::Cloud::Compute
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
return false unless package_name
service_module = Google::Cloud::Compute.const_get package_name
return false unless service_module.const_defined? :WireGroups
service_module = service_module.const_get :WireGroups
return false unless service_module.const_defined? :Rest
service_module = service_module.const_get :Rest
service_module.const_defined? :Client
rescue ::LoadError
false
end

##
# Create a new client object for ZoneOperations.
#
Expand Down
30 changes: 30 additions & 0 deletions google-cloud-compute/test/google/cloud/compute/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def test_backend_services_rest
end
end

def test_cross_site_networks_rest
skip unless Google::Cloud::Compute.cross_site_networks_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::Compute.cross_site_networks do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::Compute::V1::CrossSiteNetworks::Rest::Client, client
end
end

def test_disk_types_rest
skip unless Google::Cloud::Compute.disk_types_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
Expand Down Expand Up @@ -150,6 +160,16 @@ def test_forwarding_rules_rest
end
end

def test_future_reservations_rest
skip unless Google::Cloud::Compute.future_reservations_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::Compute.future_reservations do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::Compute::V1::FutureReservations::Rest::Client, client
end
end

def test_global_addresses_rest
skip unless Google::Cloud::Compute.global_addresses_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
Expand Down Expand Up @@ -1070,6 +1090,16 @@ def test_vpn_tunnels_rest
end
end

def test_wire_groups_rest
skip unless Google::Cloud::Compute.wire_groups_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::Compute.wire_groups do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::Compute::V1::WireGroups::Rest::Client, client
end
end

def test_zone_operations_rest
skip unless Google::Cloud::Compute.zone_operations_available?
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
Expand Down