Class: Pvectl::Commands::EditVolume
- Inherits:
-
Object
- Object
- Pvectl::Commands::EditVolume
- Extended by:
- ClassMethods
- Defined in:
- lib/pvectl/commands/edit_volume.rb
Overview
Handler for the ‘pvectl edit volume` command.
Does NOT use EditResourceCommand template — has custom flow due to different argument structure (resource_type + id + disk).
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the edit volume command.
-
#initialize(args, options, global_options) ⇒ EditVolume
constructor
A new instance of EditVolume.
Constructor Details
#initialize(args, options, global_options) ⇒ EditVolume
Returns a new instance of EditVolume.
38 39 40 41 42 |
# File 'lib/pvectl/commands/edit_volume.rb', line 38 def initialize(args, , ) @args = args @options = @global_options = end |
Instance Method Details
#execute ⇒ Integer
Executes the edit volume command.
47 48 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 93 94 95 96 |
# File 'lib/pvectl/commands/edit_volume.rb', line 47 def execute resource_type = @args[0] resource_id = @args[1] disk = @args[2] 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 load_config connection = Pvectl::Connection.new(@config) node = resolve_node(resource_id.to_i, connection, resource_type) return ExitCodes::NOT_FOUND unless node repo = build_repository(connection, resource_type) service = Pvectl::Services::EditVolume.new( repository: repo, resource_type: resource_type_symbol(resource_type), editor_session: build_editor_session, options: ) result = service.execute(id: resource_id.to_i, disk: disk, node: node) if result.nil? $stdout.puts "Edit cancelled, no changes made." return ExitCodes::SUCCESS end if result.successful? if @options[:"dry-run"] $stdout.puts "(dry-run mode — no changes applied)" else $stdout.puts "Volume #{disk} on #{resource_type} #{resource_id} updated successfully." end ExitCodes::SUCCESS else $stderr.puts "Error: #{result.error}" ExitCodes::GENERAL_ERROR end 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 |