class IBM::Cloud::SDK::VPC::Instance
Work with a single instance.
Constants
- ERROR_STATE
- RUNNING_STATE
- STOPPED_STATES
- TRANSITIONAL_STATES
Public Instance Methods
Interact with instance actions. @return [INSTANCE::Actions]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 87 def actions INSTANCE::Actions.new(self) end
Whether the state of the VM is in failed state. @return [Boolean]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 63 def failed? status == ERROR_STATE end
The id of this VM.
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 47 def id @data[:id] end
Return the data used for initializing this VM.
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 104 def initialization adhoc(method: 'get', path: 'initialization').json end
The name of this VM.
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 52 def name @data[:name] end
Interact with instance network interfaces. @return [INSTANCE::NetworkInterfaces]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 93 def network_interfaces INSTANCE::NetworkInterfaces.new(self) end
Whether the state of the VM is in the started state. @return [Boolean]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 69 def started? status == RUNNING_STATE end
The status of the virtual server instance. Possible values: [failed,paused,pausing,pending,restarting,resuming,running,starting,stopped,stopping]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 57 def status @data[:status] end
Whether the state of the VM is in a stopped or paused state. @return [Boolean]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 75 def stopped? STOPPED_STATES.include?(status) end
Whether the state of the VM is in a transitional state. @return [Boolean]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 81 def transitional? TRANSITIONAL_STATES.include?(status) end
Interact with instance volume attachements. @return [INSTANCE::VolumeAttachments]
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 99 def volume_attachments INSTANCE::VolumeAttachments.new(self) end
Wait for the VM instance to be in a stable state. @param sleep_time [Integer] The time to sleep between refreshes. @param timeout [Integer] The number of seconds before raising an error. @param block [Proc] A block to test against. Must return a boolean. @raise [RuntimeError] Instance
goes into failed state. @raise [RuntimeError] Timeout has been reached.
# 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 the VM instance to be have a started status. @param sleep_time [Integer] The time to sleep between refreshes. @param timeout [Integer] The number of seconds before raising an error. @raise [RuntimeError] Instance
goes into failed state. @raise [RuntimeError] Timeout has been reached.
# 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 the VM instance to be have a stopped status. @param sleep_time [Integer] The time to sleep between refreshes. @param timeout [Integer] The number of seconds before raising an error. @raise [RuntimeError] Instance
goes into failed state. @raise [RuntimeError] Timeout has been reached.
# 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
Private Instance Methods
Sleep for the specificed time and decrement timout by that number. @return [Integer] The current timeout.
# File lib/ibm/cloud/sdk/vpc/instances.rb, line 149 def sleep_counter(sleep_time, timeout) sleep sleep_time timeout - sleep_time end