Module: Hyperkit::Client::Operations
- Included in:
- Hyperkit::Client
- Defined in:
- lib/hyperkit/client/operations.rb
Overview
Methods for the operations API
Instance Method Summary collapse
-
#cancel_operation(uuid) ⇒ Sawyer::Resource
Cancel a running operation.
-
#operation(uuid) ⇒ Sawyer::Resource
Retrieve information about an operation.
-
#operations ⇒ Array<String>
List of operations active on the server.
-
#wait_for_operation(uuid, timeout = nil) ⇒ Sawyer::Resource
Wait for an asynchronous operation to complete.
Instance Method Details
#cancel_operation(uuid) ⇒ Sawyer::Resource
Cancel a running operation
Calling this will change the state of the operation to cancelling
. Note that the operation must be cancelable, which can be ascertained by calling #operation and checking the may_cancel
property.
67 68 69 |
# File 'lib/hyperkit/client/operations.rb', line 67 def cancel_operation(uuid) delete(operation_path(uuid)). end |
#operation(uuid) ⇒ Sawyer::Resource
Retrieve information about an operation
51 52 53 |
# File 'lib/hyperkit/client/operations.rb', line 51 def operation(uuid) get(operation_path(uuid)). end |
#operations ⇒ Array<String>
List of operations active on the server
This will include operations that are currently executing, as well as operations that are paused until #wait_for_operation is called, at which time they will begin executing.
Additionally, since LXD keeps completed operations around for 5 seconds, the list returned may include recently completed operations.
26 27 28 29 |
# File 'lib/hyperkit/client/operations.rb', line 26 def operations response = get(operations_path) response..to_h.values.flatten.map { |path| path.split('/').last } end |
#wait_for_operation(uuid, timeout = nil) ⇒ Sawyer::Resource
Wait for an asynchronous operation to complete
Note that this is only needed if Hyperkit::Configurable#auto_sync has been set to false
, or if the option sync: false
has been passed to an asynchronous method.
Note that, after an operation completes, LXD keeps it around for only 5 seconds, so if you wait too long to call wait_for_operation
, you’ll get an exception when you eventually do call it.
94 95 96 97 98 99 |
# File 'lib/hyperkit/client/operations.rb', line 94 def wait_for_operation(uuid, timeout=nil) url = File.join(operation_path(uuid), "wait") url += "?timeout=#{timeout}" if timeout.to_i > 0 get(url). end |