Class: Fog::Compute::Google::ForwardingRule

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

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/google/models/compute/forwarding_rule.rb', line 45

def destroy(async=true)
  requires :name, :region
  operation = service.delete_forwarding_rule(name, region)
  if not async
    # wait until "RUNNING" or "DONE" to ensure the operation doesn't
    # fail, raises exception on error
    Fog.wait_for do
      operation = service.get_region_operation(region, operation.body["name"])
      operation.body["status"] == "DONE"
    end
  end
  operation
end

#ready?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
# File 'lib/fog/google/models/compute/forwarding_rule.rb', line 59

def ready?
  begin
    service.get_forwarding_rule(self.name, self.region)
    true
  rescue Fog::Errors::NotFound
    false
  end
end

#reloadObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/google/models/compute/forwarding_rule.rb', line 68

def reload
  requires :name, :region

  return unless data = begin
    collection.get(name, region)
  rescue Excon::Errors::SocketError
    nil
  end

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#saveObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/models/compute/forwarding_rule.rb', line 20

def save
  requires :name, :region, :target

  options = {
    'description' => description,
    'region' => region,
    'IPAddress' => ip_address,
    'IPProtocol' => ip_protocol || "TCP",
    'portRange' => port_range,
    'target' => target
  }

  data = service.insert_forwarding_rule(name, region, options).body
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data['name'], data['zone'])
  operation.wait_for { !pending? }
  reload
end

#set_target(new_target) ⇒ Object



38
39
40
41
42
43
# File 'lib/fog/google/models/compute/forwarding_rule.rb', line 38

def set_target new_target
  new_target = new_target.self_link unless new_target.class == String
  self.target = new_target
  service.set_forwarding_rule_target(self, new_target)
  reload
end