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
-
#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.
28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 28 def create @snapshot = Snapshot.new(snapshot_params.merge(host: @host).merge(include_ram: params[:snapshot][:include_ram])) 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
78 79 80 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 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 78 def create_multiple_host data = snapshot_params 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<br /><dl>%s</dl>') % errors.map { |e| "<dt>#{e[0]}</dt><dd>#{e[1]}</dd>" }.join('<br />') unless errors.empty? if snapshots_created > 0 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.
42 43 44 45 46 47 48 49 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 42 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
20 21 22 23 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 20 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.
54 55 56 57 58 59 60 61 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 54 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
76 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 76 def select_multiple_host; end |
#update ⇒ Object
Update Snapshot
This method renames a Snapshot from a given host.
66 67 68 69 70 71 72 73 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 66 def update if @snapshot.update_attributes(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
16 17 18 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 16 def xeditable?(_object = nil) true end |