diff --git a/lib/fog/vcloudng/compute.rb b/lib/fog/vcloudng/compute.rb index f884529f4..f344caa4f 100644 --- a/lib/fog/vcloudng/compute.rb +++ b/lib/fog/vcloudng/compute.rb @@ -72,6 +72,8 @@ module Fog request :get_network request :get_vm_cpu request :put_vm_cpu + request :get_vm_memory + request :put_vm_memory request :get_request diff --git a/lib/fog/vcloudng/models/compute/vapp.rb b/lib/fog/vcloudng/models/compute/vapp.rb index 73c175ede..d98a51633 100644 --- a/lib/fog/vcloudng/models/compute/vapp.rb +++ b/lib/fog/vcloudng/models/compute/vapp.rb @@ -25,7 +25,7 @@ module Fog def vms requires :id - service.vms(:vapp => self) + service.vms(:vapp_id => id) end end diff --git a/lib/fog/vcloudng/models/compute/vm.rb b/lib/fog/vcloudng/models/compute/vm.rb index c14c1b60e..27c10c2bd 100644 --- a/lib/fog/vcloudng/models/compute/vm.rb +++ b/lib/fog/vcloudng/models/compute/vm.rb @@ -8,7 +8,8 @@ module Fog class Vm < Fog::Model identity :id - + + attribute :vapp_id attribute :name attribute :type attribute :href @@ -25,12 +26,39 @@ module Fog service.vm_customizations.new(data) end + #def reload + # service.vms(:vapp_id => vapp_id).get(id) + #end + def save if cpu_changed? puts "Debug: change the cpu from #{attributes[:old_cpu]} to #{attributes[:cpu]}" set_cpu(cpu) attributes[:cpu_task].wait_for { :ready? } end + if memory_changed? + puts "Debug: change the memory from #{attributes[:old_memory]} to #{attributes[:memory]}" + set_memory(memory) + attributes[:memory_task].wait_for { :ready? } + end + + end + + def memory=(new_memory) + attributes[:old_memory] ||= attributes[:memory] + attributes[:memory] = new_memory.to_i + end + + def memory_changed? + return false unless attributes[:old_memory] + attributes[:memory] != attributes[:old_memory] + end + + def set_memory(new_memory) + response = service.put_vm_memory(id, new_memory) + task = response.body + task[:id] = task[:href].split('/').last + attributes[:memory_task] = service.tasks.new(task) end def cpu=(new_cpu) diff --git a/lib/fog/vcloudng/models/compute/vms.rb b/lib/fog/vcloudng/models/compute/vms.rb index 969d4cb24..0af3aad48 100644 --- a/lib/fog/vcloudng/models/compute/vms.rb +++ b/lib/fog/vcloudng/models/compute/vms.rb @@ -8,7 +8,7 @@ module Fog class Vms < Fog::Collection model Fog::Compute::Vcloudng::Vm - attribute :vapp + attribute :vapp_id def index vm_links.map{ |vm| new(vm)} @@ -19,14 +19,14 @@ module Fog end def get(vm_id) - puts vapp.id - vm = vm_links.detect{ |vm| vm[:id] == vm_id} - puts vm - new({ :vapp => vapp }.merge(vm)) + vm = vm_links.detect{ |vm| vm['id'] == vm_id} + return nil unless vm + new(vm) end def get_by_name(vm_name) - vm = vm_links.detect{ |vm| vm[:name] == vm_name} + vm = vm_links.detect{ |vm| vm['name'] == vm_name} + return nil unless vm new(vm) end @@ -41,10 +41,10 @@ module Fog # end #end - private +# private def vm_links - data = service.get_vms(vapp.id).body + data = service.get_vms(vapp_id).body data['vms'] end diff --git a/lib/fog/vcloudng/parsers/compute/vm.rb b/lib/fog/vcloudng/parsers/compute/vm.rb index 42b3159f4..857922625 100644 --- a/lib/fog/vcloudng/parsers/compute/vm.rb +++ b/lib/fog/vcloudng/parsers/compute/vm.rb @@ -28,6 +28,7 @@ module Fog vapp = extract_attributes(attributes) @vm.merge!(vapp.reject {|key,value| !['href', 'name', 'status', 'type'].include?(key)}) @vm['id'] = @vm['href'].split('/').last + @vm['vapp_id'] = @response['id'] @vm['status'] = human_status(@vm['status']) when 'Children' @in_children = true diff --git a/lib/fog/vcloudng/requests/compute/get_vm_memory.rb b/lib/fog/vcloudng/requests/compute/get_vm_memory.rb new file mode 100644 index 000000000..53522e30b --- /dev/null +++ b/lib/fog/vcloudng/requests/compute/get_vm_memory.rb @@ -0,0 +1,19 @@ +module Fog + module Compute + class Vcloudng + class Real + + def put_vm_memory(vm_id) + request( + :expects => 200, + :headers => { 'Accept' => 'application/*+xml;version=1.5' }, + :method => 'GET', + :parser => Fog::ToHashDocument.new, + :path => "vApp/#{vm_id}/virtualHardwareSection/memory" + ) + end + + end + end + end +end diff --git a/lib/fog/vcloudng/requests/compute/put_vm_memory.rb b/lib/fog/vcloudng/requests/compute/put_vm_memory.rb new file mode 100644 index 000000000..49fff9b2a --- /dev/null +++ b/lib/fog/vcloudng/requests/compute/put_vm_memory.rb @@ -0,0 +1,33 @@ +module Fog + module Compute + class Vcloudng + class Real + + def put_vm_memory(vm_id, memory) + data = < + byte * 2^20 + Memory Size + #{memory} MB of memory + 5 + 0 + 4 + #{memory} + 0 + + +EOF + request( + :body => data, + :expects => 202, + :headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml', + 'Accept' => 'application/*+xml;version=1.5' }, + :method => 'PUT', + :parser => Fog::ToHashDocument.new, + :path => "vApp/#{vm_id}/virtualHardwareSection/memory" + ) + end + end + end + end +end