Module: Pvectl::Commands::FeatureCommand

Included in:
FeatureContainer, FeatureVm
Defined in:
lib/pvectl/commands/feature_command.rb

Overview

Shared functionality for the feature query commands (feature vm, feature ct).

Queries whether a Proxmox feature (clone, snapshot, copy) is available for a given VM or container. Availability depends on storage type, snapshot state, and other server-side conditions.

Designed with the hybrid Template Method pattern (MoveDiskCommand / MigrateCommand) — specializations only set RESOURCE_TYPE and SUPPORTED_RESOURCES; the FeatureVm specialization additionally implements .register which wires the GLI command.

Examples:

Including in a command class

class FeatureVm
  include FeatureCommand
  RESOURCE_TYPE = :vm
  SUPPORTED_RESOURCES = %w[vm].freeze
end

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VALID_FEATURES =

Valid feature names per Proxmox API (both QEMU and LXC endpoints).

%w[clone snapshot copy].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Hook called when the module is included.

Parameters:

  • base (Class)

    the class including this module



43
44
45
# File 'lib/pvectl/commands/feature_command.rb', line 43

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#executeInteger

Executes the feature query.

Returns:

  • (Integer)

    exit code (0 if available, 1 if unavailable, 2 on usage)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pvectl/commands/feature_command.rb', line 61

def execute
  return usage_error("#{id_label} is required") if @args.empty?
  return usage_error("FEATURE is required") if @args.size < 2

  id_str = @args[0]
  feature = @args[1]

  unless id_str.to_s.match?(/\A\d+\z/)
    return usage_error("Invalid #{id_label}: #{id_str}")
  end

  unless VALID_FEATURES.include?(feature)
    return usage_error(
      "Invalid feature: #{feature} (allowed: #{VALID_FEATURES.join(', ')})"
    )
  end

  perform_operation(id_str.to_i, feature)
end

#initialize(args, options, global_options) ⇒ Object

Initializes a feature query command.

Parameters:

  • args (Array<String>)

    command-positional args ([id, feature])

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



52
53
54
55
56
# File 'lib/pvectl/commands/feature_command.rb', line 52

def initialize(args, options, global_options)
  @args = Array(args).compact
  @options = options
  @global_options = global_options
end