mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[google|compute] Add Networks support
- Add "Networks" model and collection - Modify "insert" request to allow "description" and "gatewayIPv4" properties
This commit is contained in:
parent
57c86a0030
commit
8ed913587d
4 changed files with 81 additions and 4 deletions
|
@ -121,6 +121,9 @@ module Fog
|
|||
model :firewall
|
||||
collection :firewalls
|
||||
|
||||
model :network
|
||||
collection :networks
|
||||
|
||||
module Shared
|
||||
attr_reader :project, :api_version
|
||||
|
||||
|
|
45
lib/fog/google/models/compute/network.rb
Normal file
45
lib/fog/google/models/compute/network.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
##
|
||||
# Represents a Network resource
|
||||
#
|
||||
# @see https://developers.google.com/compute/docs/reference/latest/networks
|
||||
class Network < Fog::Model
|
||||
identity :name
|
||||
|
||||
attribute :kind
|
||||
attribute :id
|
||||
attribute :ipv4_range, :aliases => 'IPv4Range'
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :gateway_ipv4, :aliases => 'gatewayIPv4'
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
|
||||
def save
|
||||
requires :identity, :ipv4_range
|
||||
|
||||
data = service.insert_network(identity, self.ipv4_range, 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_network(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/networks.rb
Normal file
27
lib/fog/google/models/compute/networks.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/google/models/compute/network'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Networks < Fog::Collection
|
||||
model Fog::Compute::Google::Network
|
||||
|
||||
def all
|
||||
data = service.list_networks.body
|
||||
load(data['items'] || [])
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
if network = service.get_network(identity).body
|
||||
new(network)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def insert_network(network_name, ip_range)
|
||||
def insert_network(network_name, ip_range, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
|
@ -12,7 +12,7 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
def insert_network(network_name, ip_range)
|
||||
def insert_network(network_name, ip_range, options = {})
|
||||
api_method = @compute.networks.insert
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
|
@ -22,8 +22,10 @@ module Fog
|
|||
'IPv4Range' => ip_range
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters,
|
||||
body_object=body_object)
|
||||
body_object['description'] = options[:description] if options[:description]
|
||||
body_object['gatewayIPv4'] = options[:gateway_ipv4] if options[:gateway_ipv4]
|
||||
|
||||
result = self.build_result(api_method, parameters, body_object)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue