Class: Pvectl::Services::ServiceLifecycle
- Inherits:
-
Object
- Object
- Pvectl::Services::ServiceLifecycle
- Defined in:
- lib/pvectl/services/service_lifecycle.rb
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
-
#execute(operation:, node:, service:) ⇒ Models::NodeOperationResult
Executes a lifecycle operation on a single service.
-
#initialize(service_repository:) ⇒ ServiceLifecycle
constructor
Creates a new ServiceLifecycle orchestrator.
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
#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 |