Class: ForemanSnapshotManagement::SnapshotsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForemanSnapshotManagement::SnapshotsController
- Includes:
- Foreman::Controller::ActionPermissionDsl, Foreman::Controller::Parameters::Snapshot
- Defined in:
- app/controllers/foreman_snapshot_management/snapshots_controller.rb
Constant Summary collapse
- MULTIPLE_ACTIONS =
%w[select_multiple_host create_multiple_host].freeze
Instance Method Summary collapse
-
#create ⇒ Object
Create a Snapshot.
- #create_multiple_host ⇒ Object
-
#destroy ⇒ Object
Remove Snapshot.
- #index ⇒ Object
-
#revert ⇒ Object
Revert Snapshot.
- #select_multiple_host ⇒ Object
- #snapshot_mode_assignment(snapshot_mode, data) ⇒ Object
-
#update ⇒ Object
Update Snapshot.
- #xeditable?(_object = nil) ⇒ Boolean
Instance Method Details
#create ⇒ Object
Create a Snapshot.
This method creates a Snapshot with a given name and optional description.
30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 30 def create @snapshot = Snapshot.new(snapshot_params.merge(host: @host).merge(include_ram: params[:snapshot][:include_ram], quiesce: params[:snapshot][:quiesce])) if @snapshot.create process_success else msg = _('Error occurred while creating Snapshot: %s') % @snapshot.errors..to_sentence process_error :error_msg => msg end end |
#create_multiple_host ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 81 def create_multiple_host data = snapshot_params snapshot_mode_assignment(params[:snapshot][:snapshot_mode], data) snapshots_created = 0 errors = [] @hosts.each do |h| s = Snapshot.new(data.merge(host: h)) if s.create snapshots_created += 1 else errors << [h.name, s.errors..to_sentence] end end error _('Error occurred while creating Snapshot for:%s') % "<br /><dl>#{errors.map { |e| "<dt>#{e[0]}</dt><dd>#{e[1]}</dd>" }.join('<br />')}</dl>" unless errors.empty? if snapshots_created.positive? msg = _('Created %{snapshots} for %{num} %{hosts}') % { snapshots: n_('Snapshot', 'Snapshots', snapshots_created), num: snapshots_created, hosts: n_('host', 'hosts', snapshots_created), } # for backwards compatibility if respond_to? :success success msg else notice msg end end redirect_back_or_to hosts_path end |
#destroy ⇒ Object
Remove Snapshot
This method removes a Snapshot from a given host.
44 45 46 47 48 49 50 51 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 44 def destroy if @snapshot.destroy process_success else msg = _('Error occurred while removing Snapshot: %s') % @snapshot.errors..to_sentence process_error :error_msg => msg end end |
#index ⇒ Object
22 23 24 25 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 22 def index @new_snapshot = Snapshot.new(host: @host) render partial: 'index' end |
#revert ⇒ Object
Revert Snapshot
This method reverts a host to a given Snapshot.
56 57 58 59 60 61 62 63 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 56 def revert if @snapshot.revert process_success :success_msg => _('VM successfully rolled back.') else msg = _('Error occurred while rolling back VM: %s') % @snapshot.errors..to_sentence process_error :error_msg => msg end end |
#select_multiple_host ⇒ Object
78 79 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 78 def select_multiple_host end |
#snapshot_mode_assignment(snapshot_mode, data) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 111 def snapshot_mode_assignment(snapshot_mode, data) case snapshot_mode when 'memory' data[:include_ram] = true data[:quiesce] = false when 'quiesce' data[:include_ram] = false data[:quiesce] = true else data[:include_ram] = false data[:quiesce] = false end end |
#update ⇒ Object
Update Snapshot
This method renames a Snapshot from a given host.
68 69 70 71 72 73 74 75 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 68 def update if @snapshot.update(snapshot_params) render json: { name: @snapshot.name, description: @snapshot.description } else msg = _('Failed to update Snapshot: %s') % @snapshot.errors..to_sentence render json: { errors: msg }, status: :unprocessable_entity end end |
#xeditable?(_object = nil) ⇒ Boolean
18 19 20 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 18 def xeditable?(_object = nil) true end |