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

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

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



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

def destroy(async=true)
  requires :name, :zone
  operation = service.delete_target_instance(name, zone)
  if not 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)


47
48
49
50
51
52
53
54
# File 'lib/fog/google/models/compute/target_instance.rb', line 47

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

#reloadObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/google/models/compute/target_instance.rb', line 56

def reload
  requires :name, :zone

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

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#saveObject



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

def save
  requires :name, :zone

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

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