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".freeze

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



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

def destroy(async = true)
  requires :name, :zone
  data = service.delete_target_instance(name, zone)
  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name, data.zone)
  operation.wait_for { ready? } unless async
  operation
end

#ready?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/fog/compute/google/models/target_instance.rb', line 42

def ready?
  service.get_target_instance(name, zone)
  true
rescue ::Google::Apis::ClientError => e
  raise e unless e.status_code == 404
  false
end

#reloadObject



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

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
31
# File 'lib/fog/compute/google/models/target_instance.rb', line 16

def save
  requires :identity, :zone

  options = {
    :description => description,
    :zone => zone,
    :nat_policy => nat_policy,
    :instance => instance
  }

  data = service.insert_target_instance(identity, zone, options)
  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name, data.zone)
  operation.wait_for { ready? }
  reload
end