Class: Morpheus::Cli::BackupJobsCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::BackupJobsCommand
show all
- Includes:
- BackupsHelper, CliCommand
- Defined in:
- lib/morpheus/cli/commands/backup_jobs_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 96
def _get(id, params, options)
@backup_jobs_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_jobs_interface.dry.get(id, params)
return
end
json_response = @backup_jobs_interface.get(id, params)
backup_job = json_response['job']
render_response(json_response, options, 'job') do
backup_job = json_response['job']
backups = backup_job['backups'] || []
print_h1 "Backup Job Details", [], options
print cyan
columns = backup_job_column_definitions
columns.delete("Provider") if backup_job['backupProvider'].nil?
columns.delete("Repository") if backup_job['backupRepository'].nil?
columns.delete("Synthetic Full Enabled") if backup_job['syntheticFull'].nil?
columns.delete("Synthetic Full Schedule") if backup_job['syntheticFull'].nil?
columns.delete("Synthetic Full Next") if backup_job['syntheticFull'].nil?
print_description_list(columns, backup_job)
print_h2 "Backups", options
if backups.empty?
print yellow,"This job has no backups associated with it.",reset,"\n"
else
print as_pretty_table(backups, [:id, :name], options)
end
print reset,"\n"
end
return 0, nil
end
|
#add(args) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 128
def add(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups add-job [name]"
build_option_type_options(opts, options, add_backup_job_option_types)
build_standard_add_options(opts, options)
opts. = <<-EOT
Create a new backup job
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:0, max:1)
options[:options]['name'] = args[0] if args[0]
connect(options)
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'job' => parse_passed_options(options)})
else
payload.deep_merge!({'job' => parse_passed_options(options)})
avail_job_types = @options_interface.options_for_source('backupJobTypes',{})['data']
if avail_job_types.empty?
raise_command_error "No available backup job types found"
else
params["jobTypeId"] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'jobTypeId', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => avail_job_types, 'defaultValue' => avail_job_types[0] ? avail_job_types[0]['name'] : nil, 'required' => true}], options[:options], @api_client)["jobTypeId"]
end
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_backup_job_option_types, options[:options], @api_client, options[:params])
params.deep_merge!(v_prompt)
if params['scheduleId'] == 'manual' || params['scheduleId'] == ''
params['scheduleId'] = nil
end
job_type_config = Morpheus::Cli::OptionTypes.prompt(add_backup_job_type_option_types("new", params["jobTypeId"], options), options[:options].deep_merge({ :context_map => { 'domain' => ''}}), @api_client, options[:params])
job_type_config.deep_compact!
params.deep_merge!(job_type_config)
payload['job'].deep_merge!(params)
end
@backup_jobs_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_jobs_interface.dry.create(payload)
return 0, nil
end
json_response = @backup_jobs_interface.create(payload)
backup_job = json_response['job']
render_response(json_response, options, 'job') do
print_green_success "Added backup job #{backup_job['name']}"
return _get(backup_job["id"], {}, options)
end
return 0, nil
end
|
#connect(opts) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 15
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@backups_interface = @api_client.backups
@backup_jobs_interface = @api_client.backup_jobs
@backup_settings_interface = @api_client.backup_settings
@options_interface = @api_client.options
end
|
#execute(args) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 258
def execute(args)
options = {}
params = {}
payload = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups execute-job [job]"
build_standard_post_options(opts, options)
opts. = <<-EOT
Execute a backup job to create a new backup result for all the backups in the job.
[job] is required. This is the name or id of a backup job.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
backup_job = find_backup_job_by_name_or_id(args[0])
return 1 if backup_job.nil?
parse_payload(options) do |payload|
end
execute_api(@backup_jobs_interface, :execute_job, [backup_job['id']], options, 'job') do |json_response|
print_green_success "Executing backup job #{backup_job['name']}"
end
end
|
#get(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 63
def get(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups get-job [job]"
build_standard_get_options(opts, options)
opts. = <<-EOT
Get details about a specific backup job.
[job] is required. This is the id or name a backup job.
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_job = find_backup_job_by_name(id)
if backup_job
backup_job['id']
else
return 1, "backup job 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
23
24
25
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 23
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
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
60
61
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 27
def list(args)
options = {}
params = {}
ref_ids = []
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups list-jobs [search]"
build_standard_list_options(opts, options)
opts. = "List backup jobs."
end
optparse.parse!(args)
connect(options)
if args.count > 0
options[:phrase] = args.join(" ")
end
params.merge!(parse_list_options(options))
@backup_jobs_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_jobs_interface.dry.list(params)
return
end
json_response = @backup_jobs_interface.list(params)
backup_jobs = json_response['jobs']
render_response(json_response, options, 'jobs') do
print_h1 "Morpheus Backup Jobs", parse_list_subtitles(options), options
if backup_jobs.empty?
print yellow,"No backup jobs found.",reset,"\n"
else
print as_pretty_table(backup_jobs, backup_job_list_column_definitions.upcase_keys!, options)
(json_response)
end
print reset,"\n"
end
return 0, nil
end
|
#remove(args) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 235
def remove(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups remove-job [job]"
build_standard_remove_options(opts, options)
opts. = <<-EOT
Delete a backup job.
[job] is required. This is the name or id of a backup job.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
backup_job = find_backup_job_by_name_or_id(args[0])
return 1 if backup_job.nil?
parse_options(options, params)
confirm!("Are you sure you want to delete the backup job #{backup_job['name']}?", options)
execute_api(@backup_jobs_interface, :destroy, [backup_job['id']], options) do |json_response|
print_green_success "Removed backup job #{backup_job['name']}"
end
end
|
#update(args) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/morpheus/cli/commands/backup_jobs_command.rb', line 183
def update(args)
options = {}
params = {}
payload = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} backups update-job [job]"
build_option_type_options(opts, options, update_backup_job_option_types)
build_standard_update_options(opts, options)
opts. = <<-EOT
Update a backup job.
[job] is required. This is the name or id of a backup job.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
backup_job = find_backup_job_by_name_or_id(args[0])
return 1 if backup_job.nil?
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'job' => parse_passed_options(options)})
else
payload.deep_merge!({'job' => parse_passed_options(options)})
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_backup_job_option_types, options[:options], @api_client, options[:params])
v_prompt.deep_compact!
if v_prompt['scheduleId'] == 'manual' || v_prompt['scheduleId'] == ''
v_prompt['scheduleId'] = nil
end
params.deep_merge!(v_prompt)
advanced_config = Morpheus::Cli::OptionTypes.no_prompt(update_backup_job_type_option_types("new", get_object_value(backup_job, "jobType.id"), options[:params]), options[:options], @api_client, options[:params])
advanced_config.deep_compact!
params.deep_merge!(advanced_config)
payload.deep_merge!({'job' => params})
if payload['job'].empty? raise_command_error "Specify at least one option to update.\n#{optparse}"
end
end
@backup_jobs_interface.setopts(options)
if options[:dry_run]
print_dry_run @backup_jobs_interface.dry.update(backup_job['id'], payload)
return
end
json_response = @backup_jobs_interface.update(backup_job['id'], payload)
backup_job = json_response['job']
render_response(json_response, options, 'job') do
print_green_success "Updated backup job #{backup_job['name']}"
return _get(backup_job["id"], {}, options)
end
return 0, nil
end
|