Class: Morpheus::Cli::BackupRestoresCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::BackupRestoresCommand
show all
- Includes:
- BackupsHelper, CliCommand
- Defined in:
- lib/morpheus/cli/commands/backup_restores_command.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#backup_job_list_key, #backup_job_object_key, #backup_jobs_interface, #backup_list_key, #backup_object_key, #backup_restore_column_definitions, #backup_restore_list_column_definitions, #backup_result_column_definitions, #backup_result_list_column_definitions, #backups_interface, #find_backup_by_id, #find_backup_by_name, #find_backup_by_name_or_id, #find_backup_job_by_id, #find_backup_job_by_name, #find_backup_job_by_name_or_id, #format_backup_restore_status, #format_backup_result_status, included
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#_get(id, params, options) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 93
def _get(id, params, options)
@backup_restores_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_restores_interface.dry.get(id, params)
return
end
json_response = @backup_restores_interface.get(id, params)
backup_restore = json_response['restore']
render_response(json_response, options, 'restore') do
backup_restore = json_response['restore']
backups = backup_restore['backups'] || []
print_h1 "Backup Restore Details", [], options
print cyan
print_description_list(backup_restore_column_definitions, backup_restore)
if backup_restore['errorMessage']
print_h2 "Error Message", options
print red, backup_restore['errorMessage'], reset, "\n"
end
print reset,"\n"
end
return 0, nil
end
|
#connect(opts) ⇒ Object
15
16
17
18
19
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 15
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@backups_interface = @api_client.backups
@backup_restores_interface = @api_client.backup_restores
end
|
#get(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 61
def get(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups get-restore [restore]"
build_standard_get_options(opts, options)
opts. = <<-EOT
Get details about a specific backup restore.
[restore] is required. This is the id of a backup restore.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1)
connect(options)
id_list = parse_id_list(args)
id_list = id_list.collect do |id|
if id.to_s =~ /\A\d{1,}\Z/
id
else
backup_restore = find_backup_restore_by_name(id)
if backup_restore
backup_restore['id']
else
return 1, "backup restore not found for name '#{id}'"
end
end
end
return run_command_for_each_arg(id_list) do |arg|
_get(arg, params, options)
end
end
|
#handle(args) ⇒ Object
21
22
23
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 21
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 25
def list(args)
options = {}
params = {}
ref_ids = []
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups list-restores [search]"
build_standard_list_options(opts, options)
opts. = "List backup restores."
end
optparse.parse!(args)
connect(options)
if args.count > 0
options[:phrase] = args.join(" ")
end
params.merge!(parse_list_options(options))
@backup_restores_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_restores_interface.dry.list(params)
return
end
json_response = @backup_restores_interface.list(params)
backup_restores = json_response['restores']
render_response(json_response, options, 'restores') do
print_h1 "Morpheus Backup Restores", parse_list_subtitles(options), options
if backup_restores.empty?
print yellow,"No backup restores found.",reset,"\n"
else
print as_pretty_table(backup_restores, backup_restore_list_column_definitions.upcase_keys!, options)
(json_response)
end
print reset,"\n"
end
return 0, nil
end
|
#remove(args) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/morpheus/cli/commands/backup_restores_command.rb', line 116
def remove(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups remove-restore [restore]"
build_standard_remove_options(opts, options)
opts. = <<-EOT
Delete a backup restore.
[restore] is required. This is the id of a backup restore.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
backup_restore = @backup_restores_interface.get(args[0])['restore']
parse_options(options, params)
confirm!("Are you sure you want to delete the backup restore #{backup_restore['id']}?", options)
execute_api(@backup_restores_interface, :destroy, [backup_restore['id']], options) do |json_response|
print_green_success "Removed backup restore #{backup_restore['name']}"
end
end
|