Class: Pvectl::Commands::CloneContainer

Inherits:
Object
  • Object
show all
Includes:
SharedConfigParsers
Defined in:
lib/pvectl/commands/clone_container.rb

Overview

Handler for the ‘pvectl clone container` command.

Clones a container by CTID, supporting full and linked clones, custom hostname, target node, storage, pool, and description. No batch operations - clones exactly one container at a time.

Examples:

Full clone with auto-generated CTID

pvectl clone container 100

Clone with custom hostname and target CTID

pvectl clone container 100 --vmid 200 --name web-clone

Linked clone to different node

pvectl clone container 100 --linked --target pve2

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedConfigParsers

#build_ct_config_params, #build_vm_config_params, #parse_ct_mountpoints, #parse_ct_nets, #parse_vm_cloud_init, #parse_vm_disks, #parse_vm_nets

Constructor Details

#initialize(args, options, global_options) ⇒ CloneContainer

Initializes a clone container command.

Parameters:

  • args (Array<String>)

    command arguments

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



38
39
40
41
42
# File 'lib/pvectl/commands/clone_container.rb', line 38

def initialize(args, options, global_options)
  @args = args
  @options = options
  @global_options = global_options
end

Class Method Details

.execute(args, options, global_options) ⇒ Integer

Executes the clone container command.

Parameters:

  • args (Array<String>)

    command arguments (CTID)

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options

Returns:

  • (Integer)

    exit code



29
30
31
# File 'lib/pvectl/commands/clone_container.rb', line 29

def self.execute(args, options, global_options)
  new(args, options, global_options).execute
end

Instance Method Details

#executeInteger

Executes the clone container command.

Builds config params from shared flags, validates async+config compatibility, and delegates to the clone operation.

Returns:

  • (Integer)

    exit code



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pvectl/commands/clone_container.rb', line 50

def execute
  ctid = @args.first
  return usage_error("Source CTID required") unless ctid

  config_params = build_ct_config_params

  if @options[:async] && !config_params.empty?
    return usage_error("Config flags require sync mode (remove --async)")
  end

  perform_clone(ctid.to_i, config_params)
end