Class: Pvectl::Commands::SetVolume
- Inherits:
-
Object
- Object
- Pvectl::Commands::SetVolume
- Extended by:
- ClassMethods
- Defined in:
- lib/pvectl/commands/set_volume.rb
Overview
Handler for the ‘pvectl set volume` command.
Does NOT use SetResourceCommand template — has custom flow due to different argument structure (resource_type + id + disk + key=value).
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the set volume command.
-
#initialize(args, options, global_options) ⇒ SetVolume
constructor
Initializes a set volume command.
Constructor Details
#initialize(args, options, global_options) ⇒ SetVolume
Initializes a set volume command.
40 41 42 43 44 |
# File 'lib/pvectl/commands/set_volume.rb', line 40 def initialize(args, , ) @args = args @options = @global_options = end |
Instance Method Details
#execute ⇒ Integer
Executes the set volume command.
49 50 51 52 53 54 55 56 57 58 59 60 61 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 90 91 92 |
# File 'lib/pvectl/commands/set_volume.rb', line 49 def execute resource_type = @args[0] resource_id = @args[1] disk = @args[2] key_value_args = @args[3..] || [] return usage_error("Resource type required (vm, container)") unless resource_type return usage_error("Resource ID is required") unless resource_id return usage_error("Volume name is required (e.g., scsi0, rootfs)") unless disk key_values = parse_key_values(key_value_args) return usage_error("At least one key=value pair is required") if key_values.empty? load_config connection = Pvectl::Connection.new(@config) node = resolve_node(resource_id.to_i, connection, resource_type) return ExitCodes::NOT_FOUND unless node # Confirmation for resize operations if key_values.key?("size") && !@options[:yes] return ExitCodes::SUCCESS unless confirm_resize(resource_id, disk, key_values["size"]) end repo = build_repository(connection, resource_type) service = Pvectl::Services::SetVolume.new( repository: repo, resource_type: resource_type_symbol(resource_type) ) result = service.execute(id: resource_id.to_i, disk: disk, params: key_values, node: node) output_result(result) result.successful? ? ExitCodes::SUCCESS : ExitCodes::GENERAL_ERROR rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError raise rescue StandardError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR end |