2013-06-28 06:49:11 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Vcloudng
|
|
|
|
|
|
|
|
class Disk < Fog::Model
|
|
|
|
|
|
|
|
|
|
|
|
identity :id, :aliases => 'instance_id'
|
|
|
|
identity :vm_id
|
|
|
|
|
|
|
|
|
|
|
|
attribute :address
|
|
|
|
attribute :description
|
|
|
|
attribute :element_name
|
|
|
|
attribute :instance_id
|
|
|
|
attribute :resource_sub_type
|
|
|
|
attribute :resource_type
|
|
|
|
attribute :address_on_parent
|
|
|
|
attribute :parent
|
|
|
|
attribute :capacity
|
|
|
|
attribute :bus_sub_type
|
|
|
|
attribute :bus_type
|
|
|
|
|
2013-07-05 10:33:31 -04:00
|
|
|
# TODO Virtual machine disk sizes may only be increased, not decreased.
|
2013-06-28 06:49:11 -04:00
|
|
|
def capacity=(new_capacity)
|
2013-07-05 10:33:31 -04:00
|
|
|
has_changed = ( capacity != new_capacity.to_i )
|
|
|
|
not_first_set = !capacity.nil?
|
2013-06-28 06:49:11 -04:00
|
|
|
attributes[:capacity] = new_capacity.to_i
|
2013-07-05 10:33:31 -04:00
|
|
|
if not_first_set && has_changed
|
|
|
|
data = Fog::Generators::Compute::Vcloudng::Disks.new(all_disks)
|
|
|
|
num_disk = element_name.scan(/\d+/).first.to_i
|
|
|
|
data.modify_hard_disk_size(num_disk, new_capacity)
|
|
|
|
response = service.put_vm_disks(vm_id, data.disks)
|
2013-07-05 13:10:43 -04:00
|
|
|
service.process_task(response.body)
|
2013-07-05 10:33:31 -04:00
|
|
|
end
|
2013-06-28 06:49:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def all_disks
|
|
|
|
attributes[:all_disks] # this is passed at instantiation time
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
num_disk = element_name.scan(/\d+/).first.to_i
|
|
|
|
data = Fog::Generators::Compute::Vcloudng::Disks.new(all_disks)
|
|
|
|
data.delete_hard_disk(num_disk)
|
|
|
|
response = service.put_vm_disks(vm_id, data.disks)
|
2013-07-05 13:10:43 -04:00
|
|
|
service.process_task(response.body)
|
2013-06-28 06:49:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|