Class: Fog::Compute::Google::Firewall

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/google/models/firewall.rb

Overview

Represents a Firewall resource

Instance Method Summary collapse

Instance Method Details

#allowedArray<Hash>

Allowed ports in API format

[

{ :ip_protocol => "TCP",
  :ports => ["201"] }

]

Returns:

  • (Array<Hash>)


19
# File 'lib/fog/compute/google/models/firewall.rb', line 19

attribute :allowed

#createObject



54
55
56
57
58
59
60
# File 'lib/fog/compute/google/models/firewall.rb', line 54

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

#deniedArray<Hash>

Denied ports in API format

[

{ :ip_protocol => "TCP",
  :ports => ["201"] }

]

Returns:

  • (Array<Hash>)


29
# File 'lib/fog/compute/google/models/firewall.rb', line 29

attribute :denied

#destroy(async = true) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/fog/compute/google/models/firewall.rb', line 82

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

#patch(diff = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/fog/compute/google/models/firewall.rb', line 72

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

#saveObject



44
45
46
47
48
49
50
51
52
# File 'lib/fog/compute/google/models/firewall.rb', line 44

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

#updateObject



62
63
64
65
66
67
68
69
70
# File 'lib/fog/compute/google/models/firewall.rb', line 62

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