mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
set memory and vm.reload
This commit is contained in:
parent
717b85defa
commit
3cbe09e2dc
7 changed files with 93 additions and 10 deletions
|
@ -72,6 +72,8 @@ module Fog
|
||||||
request :get_network
|
request :get_network
|
||||||
request :get_vm_cpu
|
request :get_vm_cpu
|
||||||
request :put_vm_cpu
|
request :put_vm_cpu
|
||||||
|
request :get_vm_memory
|
||||||
|
request :put_vm_memory
|
||||||
request :get_request
|
request :get_request
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Fog
|
||||||
|
|
||||||
def vms
|
def vms
|
||||||
requires :id
|
requires :id
|
||||||
service.vms(:vapp => self)
|
service.vms(:vapp_id => id)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,8 @@ module Fog
|
||||||
|
|
||||||
class Vm < Fog::Model
|
class Vm < Fog::Model
|
||||||
identity :id
|
identity :id
|
||||||
|
|
||||||
|
attribute :vapp_id
|
||||||
attribute :name
|
attribute :name
|
||||||
attribute :type
|
attribute :type
|
||||||
attribute :href
|
attribute :href
|
||||||
|
@ -25,12 +26,39 @@ module Fog
|
||||||
service.vm_customizations.new(data)
|
service.vm_customizations.new(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#def reload
|
||||||
|
# service.vms(:vapp_id => vapp_id).get(id)
|
||||||
|
#end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
if cpu_changed?
|
if cpu_changed?
|
||||||
puts "Debug: change the cpu from #{attributes[:old_cpu]} to #{attributes[:cpu]}"
|
puts "Debug: change the cpu from #{attributes[:old_cpu]} to #{attributes[:cpu]}"
|
||||||
set_cpu(cpu)
|
set_cpu(cpu)
|
||||||
attributes[:cpu_task].wait_for { :ready? }
|
attributes[:cpu_task].wait_for { :ready? }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def cpu=(new_cpu)
|
def cpu=(new_cpu)
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Fog
|
||||||
class Vms < Fog::Collection
|
class Vms < Fog::Collection
|
||||||
model Fog::Compute::Vcloudng::Vm
|
model Fog::Compute::Vcloudng::Vm
|
||||||
|
|
||||||
attribute :vapp
|
attribute :vapp_id
|
||||||
|
|
||||||
def index
|
def index
|
||||||
vm_links.map{ |vm| new(vm)}
|
vm_links.map{ |vm| new(vm)}
|
||||||
|
@ -19,14 +19,14 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(vm_id)
|
def get(vm_id)
|
||||||
puts vapp.id
|
vm = vm_links.detect{ |vm| vm['id'] == vm_id}
|
||||||
vm = vm_links.detect{ |vm| vm[:id] == vm_id}
|
return nil unless vm
|
||||||
puts vm
|
new(vm)
|
||||||
new({ :vapp => vapp }.merge(vm))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_by_name(vm_name)
|
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)
|
new(vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,10 +41,10 @@ module Fog
|
||||||
# end
|
# end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
private
|
# private
|
||||||
|
|
||||||
def vm_links
|
def vm_links
|
||||||
data = service.get_vms(vapp.id).body
|
data = service.get_vms(vapp_id).body
|
||||||
data['vms']
|
data['vms']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ module Fog
|
||||||
vapp = extract_attributes(attributes)
|
vapp = extract_attributes(attributes)
|
||||||
@vm.merge!(vapp.reject {|key,value| !['href', 'name', 'status', 'type'].include?(key)})
|
@vm.merge!(vapp.reject {|key,value| !['href', 'name', 'status', 'type'].include?(key)})
|
||||||
@vm['id'] = @vm['href'].split('/').last
|
@vm['id'] = @vm['href'].split('/').last
|
||||||
|
@vm['vapp_id'] = @response['id']
|
||||||
@vm['status'] = human_status(@vm['status'])
|
@vm['status'] = human_status(@vm['status'])
|
||||||
when 'Children'
|
when 'Children'
|
||||||
@in_children = true
|
@in_children = true
|
||||||
|
|
19
lib/fog/vcloudng/requests/compute/get_vm_memory.rb
Normal file
19
lib/fog/vcloudng/requests/compute/get_vm_memory.rb
Normal file
|
@ -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
|
33
lib/fog/vcloudng/requests/compute/put_vm_memory.rb
Normal file
33
lib/fog/vcloudng/requests/compute/put_vm_memory.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Vcloudng
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def put_vm_memory(vm_id, memory)
|
||||||
|
data = <<EOF
|
||||||
|
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns12="http://www.vmware.com/vcloud/v1.5" ns12:href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory" ns12:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
|
||||||
|
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
|
||||||
|
<rasd:Description>Memory Size</rasd:Description>
|
||||||
|
<rasd:ElementName>#{memory} MB of memory</rasd:ElementName>
|
||||||
|
<rasd:InstanceID>5</rasd:InstanceID>
|
||||||
|
<rasd:Reservation>0</rasd:Reservation>
|
||||||
|
<rasd:ResourceType>4</rasd:ResourceType>
|
||||||
|
<rasd:VirtualQuantity>#{memory}</rasd:VirtualQuantity>
|
||||||
|
<rasd:Weight>0</rasd:Weight>
|
||||||
|
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory"/>
|
||||||
|
</Item>
|
||||||
|
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
|
Loading…
Reference in a new issue