2013-06-28 06:49:11 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/vcloudng/models/compute/disk'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Vcloudng
|
|
|
|
|
|
|
|
class Disks < Fog::Collection
|
|
|
|
model Fog::Compute::Vcloudng::Disk
|
|
|
|
|
|
|
|
attribute :vm_id
|
|
|
|
|
|
|
|
def index
|
|
|
|
disks.map{ |disk| new(disk.merge(all_disks: @disks, vm_id: vm_id))}
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
index
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(instance_id)
|
|
|
|
disk = disks.detect{ |disk| disk['InstanceID'] == instance_id }
|
|
|
|
return nil unless disk
|
|
|
|
new(disk.merge(all_disks: @disks, vm_id: vm_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_by_name(disk_name)
|
|
|
|
disk = disks.detect{ |disk| disk['element_name'] == disk_name }
|
|
|
|
return nil unless disk
|
|
|
|
new(disk.merge(all_disks: @disks, vm_id: vm_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(size)
|
|
|
|
disks unless @disks
|
|
|
|
data = Fog::Generators::Compute::Vcloudng::Disks.new(@disks)
|
|
|
|
data.add_hard_disk(size)
|
|
|
|
response = service.put_vm_disks(vm_id, data.disks)
|
2013-07-05 10:33:31 -04:00
|
|
|
service.process_task(response)
|
2013-06-28 06:49:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def disks
|
|
|
|
@disks = service.get_vm_disks(vm_id).body
|
|
|
|
@disks['disks']
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|