Class: Pvectl::Services::ServiceLifecycle
- Inherits:
-
Object
- Object
- Pvectl::Services::ServiceLifecycle
- Defined in:
- lib/pvectl/services/service_lifecycle.rb,
sig/pvectl/services/service_lifecycle.rbs
Overview
Orchestrates systemd service lifecycle operations (start/stop/restart/reload) on a Proxmox node.
Wraps Repositories::Service to provide a uniform return shape suitable for table/JSON/YAML formatting (Models::NodeOperationResult) and to convert API errors into structured results instead of raising.
Constant Summary collapse
- OPERATIONS =
Operations supported by the Proxmox services API.
i[start stop restart reload].freeze
Instance Method Summary collapse
-
#build_result(operation:, node:, service:, **attrs) ⇒ Models::NodeOperationResult
Builds a NodeOperationResult for the operation.
-
#execute(operation:, node:, service:) ⇒ Models::NodeOperationResult
Executes a lifecycle operation on a single service.
-
#initialize(service_repository:) ⇒ ServiceLifecycle
constructor
Creates a new ServiceLifecycle orchestrator.
-
#validate_operation!(operation) ⇒ void
Validates operation is one of the supported actions.
Constructor Details
#initialize(service_repository:) ⇒ ServiceLifecycle
Creates a new ServiceLifecycle orchestrator.
24 25 26 |
# File 'lib/pvectl/services/service_lifecycle.rb', line 24 def initialize(service_repository:) @service_repository = service_repository end |
Instance Method Details
#build_result(operation:, node:, service:, **attrs) ⇒ Models::NodeOperationResult
Builds a NodeOperationResult for the operation.
78 79 80 81 82 83 84 85 86 |
# File 'lib/pvectl/services/service_lifecycle.rb', line 78 def build_result(operation:, node:, service:, **attrs) node_model = Models::Node.new(name: node) Models::NodeOperationResult.new( operation: operation, node_model: node_model, resource: { service: service, node: node }, **attrs ) end |
#execute(operation:, node:, service:) ⇒ Models::NodeOperationResult
Executes a lifecycle operation on a single service.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pvectl/services/service_lifecycle.rb', line 35 def execute(operation:, node:, service:) validate_operation!(operation) begin upid = @service_repository.public_send(operation, node, service) build_result( operation: operation, node: node, service: service, task_upid: upid, success: :pending ) rescue StandardError => e build_result( operation: operation, node: node, service: service, success: false, error: e. ) end end |
#validate_operation!(operation) ⇒ void
This method returns an undefined value.
Validates operation is one of the supported actions.
64 65 66 67 68 69 |
# File 'lib/pvectl/services/service_lifecycle.rb', line 64 def validate_operation!(operation) return if OPERATIONS.include?(operation) raise ArgumentError, "Unknown service operation: #{operation}. Valid: #{OPERATIONS.join(', ')}" end |