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
72
73
74
75
76
77
# File 'app/controllers/volumes_controller.rb', line 66

def attach
  instance_id = params[:instance_id]
  volume_ids = params[:volume_ids]
  res = []
  volume_ids.each do |volume_id|
    data = {
      :volume_id => volume_id
    }
    res << DcmgrResource::Volume.attach(volume_id, instance_id)
  end
  render :json => res
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
    res = []
    snapshot_ids.each do |snapshot_id|
      data = {
        :snapshot_id => snapshot_id
      }
      res << DcmgrResource::Volume.create(data)
    end
    render :json => res
  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]
  res = []
  volume_ids.each do |volume_id|
    res << DcmgrResource::Volume.destroy(volume_id)
  end
  render :json => res
end

#detachObject



79
80
81
82
83
84
85
86
# File 'app/controllers/volumes_controller.rb', line 79

def detach
  volume_ids = params[:ids]
  res = []
  volume_ids.each do |volume_id|
    res << DcmgrResource::Volume.detach(volume_id)
  end
  render :json => res
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



88
89
90
91
92
93
94
95
# File 'app/controllers/volumes_controller.rb', line 88

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