mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' of github.com:fog/fog
This commit is contained in:
commit
328df19faf
8 changed files with 228 additions and 10 deletions
|
@ -10,6 +10,7 @@ module Fog
|
|||
request_path 'fog/google/requests/compute'
|
||||
request :list_servers
|
||||
request :list_addresses
|
||||
request :list_aggregated_addresses
|
||||
request :list_disks
|
||||
request :list_firewalls
|
||||
request :list_images
|
||||
|
@ -93,6 +94,9 @@ module Fog
|
|||
model :disk
|
||||
collection :disks
|
||||
|
||||
model :address
|
||||
collection :addresses
|
||||
|
||||
model :operation
|
||||
collection :operations
|
||||
|
||||
|
@ -110,9 +114,13 @@ module Fog
|
|||
|
||||
model :forwarding_rule
|
||||
collection :forwarding_rules
|
||||
|
||||
model :project
|
||||
collection :projects
|
||||
|
||||
model :firewall
|
||||
collection :firewalls
|
||||
|
||||
module Shared
|
||||
attr_reader :project, :api_version
|
||||
|
||||
|
|
62
lib/fog/google/models/compute/address.rb
Executable file
62
lib/fog/google/models/compute/address.rb
Executable file
|
@ -0,0 +1,62 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
##
|
||||
# Represents an Address resource
|
||||
#
|
||||
# @see https://developers.google.com/compute/docs/reference/latest/addresses
|
||||
class Address < Fog::Model
|
||||
identity :name
|
||||
|
||||
attribute :kind
|
||||
attribute :id
|
||||
attribute :address
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :region
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
attribute :status
|
||||
attribute :users
|
||||
|
||||
IN_USE_STATE = 'IN_USE'
|
||||
RESERVED_STATE = 'RESERVED'
|
||||
|
||||
def save
|
||||
requires :identity, :region
|
||||
|
||||
data = service.insert_address(identity, self.region, self.attributes)
|
||||
operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'], nil, data.body['region'])
|
||||
operation.wait_for { !pending? }
|
||||
reload
|
||||
end
|
||||
|
||||
def destroy(async=true)
|
||||
requires :identity, :region
|
||||
|
||||
data = service.delete_address(identity, self.region.split('/')[-1])
|
||||
operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'], nil, data.body['region'])
|
||||
unless async
|
||||
operation.wait_for { ready? }
|
||||
end
|
||||
operation
|
||||
end
|
||||
|
||||
def reload
|
||||
requires :identity, :region
|
||||
|
||||
data = collection.get(identity, self.region.split('/')[-1])
|
||||
merge_attributes(data.attributes)
|
||||
self
|
||||
end
|
||||
|
||||
def in_use?
|
||||
self.status == IN_USE_STATE
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/google/models/compute/addresses.rb
Executable file
34
lib/fog/google/models/compute/addresses.rb
Executable file
|
@ -0,0 +1,34 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/google/models/compute/address'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Addresses < Fog::Collection
|
||||
model Fog::Compute::Google::Address
|
||||
|
||||
def all(filters = {})
|
||||
if filters[:region]
|
||||
data = service.list_addresses(filters[:region]).body['items'] || []
|
||||
else
|
||||
data = []
|
||||
service.list_aggregated_addresses.body['items'].each_value do |region|
|
||||
data.concat(region['addresses']) if region['addresses']
|
||||
end
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(identity, region)
|
||||
if address = service.get_address(identity, region).body
|
||||
new(address)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
48
lib/fog/google/models/compute/firewall.rb
Normal file
48
lib/fog/google/models/compute/firewall.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
##
|
||||
# Represents a Firewall resource
|
||||
#
|
||||
# @see https://developers.google.com/compute/docs/reference/latest/firewalls
|
||||
class Firewall < Fog::Model
|
||||
identity :name
|
||||
|
||||
attribute :kind
|
||||
attribute :id
|
||||
attribute :allowed
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :network
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
attribute :source_ranges, :aliases => 'sourceRanges'
|
||||
attribute :source_tags, :aliases => 'sourceTags'
|
||||
attribute :target_tags, :aliases => 'targetTags'
|
||||
|
||||
def save
|
||||
requires :identity, :allowed, :network
|
||||
|
||||
data = service.insert_firewall(identity, self.allowed, self.network, 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_firewall(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/firewalls.rb
Normal file
27
lib/fog/google/models/compute/firewalls.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/google/models/compute/firewall'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Firewalls < Fog::Collection
|
||||
model Fog::Compute::Google::Firewall
|
||||
|
||||
def all
|
||||
data = service.list_firewalls.body
|
||||
load(data['items'] || [])
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
if firewall = service.get_firewall(identity).body
|
||||
new(firewall)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def insert_address(address_name, region_name)
|
||||
def insert_address(address_name, region_name, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
|
@ -12,16 +12,16 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
def insert_address(address_name, region_name)
|
||||
def insert_address(address_name, region_name, options = {})
|
||||
api_method = @compute.addresses.insert
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
'region' => region_name,
|
||||
}
|
||||
body_object = { 'name' => address_name }
|
||||
body_object['description'] = options[:description] if options[:description]
|
||||
|
||||
result = self.build_result(api_method, parameters,
|
||||
body_object=body_object)
|
||||
result = self.build_result(api_method, parameters, body_object)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Google
|
||||
|
||||
class Mock
|
||||
def insert_firewall(firewall_name, source_range=[], allowed=[], network=@default_network, source_tags=[])
|
||||
def insert_firewall(firewall_name, allowed, network = @default_network, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
|
@ -11,20 +11,34 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
def insert_firewall(firewall_name, source_range=[], allowed=[], network=@default_network, source_tags=[])
|
||||
def insert_firewall(firewall_name, allowed, network = @default_network, options = {})
|
||||
unless network.start_with? 'http'
|
||||
network = "#{@api_url}#{@project}/global/networks/#{network}"
|
||||
end
|
||||
|
||||
api_method = @compute.firewalls.insert
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
}
|
||||
body_object = {
|
||||
"name" => firewall_name,
|
||||
"network" => "#{@api_url}#{@project}/global/networks/#{network}",
|
||||
"network" => network,
|
||||
"allowed" => allowed,
|
||||
}
|
||||
body_object["sourceRanges"] = source_range if !source_range.empty?
|
||||
body_object["sourceTags"] = source_tags if !source_tags.empty?
|
||||
unless options[:description].nil?
|
||||
body_object["description"] = options[:description]
|
||||
end
|
||||
unless options[:source_ranges].nil? || options[:source_ranges].empty?
|
||||
body_object["sourceRanges"] = options[:source_ranges]
|
||||
end
|
||||
unless options[:source_tags].nil? || options[:source_tags].empty?
|
||||
body_object["sourceTags"] = options[:source_tags]
|
||||
end
|
||||
unless options[:target_tags].nil? || options[:target_tags].empty?
|
||||
body_object["targetTags"] = options[:target_tags]
|
||||
end
|
||||
|
||||
result = self.build_result(api_method, parameters, body_object=body_object)
|
||||
result = self.build_result(api_method, parameters, body_object)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
|
||||
|
|
25
lib/fog/google/requests/compute/list_aggregated_addresses.rb
Normal file
25
lib/fog/google/requests/compute/list_aggregated_addresses.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def list_aggregated_addresses
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def list_aggregated_addresses
|
||||
api_method = @compute.addresses.aggregated_list
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue