Class: Pvectl::Services::CreateContainer
- Inherits:
-
Object
- Object
- Pvectl::Services::CreateContainer
- Defined in:
- lib/pvectl/services/create_container.rb
Overview
Orchestrates LXC container creation operations.
Handles auto-CTID allocation, parameter building (mapping rootfs/mountpoints/net configs to Proxmox API format), sync/async modes, and optional auto-start.
Constant Summary collapse
- DEFAULT_TIMEOUT =
Returns Default timeout for create operations (seconds).
300- START_TIMEOUT =
Returns Default timeout for start operations (seconds).
60
Instance Method Summary collapse
-
#execute(ctid: nil, hostname:, node:, ostemplate:, cores: nil, memory: nil, swap: nil, rootfs: nil, mountpoints: nil, nets: nil, privileged: nil, features: nil, password: nil, ssh_public_keys: nil, onboot: nil, startup: nil, description: nil, tags: nil, pool: nil) ⇒ Models::ContainerOperationResult
Executes container creation operation.
-
#initialize(container_repository:, task_repository:, options: {}) ⇒ CreateContainer
constructor
Creates a new CreateContainer service.
Constructor Details
#initialize(container_repository:, task_repository:, options: {}) ⇒ CreateContainer
Creates a new CreateContainer service.
34 35 36 37 38 |
# File 'lib/pvectl/services/create_container.rb', line 34 def initialize(container_repository:, task_repository:, options: {}) @container_repository = container_repository @task_repository = task_repository @options = end |
Instance Method Details
#execute(ctid: nil, hostname:, node:, ostemplate:, cores: nil, memory: nil, swap: nil, rootfs: nil, mountpoints: nil, nets: nil, privileged: nil, features: nil, password: nil, ssh_public_keys: nil, onboot: nil, startup: nil, description: nil, tags: nil, pool: nil) ⇒ Models::ContainerOperationResult
Executes container creation operation.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pvectl/services/create_container.rb', line 62 def execute(ctid: nil, hostname:, node:, ostemplate:, cores: nil, memory: nil, swap: nil, rootfs: nil, mountpoints: nil, nets: nil, privileged: nil, features: nil, password: nil, ssh_public_keys: nil, onboot: nil, startup: nil, description: nil, tags: nil, pool: nil) ctid ||= @container_repository.next_available_ctid params = build_params( hostname: hostname, ostemplate: ostemplate, cores: cores, memory: memory, swap: swap, rootfs: rootfs, mountpoints: mountpoints, nets: nets, privileged: privileged, features: features, password: password, ssh_public_keys: ssh_public_keys, onboot: onboot, startup: startup, description: description, tags: , pool: pool ) upid = @container_repository.create(node, ctid, params) resource_info = { ctid: ctid, hostname: hostname, node: node } if @options[:async] build_result(resource_info, task_upid: upid, success: :pending) else task = @task_repository.wait(upid, timeout: timeout) start_container(ctid, node) if task.successful? && @options[:start] build_result(resource_info, task: task, success: task.successful?) end rescue StandardError => e build_result({ ctid: ctid, hostname: hostname, node: node }, success: false, error: e.) end |