Class: Fog::Compute::Google::TargetInstance

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

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/compute/google/models/target_instance.rb', line 32

def destroy(async = true)
  requires :name, :zone
  operation = service.delete_target_instance(name, zone)
  unless async
    # wait until "DONE" to ensure the operation doesn't fail, raises
    # exception on error
    Fog.wait_for do
      operation.body["status"] == "DONE"
    end
  end
  operation
end

#ready?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/fog/compute/google/models/target_instance.rb', line 45

def ready?
  service.get_target_instance(name, zone)
  true
rescue Fog::Errors::NotFound
  false
end

#reloadObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/compute/google/models/target_instance.rb', line 52

def reload
  requires :name, :zone

  begin
    data = collection.get(name, zone)
    new_attributes = data.attributes
    merge_attributes(new_attributes)
    return self
  rescue Excon::Errors::SocketError
    return nil
  end
end

#saveObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/compute/google/models/target_instance.rb', line 16

def save
  requires :name, :zone

  options = {
    "description" => description,
    "zone" => zone,
    "natPolicy" => nat_policy,
    "instance" => instance
  }

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