Class: Chef::Provisioning::GoogleDriver::Client::Instance
- Inherits:
-
Object
- Object
- Chef::Provisioning::GoogleDriver::Client::Instance
- 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
-
#determine_remote_host ⇒ Object
TODO right now we assume the host has a accessConfig which is public cloud.google.com/compute/docs/reference/latest/instances#resource.
- #id ⇒ Object
-
#initialize(response) ⇒ Instance
constructor
A new instance of Instance.
- #name ⇒ Object
- #running? ⇒ Boolean
- #status ⇒ Object
- #stopped? ⇒ Boolean
- #stopping? ⇒ Boolean
- #terminated? ⇒ Boolean
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_host ⇒ Object
TODO right now we assume the host has a accessConfig which is public cloud.google.com/compute/docs/reference/latest/instances#resource
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 |
#id ⇒ Object
19 20 21 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 19 def id @response[:body][:id] end |
#name ⇒ Object
15 16 17 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 15 def name @response[:body][:name] end |
#running? ⇒ Boolean
31 32 33 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 31 def running? status == "RUNNING" end |
#status ⇒ Object
23 24 25 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 23 def status @response[:body][:status] end |
#stopped? ⇒ Boolean
39 40 41 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 39 def stopped? status == "STOPPED" end |
#stopping? ⇒ Boolean
35 36 37 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 35 def stopping? status == "STOPPING" end |
#terminated? ⇒ Boolean
27 28 29 |
# File 'lib/chef/provisioning/google_driver/client/instance.rb', line 27 def terminated? status == "TERMINATED" end |