Class: Pvectl::Models::OperationResult
- Defined in:
- lib/pvectl/models/operation_result.rb
Overview
Represents the result of a lifecycle operation on a VM.
Combines VM, task status, and error information into a single object for consistent presentation of operation results.
Direct Known Subclasses
ContainerOperationResult, NodeOperationResult, VmOperationResult, VolumeOperationResult
Instance Attribute Summary collapse
-
#error ⇒ String?
readonly
Error message if operation failed.
-
#operation ⇒ Symbol
readonly
The operation performed (:start, :stop, etc.).
-
#resource ⇒ Hash?
readonly
Generic resource info (for snapshot/backup operations).
-
#success ⇒ Boolean, Symbol
readonly
True, false, or :pending.
-
#task ⇒ Models::Task?
readonly
The task (for completed sync operations).
-
#task_upid ⇒ String?
readonly
The task UPID (for async operations).
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Checks if the operation failed.
-
#initialize(attrs = {}) ⇒ OperationResult
constructor
Creates a new OperationResult.
-
#message ⇒ String
Returns the result message for display.
-
#partial? ⇒ Boolean
Checks if the operation partially succeeded (e.g. clone OK, config update failed).
-
#pending? ⇒ Boolean
Checks if the operation is still pending (async).
-
#status_text ⇒ String
Returns human-readable status.
-
#successful? ⇒ Boolean
Checks if the operation was successful.
Constructor Details
#initialize(attrs = {}) ⇒ OperationResult
Creates a new OperationResult.
47 48 49 50 51 52 53 54 55 |
# File 'lib/pvectl/models/operation_result.rb', line 47 def initialize(attrs = {}) super(attrs) @resource = @attributes[:resource] @operation = @attributes[:operation] @task = @attributes[:task] @task_upid = @attributes[:task_upid] @success = @attributes[:success] @error = @attributes[:error] end |
Instance Attribute Details
#error ⇒ String? (readonly)
Returns Error message if operation failed.
42 43 44 |
# File 'lib/pvectl/models/operation_result.rb', line 42 def error @error end |
#operation ⇒ Symbol (readonly)
Returns The operation performed (:start, :stop, etc.).
30 31 32 |
# File 'lib/pvectl/models/operation_result.rb', line 30 def operation @operation end |
#resource ⇒ Hash? (readonly)
Returns Generic resource info (for snapshot/backup operations).
27 28 29 |
# File 'lib/pvectl/models/operation_result.rb', line 27 def resource @resource end |
#success ⇒ Boolean, Symbol (readonly)
Returns true, false, or :pending.
39 40 41 |
# File 'lib/pvectl/models/operation_result.rb', line 39 def success @success end |
#task ⇒ Models::Task? (readonly)
Returns The task (for completed sync operations).
33 34 35 |
# File 'lib/pvectl/models/operation_result.rb', line 33 def task @task end |
#task_upid ⇒ String? (readonly)
Returns The task UPID (for async operations).
36 37 38 |
# File 'lib/pvectl/models/operation_result.rb', line 36 def task_upid @task_upid end |
Instance Method Details
#failed? ⇒ Boolean
Checks if the operation failed.
67 68 69 |
# File 'lib/pvectl/models/operation_result.rb', line 67 def failed? success == false || success == :partial || task&.failed? end |
#message ⇒ String
Returns the result message for display.
Priority: error > task.exitstatus > task_upid > status_text
101 102 103 104 105 106 107 |
# File 'lib/pvectl/models/operation_result.rb', line 101 def return error if error return task.exitstatus if task return "Task: #{task_upid}" if task_upid status_text end |
#partial? ⇒ Boolean
Checks if the operation partially succeeded (e.g. clone OK, config update failed).
81 82 83 |
# File 'lib/pvectl/models/operation_result.rb', line 81 def partial? success == :partial end |
#pending? ⇒ Boolean
Checks if the operation is still pending (async).
74 75 76 |
# File 'lib/pvectl/models/operation_result.rb', line 74 def pending? success == :pending || task&.pending? end |
#status_text ⇒ String
Returns human-readable status.
88 89 90 91 92 93 94 |
# File 'lib/pvectl/models/operation_result.rb', line 88 def status_text return "Pending" if pending? return "Partial" if partial? return "Success" if successful? "Failed" end |
#successful? ⇒ Boolean
Checks if the operation was successful.
60 61 62 |
# File 'lib/pvectl/models/operation_result.rb', line 60 def successful? success == true || task&.successful? end |