1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
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
# Allowed ports in API format
#
# @example
# [
# { :ip_protocol => "TCP",
# :ports => ["201"] }
# ]
# @return [Array<Hash>]
attribute :allowed
attribute :creation_timestamp, :aliases => "creationTimestamp"
# Denied ports in API format
#
# @example
# [
# { :ip_protocol => "TCP",
# :ports => ["201"] }
# ]
# @return [Array<Hash>]
attribute :denied
attribute :description
attribute :destination_ranges, :aliases => "destinationRanges"
attribute :direction
attribute :id
attribute :kind
attribute :network
attribute :priority
attribute :self_link, :aliases => "selfLink"
attribute :source_ranges, :aliases => "sourceRanges"
attribute :source_service_accounts, :aliases => "sourceServiceAccounts"
attribute :source_tags, :aliases => "sourceTags"
attribute :target_service_accounts, :aliases => "targetServiceAccounts"
attribute :target_tags, :aliases => "targetTags"
def save
requires :identity
unless self.allowed || self.denied
raise Fog::Errors::Error.new("Firewall needs denied or allowed ports specified")
end
id.nil? ? create : update
end
def create
data = service.insert_firewall(identity, attributes)
operation = Fog::Compute::Google::Operations.new(service: service)
.get(data.name)
operation.wait_for { ready? }
reload
end
def update
requires :identity, :allowed, :network
data = service.update_firewall(identity, attributes)
operation = Fog::Compute::Google::Operations.new(service: service)
.get(data.name)
operation.wait_for { ready? }
reload
end
def patch(diff = {})
requires :identity
data = service.patch_firewall(identity, diff)
operation = Fog::Compute::Google::Operations.new(:service => service)
.get(data.name)
operation.wait_for { ready? }
reload
end
def destroy(async = true)
requires :identity
data = service.delete_firewall(identity)
operation = Fog::Compute::Google::Operations.new(:service => service)
.get(data.name)
operation.wait_for { ready? } unless async
operation
end
end
end
end
end
|