mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2844 from frodenas/gce_routes
[google|compute] Add Routes support
This commit is contained in:
commit
6994bd8710
7 changed files with 201 additions and 0 deletions
|
@ -26,6 +26,7 @@ module Fog
|
|||
request :list_http_health_checks
|
||||
request :list_target_pools
|
||||
request :list_forwarding_rules
|
||||
request :list_routes
|
||||
|
||||
request :get_server
|
||||
request :get_address
|
||||
|
@ -44,6 +45,7 @@ module Fog
|
|||
request :get_target_pool_health
|
||||
request :get_forwarding_rule
|
||||
request :get_project
|
||||
request :get_route
|
||||
|
||||
request :delete_address
|
||||
request :delete_disk
|
||||
|
@ -58,6 +60,7 @@ module Fog
|
|||
request :delete_http_health_check
|
||||
request :delete_target_pool
|
||||
request :delete_forwarding_rule
|
||||
request :delete_route
|
||||
|
||||
request :insert_address
|
||||
request :insert_disk
|
||||
|
@ -69,6 +72,7 @@ module Fog
|
|||
request :insert_http_health_check
|
||||
request :insert_target_pool
|
||||
request :insert_forwarding_rule
|
||||
request :insert_route
|
||||
|
||||
request :set_metadata
|
||||
request :set_tags
|
||||
|
@ -124,6 +128,9 @@ module Fog
|
|||
model :network
|
||||
collection :networks
|
||||
|
||||
model :route
|
||||
collection :routes
|
||||
|
||||
module Shared
|
||||
attr_reader :project, :api_version
|
||||
|
||||
|
|
52
lib/fog/google/models/compute/route.rb
Normal file
52
lib/fog/google/models/compute/route.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
##
|
||||
# Represents a Route resource
|
||||
#
|
||||
# @see https://developers.google.com/compute/docs/reference/latest/routes
|
||||
class Route < Fog::Model
|
||||
identity :name
|
||||
|
||||
attribute :kind
|
||||
attribute :id
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :dest_range, :aliases => 'destRange'
|
||||
attribute :network
|
||||
attribute :next_hop_gateway, :aliases => 'nextHopGateway'
|
||||
attribute :next_hop_instance, :aliases => 'nextHopInstance'
|
||||
attribute :next_hop_ip, :aliases => 'nextHopIp'
|
||||
attribute :next_hop_network, :aliases => 'nextHopNetwork'
|
||||
attribute :priority
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
attribute :tags
|
||||
attribute :warnings
|
||||
|
||||
def save
|
||||
requires :identity, :network, :dest_range, :priority
|
||||
|
||||
data = service.insert_route(identity, self.network, self.dest_range, self.priority, self.attributes)
|
||||
operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'])
|
||||
operation.wait_for { !pending? }
|
||||
reload
|
||||
end
|
||||
|
||||
def destroy(async=true)
|
||||
requires :identity
|
||||
|
||||
data = service.delete_route(identity)
|
||||
operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'])
|
||||
unless async
|
||||
operation.wait_for { ready? }
|
||||
end
|
||||
operation
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/google/models/compute/routes.rb
Normal file
27
lib/fog/google/models/compute/routes.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/google/models/compute/route'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Routes < Fog::Collection
|
||||
model Fog::Compute::Google::Route
|
||||
|
||||
def all
|
||||
data = service.list_routes.body
|
||||
load(data['items'] || [])
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
if route = service.get_route(identity).body
|
||||
new(route)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/google/requests/compute/delete_route.rb
Normal file
26
lib/fog/google/requests/compute/delete_route.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def delete_route(identity)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def delete_route(identity)
|
||||
api_method = @compute.routes.delete
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
'route' => identity,
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/google/requests/compute/get_route.rb
Normal file
26
lib/fog/google/requests/compute/get_route.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def get_route(identity)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def get_route(identity)
|
||||
api_method = @compute.routes.get
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
'route' => identity,
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/google/requests/compute/insert_route.rb
Normal file
38
lib/fog/google/requests/compute/insert_route.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def insert_route(name, network, dest_range, priority, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def insert_route(name, network, dest_range, priority, options = {})
|
||||
api_method = @compute.routes.insert
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
}
|
||||
body_object = {
|
||||
'name' => name,
|
||||
'network' => network,
|
||||
'destRange' => dest_range,
|
||||
'priority' => priority,
|
||||
}
|
||||
body_object['description'] = options[:description] if options[:description]
|
||||
unless options[:tags].nil? || options[:tags].empty?
|
||||
body_object['tags'] = options[:tags]
|
||||
end
|
||||
body_object['nextHopInstance'] = options[:next_hop_instance] if options[:next_hop_instance]
|
||||
body_object['nextHopGateway'] = options[:next_hop_gateway] if options[:next_hop_gateway]
|
||||
body_object['nextHopIp'] = options[:next_hop_ip] if options[:next_hop_ip]
|
||||
|
||||
result = self.build_result(api_method, parameters, body_object)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/google/requests/compute/list_routes.rb
Normal file
25
lib/fog/google/requests/compute/list_routes.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def list_routes(options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def list_routes
|
||||
api_method = @compute.routes.list
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue