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/vcloud_director/models/compute/disk.rb

52 lines
1.5 KiB
Ruby
Raw Normal View History

2013-06-28 06:49:11 -04:00
require 'fog/core/model'
module Fog
module Compute
2013-08-27 05:19:54 -04:00
class VcloudDirector
2013-06-28 06:49:11 -04:00
2013-08-27 05:19:54 -04:00
class Disk < Model # there is no lazy_load in disks
2013-09-16 13:13:09 -04:00
identity :id
2013-09-16 13:13:09 -04:00
2013-06-28 06:49:11 -04:00
attribute :address
attribute :description
attribute :name
2013-06-28 06:49:11 -04:00
attribute :resource_sub_type
attribute :resource_type
attribute :address_on_parent
attribute :parent
attribute :capacity
attribute :bus_sub_type
attribute :bus_type
2013-09-16 13:13:09 -04:00
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
2013-08-27 05:19:54 -04:00
data = Fog::Generators::Compute::VcloudDirector::Disks.new(all_disks)
num_disk = name.scan(/\d+/).first.to_i
2013-07-05 10:33:31 -04:00
data.modify_hard_disk_size(num_disk, new_capacity)
response = service.put_vm_disks(attributes[:vm].id, data.disks)
service.process_task(response.body)
2013-07-05 10:33:31 -04:00
end
2013-06-28 06:49:11 -04:00
end
2013-09-16 13:13:09 -04:00
2013-06-28 06:49:11 -04:00
def all_disks
attributes[:all_disks] # this is passed at instantiation time
end
2013-09-16 13:13:09 -04:00
2013-06-28 06:49:11 -04:00
def destroy
num_disk = name.scan(/\d+/).first.to_i
2013-08-27 05:19:54 -04:00
data = Fog::Generators::Compute::VcloudDirector::Disks.new(all_disks)
2013-06-28 06:49:11 -04:00
data.delete_hard_disk(num_disk)
response = service.put_vm_disks(attributes[:vm].id, data.disks)
service.process_task(response.body)
2013-06-28 06:49:11 -04:00
end
end
end
end
2013-09-16 13:13:09 -04:00
end