Class: Morpheus::Cli::BackupResultsCommand

Inherits:
Object
  • Object
show all
Includes:
BackupsHelper, CliCommand
Defined in:
lib/morpheus/cli/commands/backup_results_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from BackupsHelper

#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_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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/morpheus/cli/commands/backup_results_command.rb', line 92

def _get(id, params, options)
  @backup_results_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @backup_results_interface.dry.get(id, params)
    return
  end
  json_response = @backup_results_interface.get(id, params)
  backup_result = json_response['result']
  render_response(json_response, options, 'result') do
    backup_result = json_response['result']
    backups = backup_result['backups'] || []
    print_h1 "Backup Result Details", [], options
    print cyan
    print_description_list(backup_result_column_definitions, backup_result)
    if backup_result['errorMessage']
      print_h2 "Error Message", options
      print red, backup_result['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_results_command.rb', line 15

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @backups_interface = @api_client.backups
  @backup_results_interface = @api_client.backup_results
end

#get(args) ⇒ Object



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
# File 'lib/morpheus/cli/commands/backup_results_command.rb', line 60

def get(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = "Usage: #{prog_name} backups get-result [result]"
    build_standard_get_options(opts, options)
    opts.footer = <<-EOT
Get details about a specific backup result.
[result] is required. This is the id of a backup result.
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_result = find_backup_result_by_name(id)
      if backup_result
        backup_result['id']
      else
        return 1, "backup result 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_results_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
# File 'lib/morpheus/cli/commands/backup_results_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-results [search]"
    opts.on('--backup BACKUP', String, "Backup Name or ID") do |val|
      options[:backup] = val
    end
    opts.on('--instance INSTANCE', String, "Instance Name or ID") do |val|
      options[:instance] = val
    end
    build_standard_list_options(opts, options)
    opts.footer = "List backup results."
  end
  optparse.parse!(args)
  connect(options)
  # verify_args!(args:args, optparse:optparse, max:1)
  parse_list_options!(args, options, params)
  execute_api(@backup_results_interface, :list, [], options, 'results') do |json_response|
    backup_results = json_response['results']
    subtitles = []
    subtitles << "Backup: #{options[:backup]}" if options[:backup]
    subtitles += parse_list_subtitles(options)
    print_h1 "Morpheus Backup Results", subtitles, options
    if backup_results.empty?
      print yellow,"No backup results found.",reset,"\n"
    else
      print as_pretty_table(backup_results, backup_result_list_column_definitions.upcase_keys!, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
end

#remove(args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/morpheus/cli/commands/backup_results_command.rb', line 115

def remove(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = "Usage: #{prog_name} backups remove-result [result]"
    build_standard_remove_options(opts, options)
    opts.footer = <<-EOT
Delete a backup result.
[result] is required. This is the id of a backup result.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  backup_result = @backup_results_interface.get(args[0])['result']
  # backup_result = find_backup_result_by_name_or_id(args[0])
  # return 1 if backup_result.nil?
  parse_options(options, params)
  confirm!("Are you sure you want to delete the backup result #{backup_result['id']}?", options)
  execute_api(@backup_results_interface, :destroy, [backup_result['id']], options) do |json_response|
    print_green_success "Removed backup result #{backup_result['name']}"
  end
end