Class: ForemanSnapshotManagement::SnapshotsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Foreman::Controller::Parameters::Snapshot
Defined in:
app/controllers/foreman_snapshot_management/snapshots_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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.full_messages.to_sentence
    process_error :error_msg => msg
  end
end

#destroyObject

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.full_messages.to_sentence
    process_error :error_msg => msg
  end
end

#indexObject



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

#revertObject

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.full_messages.to_sentence
    process_error :error_msg => msg
  end
end

#updateObject

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.full_messages.to_sentence
    render json: { errors: msg }, status: :unprocessable_entity
  end
end

#xeditable?(_object = nil) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/controllers/foreman_snapshot_management/snapshots_controller.rb', line 11

def xeditable?(_object = nil)
  true
end