Class: SnapshotsController

Inherits:
ApplicationController show all
Includes:
Util
Defined in:
app/controllers/snapshots_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#dispatch, #get_locales, #is_dcmgr?, #set_application, #set_locale

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/snapshots_controller.rb', line 8

def create
  volume_ids = params[:ids]
  destination = params[:destination]
  res = []
  volume_ids.each do |volume_id|
    data = {
      :volume_id => volume_id,
      :destination => destination
    }
    res << DcmgrResource::VolumeSnapshot.create(data)
  end
  render :json => res
end

#destroyObject



22
23
24
25
26
27
28
29
# File 'app/controllers/snapshots_controller.rb', line 22

def destroy
  snapshot_ids = params[:ids]
  res = []
  snapshot_ids.each do |snapshot_id|
    res << DcmgrResource::VolumeSnapshot.delete(snapshot_id)
  end
  render :json => res
end

#indexObject



5
6
# File 'app/controllers/snapshots_controller.rb', line 5

def index
end

#listObject



31
32
33
34
35
36
37
38
# File 'app/controllers/snapshots_controller.rb', line 31

def list
  data = {
    :start => params[:start].to_i - 1,
    :limit => params[:limit]
  }
  snapshots = DcmgrResource::VolumeSnapshot.list(data)
  respond_with(snapshots[0], :to => [:json])
end

#showObject



40
41
42
43
44
# File 'app/controllers/snapshots_controller.rb', line 40

def show
  snapshot_id = params[:id]
  detail = DcmgrResource::VolumeSnapshot.show(snapshot_id)
  respond_with(detail,:to => [:json])
end

#totalObject



46
47
48
49
50
51
52
53
# File 'app/controllers/snapshots_controller.rb', line 46

def total
  all_resource_count = DcmgrResource::VolumeSnapshot.total_resource
  all_resources = DcmgrResource::VolumeSnapshot.find(:all,:params => {:start => 0, :limit => all_resource_count})
  resources = all_resources[0].results
  deleted_resource_count = DcmgrResource::VolumeSnapshot.get_resource_state_count(resources, 'deleted')
  total = all_resource_count - deleted_resource_count
  render :json => total
end

#upload_destinationObject



55
56
57
58
# File 'app/controllers/snapshots_controller.rb', line 55

def upload_destination
  destinations = DcmgrResource::VolumeSnapshot.upload_destination
  render :json => destinations[0]
end