Class: VolumesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Instance Method Details

#attachObject



66
67
68
69
70
71
# File 'app/controllers/volumes_controller.rb', line 66

def attach
  volume_id = params[:volume_id]
  instance_id = params[:instance_id]
  response = DcmgrResource::Volume.attach(volume_id, instance_id)
  render :json => response
end

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/volumes_controller.rb', line 8

def create
  snapshot_ids = params[:ids]
  if snapshot_ids
    response = []
    snapshot_ids.each do |snapshot_id|
      data = {
        :snapshot_id => snapshot_id
      }
      response << DcmgrResource::Volume.create(data)
    end
    render :json => response
  else
    # Convert to MB
    size = case params[:unit]
           when 'gb'
             params[:size].to_i * 1024
           when 'tb'
             params[:size].to_i * 1024 * 1024
           end
    
    storage_pool_id = params[:storage_pool_id] #option
    
    data = {
      :volume_size => size,
      :storage_pool_id => storage_pool_id
    }
    
    @volume = DcmgrResource::Volume.create(data)

    render :json => @volume
  end
end

#destroyObject



41
42
43
44
45
46
47
48
# File 'app/controllers/volumes_controller.rb', line 41

def destroy
  volume_ids = params[:ids]
  response = []
  volume_ids.each do |volume_id|
    response << DcmgrResource::Volume.destroy(volume_id)
  end
  render :json => response
end

#detachObject



73
74
75
76
77
78
79
80
# File 'app/controllers/volumes_controller.rb', line 73

def detach
  volume_ids = params[:ids]
  response = []
  volume_ids.each do |volume_id|
    response << DcmgrResource::Volume.detach(volume_id)
  end
  render :json => response
end

#indexObject



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

def index
end

#listObject



50
51
52
53
54
55
56
57
# File 'app/controllers/volumes_controller.rb', line 50

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

#showObject

GET volumes/vol-24f1af4d.json



60
61
62
63
64
# File 'app/controllers/volumes_controller.rb', line 60

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

#totalObject



82
83
84
85
86
87
88
89
# File 'app/controllers/volumes_controller.rb', line 82

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