Module: Morpheus::Cli::BackupsHelper
- Included in:
- BackupJobsCommand, BackupsCommand
- Defined in:
- lib/morpheus/cli/mixins/backups_helper.rb
Overview
Provides common methods for infrastructure management
Class Method Summary collapse
Instance Method Summary collapse
- #backup_job_list_key ⇒ Object
- #backup_job_object_key ⇒ Object
- #backup_jobs_interface ⇒ Object
- #backup_list_key ⇒ Object
- #backup_object_key ⇒ Object
- #backups_interface ⇒ Object
- #find_backup_by_id(id) ⇒ Object
- #find_backup_by_name(name) ⇒ Object
- #find_backup_by_name_or_id(val) ⇒ Object
- #find_backup_job_by_id(id) ⇒ Object
- #find_backup_job_by_name(name) ⇒ Object
- #find_backup_job_by_name_or_id(val) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
6 7 8 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 6 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#backup_job_list_key ⇒ Object
73 74 75 76 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 73 def backup_job_list_key # 'backupJobs' 'jobs' end |
#backup_job_object_key ⇒ Object
68 69 70 71 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 68 def backup_job_object_key # 'backupJob' 'job' end |
#backup_jobs_interface ⇒ Object
16 17 18 19 20 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 16 def backup_jobs_interface # @api_client.groups raise "#{self.class} has not defined @backup_jobs_interface" if @backup_jobs_interface.nil? @backup_jobs_interface end |
#backup_list_key ⇒ Object
26 27 28 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 26 def backup_list_key 'backups' end |
#backup_object_key ⇒ Object
22 23 24 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 22 def backup_object_key 'backup' end |
#backups_interface ⇒ Object
10 11 12 13 14 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 10 def backups_interface # @api_client.groups raise "#{self.class} has not defined @backups_interface" if @backups_interface.nil? @backups_interface end |
#find_backup_by_id(id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 38 def find_backup_by_id(id) begin json_response = backups_interface.get(id.to_i) return json_response[backup_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Backup not found by id '#{id}'" else raise e end end end |
#find_backup_by_name(name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 51 def find_backup_by_name(name) json_response = backups_interface.list({name: name.to_s}) backups = json_response[backup_list_key] if backups.empty? print_red_alert "Backup not found by name '#{name}'" return nil elsif backups.size > 1 print_red_alert "#{backups.size} backups found by name '#{name}'" puts_error as_pretty_table(backups, [:id, :name], {color:red}) print_red_alert "Try using ID instead" print reset,"\n" return nil else return backups[0] end end |
#find_backup_by_name_or_id(val) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 30 def find_backup_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_backup_by_id(val) else return find_backup_by_name(val) end end |
#find_backup_job_by_id(id) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 86 def find_backup_job_by_id(id) begin json_response = backup_jobs_interface.get(id.to_i) return json_response[backup_job_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Backup job not found by id '#{id}'" else raise e end end end |
#find_backup_job_by_name(name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 99 def find_backup_job_by_name(name) json_response = backup_jobs_interface.list({name: name.to_s}) backup_jobs = json_response[backup_job_list_key] if backup_jobs.empty? print_red_alert "Backup job not found by name '#{name}'" return nil elsif backup_jobs.size > 1 print_red_alert "#{backup_jobs.size} backup jobs found by name '#{name}'" puts_error as_pretty_table(backup_jobs, [:id, :name], {color:red}) print_red_alert "Try using ID instead" print reset,"\n" return nil else return backup_jobs[0] end end |
#find_backup_job_by_name_or_id(val) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/morpheus/cli/mixins/backups_helper.rb', line 78 def find_backup_job_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_backup_job_by_id(val) else return find_backup_job_by_name(val) end end |