Class: Chef::Provisioning::GoogleDriver::Client::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provisioning/google_driver/client/instance.rb

Overview

Wraps a response of an instances.get request to the GCE API and provides access to information about the instance.

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Instance

Returns a new instance of Instance.



11
12
13
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 11

def initialize(response)
  @response = response
end

Instance Method Details

#determine_remote_hostObject

TODO right now we assume the host has a accessConfig which is public cloud.google.com/compute/docs/reference/latest/instances#resource

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 45

def determine_remote_host
  interfaces = @response[:body][:networkInterfaces]
  interfaces.each do |i|
    if i.key?(:accessConfigs)
      i[:accessConfigs].each do |a|
        if a.key?(:natIP)
          return a[:natIP]
        end
      end
    end
  end
  raise GoogleComputeError, "Server #{name} has no private or public IP address!"
end

#idObject



19
20
21
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 19

def id
  @response[:body][:id]
end

#nameObject



15
16
17
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 15

def name
  @response[:body][:name]
end

#running?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 31

def running?
  status == "RUNNING"
end

#statusObject



23
24
25
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 23

def status
  @response[:body][:status]
end

#stopped?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 39

def stopped?
  status == "STOPPED"
end

#stopping?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 35

def stopping?
  status == "STOPPING"
end

#terminated?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 27

def terminated?
  status == "TERMINATED"
end