Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add "Routes" model and collection - Add "delete_route" request - Add "get_route" request - Add "insert_route" request - Add "list_routes" request
- Loading branch information
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |