mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
disk model implemented, yeah!!
This commit is contained in:
parent
905fe640ca
commit
8635dd42d9
6 changed files with 134 additions and 14 deletions
|
@ -55,6 +55,8 @@ module Fog
|
|||
collection :vm_customizations
|
||||
model :network
|
||||
collection :networks
|
||||
model :disk
|
||||
collection :disks
|
||||
|
||||
request_path 'fog/vcloudng/requests/compute'
|
||||
request :get_organizations
|
||||
|
|
|
@ -160,7 +160,7 @@ module Fog
|
|||
element_names = hard_disks.map{|item| item['element_name'] }
|
||||
only_numbers = element_names.map{|b| b.scan(/\d+/).first.to_i} # extract numbers
|
||||
last_number = only_numbers.sort.last # get the last number
|
||||
hard_disks.detect{|hard_disk| hard_disk =~ /#{last_number}$/ }
|
||||
hard_disks.detect{|hard_disk| hard_disk["element_name"] =~ /#{last_number}$/ }
|
||||
end
|
||||
|
||||
def increase_hard_disk_name(hard_disk_name)
|
||||
|
|
71
lib/fog/vcloudng/models/compute/disk.rb
Normal file
71
lib/fog/vcloudng/models/compute/disk.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
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
|
||||
|
||||
def save
|
||||
if capacity_changed?
|
||||
puts "Debug: change the cpu from #{attributes[:old_capacity]} to #{attributes[:capacity]}"
|
||||
set_capacity(capacity)
|
||||
attributes[:capacity_task].wait_for { :ready? }
|
||||
end
|
||||
end
|
||||
|
||||
def capacity=(new_capacity)
|
||||
attributes[:old_capacity] ||= attributes[:capacity]
|
||||
attributes[:capacity] = new_capacity.to_i
|
||||
end
|
||||
|
||||
def capacity_changed?
|
||||
return false unless attributes[:old_capacity]
|
||||
attributes[:capacity] != attributes[:old_capacity]
|
||||
end
|
||||
|
||||
def set_capacity(new_capacity)
|
||||
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)
|
||||
task = response.body
|
||||
task[:id] = task[:href].split('/').last
|
||||
attributes[:capacity_task] = service.tasks.new(task)
|
||||
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)
|
||||
task = response.body
|
||||
task[:id] = task[:href].split('/').last
|
||||
attributes[:destroy_disk_task] = service.tasks.new(task)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
53
lib/fog/vcloudng/models/compute/disks.rb
Normal file
53
lib/fog/vcloudng/models/compute/disks.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
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)
|
||||
task = response.body
|
||||
task[:id] = task[:href].split('/').last
|
||||
attributes[:crate_disk_task] = service.tasks.new(task)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def disks
|
||||
@disks = service.get_vm_disks(vm_id).body
|
||||
@disks['disks']
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ module Fog
|
|||
attribute :ip_address
|
||||
attribute :cpu, :type => :integer
|
||||
attribute :memory
|
||||
attribute :disks
|
||||
attribute :hard_disks, :aliases => 'disks'
|
||||
|
||||
def customization
|
||||
data = service.get_vm_customization(id).body
|
||||
|
@ -26,6 +26,11 @@ module Fog
|
|||
service.vm_customizations.new(data)
|
||||
end
|
||||
|
||||
def disks
|
||||
requires :id
|
||||
service.disks(:vm_id => id)
|
||||
end
|
||||
|
||||
#def reload
|
||||
# service.vms(:vapp_id => vapp_id).get(id)
|
||||
#end
|
||||
|
|
|
@ -30,18 +30,7 @@ module Fog
|
|||
new(vm)
|
||||
end
|
||||
|
||||
#def new(attributes = {})
|
||||
# puts attributes
|
||||
# puts attributes.class
|
||||
# if vapp
|
||||
# puts "there is a vapp #{vapp.inspect}"
|
||||
# super({ :vapp => vapp }.merge!(attributes))
|
||||
# else
|
||||
# super(attributes)
|
||||
# end
|
||||
#end
|
||||
|
||||
# private
|
||||
private
|
||||
|
||||
def vm_links
|
||||
data = service.get_vms(vapp_id).body
|
||||
|
|
Loading…
Add table
Reference in a new issue