Class: IBM::Cloud::SDK::VPC::Instance
- Inherits:
-
VPCInstance
- Object
- IBM::Cloud::SDKHTTP::BaseInstance
- VPCInstance
- IBM::Cloud::SDK::VPC::Instance
- Defined in:
- lib/ibm/cloud/sdk/vpc/instances.rb
Overview
Work with a single instance.
Constant Summary collapse
- TRANSITIONAL_STATES =
%w[pausing pending restarting resuming starting stopping].freeze
- ERROR_STATE =
'failed'- RUNNING_STATE =
'running'- STOPPED_STATES =
%w[stopped paused].freeze
Instance Attribute Summary
Attributes included from IBM::Cloud::SDKHTTP::BaseHTTPMixin
Attributes inherited from IBM::Cloud::SDKHTTP::BaseInstance
#connection, #endpoint, #logger, #token
Instance Method Summary collapse
-
#actions ⇒ INSTANCE::Actions
Interact with instance actions.
-
#failed? ⇒ Boolean
Whether the state of the VM is in failed state.
-
#id ⇒ Object
The id of this VM.
-
#initialization ⇒ Object
Return the data used for initializing this VM.
-
#name ⇒ Object
The name of this VM.
-
#network_interfaces ⇒ INSTANCE::NetworkInterfaces
Interact with instance network interfaces.
-
#started? ⇒ Boolean
Whether the state of the VM is in the started state.
-
#status ⇒ Object
The status of the virtual server instance.
-
#stopped? ⇒ Boolean
Whether the state of the VM is in a stopped or paused state.
-
#transitional? ⇒ Boolean
Whether the state of the VM is in a transitional state.
-
#volume_attachments ⇒ INSTANCE::VolumeAttachments
Interact with instance volume attachements.
-
#wait_for!(sleep_time: 5, timeout: 600, &block) ⇒ Object
Wait for the VM instance to be in a stable state.
-
#wait_for_started!(sleep_time: 5, timeout: 600) ⇒ Object
Wait for the VM instance to be have a started status.
-
#wait_for_stopped!(sleep_time: 5, timeout: 600) ⇒ Object
Wait for the VM instance to be have a stopped status.
Methods inherited from VPCInstance
Methods included from VpcHTTP
Methods included from IBM::Cloud::SDKHTTP::BaseHTTPMixin
#adhoc, #delete, #get, #metadata, #patch, #post, #put, #unchecked_response, #url
Methods inherited from IBM::Cloud::SDKHTTP::BaseInstance
#details, #initialize, #refresh, #remove, #update
Constructor Details
This class inherits a constructor from IBM::Cloud::SDKHTTP::BaseInstance
Instance Method Details
#actions ⇒ INSTANCE::Actions
Interact with instance actions.
87 88 89 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 87 def actions INSTANCE::Actions.new(self) end |
#failed? ⇒ Boolean
Whether the state of the VM is in failed state.
63 64 65 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 63 def failed? status == ERROR_STATE end |
#id ⇒ Object
The id of this VM.
47 48 49 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 47 def id @data[:id] end |
#initialization ⇒ Object
Return the data used for initializing this VM.
104 105 106 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 104 def initialization adhoc(method: 'get', path: 'initialization').json end |
#name ⇒ Object
The name of this VM.
52 53 54 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 52 def name @data[:name] end |
#network_interfaces ⇒ INSTANCE::NetworkInterfaces
Interact with instance network interfaces.
93 94 95 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 93 def network_interfaces INSTANCE::NetworkInterfaces.new(self) end |
#started? ⇒ Boolean
Whether the state of the VM is in the started state.
69 70 71 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 69 def started? status == RUNNING_STATE end |
#status ⇒ Object
The status of the virtual server instance. Possible values: [failed,paused,pausing,pending,restarting,resuming,running,starting,stopped,stopping]
57 58 59 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 57 def status @data[:status] end |
#stopped? ⇒ Boolean
Whether the state of the VM is in a stopped or paused state.
75 76 77 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 75 def stopped? STOPPED_STATES.include?(status) end |
#transitional? ⇒ Boolean
Whether the state of the VM is in a transitional state.
81 82 83 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 81 def transitional? TRANSITIONAL_STATES.include?(status) end |
#volume_attachments ⇒ INSTANCE::VolumeAttachments
Interact with instance volume attachements.
99 100 101 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 99 def INSTANCE::VolumeAttachments.new(self) end |
#wait_for!(sleep_time: 5, timeout: 600, &block) ⇒ Object
Wait for the VM instance to be in a stable state.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 114 def wait_for!(sleep_time: 5, timeout: 600, &block) @logger.info("Starting wait for instance #{id}. Starts in state #{status}.") loop do refresh raise "VM #{id} is in a failed state." if failed? break if block.call(self) timeout = sleep_counter(sleep_time, timeout) raise "Time out while waiting #{id} to be stable." if timeout <= 0 end @logger.info("Finished wait for instance #{id}. Ends in state #{status}.") end |
#wait_for_started!(sleep_time: 5, timeout: 600) ⇒ Object
Wait for the VM instance to be have a started status.
132 133 134 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 132 def wait_for_started!(sleep_time: 5, timeout: 600) wait_for!(sleep_time: sleep_time, timeout: timeout, &:started?) end |
#wait_for_stopped!(sleep_time: 5, timeout: 600) ⇒ Object
Wait for the VM instance to be have a stopped status.
141 142 143 |
# File 'lib/ibm/cloud/sdk/vpc/instances.rb', line 141 def wait_for_stopped!(sleep_time: 5, timeout: 600) wait_for!(sleep_time: sleep_time, timeout: timeout, &:stopped?) end |