1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vcloudng/models/compute/disks.rb

69 lines
1.8 KiB
Ruby
Raw Normal View History

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 < Collection
2013-06-28 06:49:11 -04:00
model Fog::Compute::Vcloudng::Disk
attribute :vm
2013-06-28 06:49:11 -04:00
# 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
2013-06-28 06:49:11 -04:00
def create(size)
item_list unless @disks
2013-06-28 06:49:11 -04:00
data = Fog::Generators::Compute::Vcloudng::Disks.new(@disks)
puts data
puts data.disks
2013-06-28 06:49:11 -04:00
data.add_hard_disk(size)
response = service.put_vm_disks(vm.id, data.disks)
service.process_task(response.body)
2013-06-28 06:49:11 -04:00
end
def get_by_id(item_id)
item = item_list.detect{ |i| i[:id] == item_id}
item.merge!(all_disks: @disks, vm: vm) if item
item
end
def item_list
@disks = service.get_vm_disks(vm.id).body
items = @disks[:disks]
items.each do |disk|
disk[:all_disks] = @disks
disk[:vm] = vm
end
items
2013-06-28 06:49:11 -04:00
end
# private
# def disks
# @disks = service.get_vm_disks(vm_id).body
# @disks['disks']
# end
2013-06-28 06:49:11 -04:00
end
end
end
end