Class: Pvectl::Commands::DeleteBackup
- Inherits:
-
Object
- Object
- Pvectl::Commands::DeleteBackup
- Defined in:
- lib/pvectl/commands/delete_backup.rb,
sig/pvectl/commands/delete_backup.rbs
Overview
Handler for the pvectl delete backup command.
Deletes a backup identified by its full volume ID (volid). Requires --yes flag for confirmation.
Class Method Summary collapse
-
.execute(resource_type, args, options, global_options) ⇒ Integer
Executes the delete backup command.
Instance Method Summary collapse
-
#determine_exit_code(results) ⇒ Integer
Determines exit code based on results.
-
#execute ⇒ Integer
Executes the delete backup command.
-
#initialize(resource_type, args, options, global_options) ⇒ DeleteBackup
constructor
Initializes a delete backup command.
-
#load_config ⇒ void
Loads configuration from file or environment.
-
#output_results(results) ⇒ void
Outputs operation results using the configured formatter.
-
#perform_operation ⇒ Integer
Performs the backup deletion operation.
-
#service_options ⇒ Hash
Builds service options from command options.
-
#usage_error(message) ⇒ Integer
Outputs usage error and returns exit code.
Constructor Details
#initialize(resource_type, args, options, global_options) ⇒ DeleteBackup
Initializes a delete backup command.
31 32 33 34 35 36 37 |
# File 'lib/pvectl/commands/delete_backup.rb', line 31 def initialize(resource_type, args, , ) @resource_type = resource_type @args = Array(args).compact = = @volid = @args.first end |
Class Method Details
.execute(resource_type, args, options, global_options) ⇒ Integer
Executes the delete backup command.
21 22 23 |
# File 'lib/pvectl/commands/delete_backup.rb', line 21 def self.execute(resource_type, args, , ) new(resource_type, args, , ).execute end |
Instance Method Details
#determine_exit_code(results) ⇒ Integer
Determines exit code based on results.
122 123 124 125 126 127 |
# File 'lib/pvectl/commands/delete_backup.rb', line 122 def determine_exit_code(results) return ExitCodes::SUCCESS if results.all?(&:successful?) return ExitCodes::SUCCESS if results.all?(&:pending?) ExitCodes::GENERAL_ERROR end |
#execute ⇒ Integer
Executes the delete backup command.
42 43 44 45 46 47 48 |
# File 'lib/pvectl/commands/delete_backup.rb', line 42 def execute return usage_error("Resource type required (backup)") unless @resource_type == "backup" return usage_error("Backup volid is required") if @volid.nil? || @volid.empty? return usage_error("Confirmation required: use --yes to confirm deletion") unless [:yes] perform_operation end |
#load_config ⇒ void
This method returns an undefined value.
Loads configuration from file or environment.
88 89 90 91 92 |
# File 'lib/pvectl/commands/delete_backup.rb', line 88 def load_config service = Pvectl::Config::Service.new service.load(config: [:config]) @config = service.current_config end |
#output_results(results) ⇒ void
This method returns an undefined value.
Outputs operation results using the configured formatter.
108 109 110 111 112 113 114 115 116 |
# File 'lib/pvectl/commands/delete_backup.rb', line 108 def output_results(results) presenter = Pvectl::Presenters::SnapshotOperationResult.new format = [:output] || "table" color_flag = [:color] formatter = Pvectl::Formatters::Registry.for(format) output = formatter.format(results, presenter, color: color_flag) puts output end |
#perform_operation ⇒ Integer
Performs the backup deletion operation.
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 |
# File 'lib/pvectl/commands/delete_backup.rb', line 55 def perform_operation load_config connection = Pvectl::Connection.new(@config) backup_repo = Pvectl::Repositories::Backup.new(connection) resolver = Pvectl::Utils::ResourceResolver.new(connection) task_repo = Pvectl::Repositories::Task.new(connection) service = Pvectl::Services::Backup.new( backup_repo: backup_repo, resource_resolver: resolver, task_repo: task_repo, options: ) result = service.delete(@volid) output_results([result]) determine_exit_code([result]) rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError raise rescue StandardError => e $stderr.puts "Error: #{e.message}" ExitCodes::GENERAL_ERROR end |
#service_options ⇒ Hash
Builds service options from command options.
97 98 99 100 101 102 |
# File 'lib/pvectl/commands/delete_backup.rb', line 97 def opts = {} opts[:timeout] = [:timeout] if [:timeout] opts[:async] = true if [:async] opts end |
#usage_error(message) ⇒ Integer
Outputs usage error and returns exit code.
133 134 135 136 |
# File 'lib/pvectl/commands/delete_backup.rb', line 133 def usage_error() $stderr.puts "Error: #{message}" ExitCodes::USAGE_ERROR end |