Class: ForemanSnapshotManagement::SnapshotsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForemanSnapshotManagement::SnapshotsController
- Includes:
- Foreman::Controller::Parameters::Snapshot
- Defined in:
- app/controllers/foreman_snapshot_management/snapshots_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create a Snapshot.
-
#destroy ⇒ Object
Remove Snapshot.
- #index ⇒ Object
-
#revert ⇒ Object
Revert Snapshot.
-
#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.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 23 def create @snapshot = Snapshot.new(snapshot_params.merge(host: @host)) if @snapshot.create process_success else msg = _('Error occurred while creating Snapshot: %s') % @snapshot.errors..to_sentence process_error :error_msg => msg end end |
#destroy ⇒ Object
Remove Snapshot
This method removes a Snapshot from a given host.
37 38 39 40 41 42 43 44 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 37 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
15 16 17 18 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 15 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.
49 50 51 52 53 54 55 56 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 49 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 |
#update ⇒ Object
Update Snapshot
This method renames a Snapshot from a given host.
61 62 63 64 65 66 67 68 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 61 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
11 12 13 |
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 11 def xeditable?(_object = nil) true end |