mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
set_cpu implemented
This commit is contained in:
parent
dca7193300
commit
717b85defa
8 changed files with 138 additions and 16 deletions
|
@ -70,6 +70,9 @@ module Fog
|
|||
request :get_tasks_list
|
||||
request :get_vm_customization
|
||||
request :get_network
|
||||
request :get_vm_cpu
|
||||
request :put_vm_cpu
|
||||
request :get_request
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,13 +18,18 @@ module Fog
|
|||
attribute :end_time, :aliases => :endTime, :type => :time
|
||||
attribute :error, :aliases => :Error
|
||||
attribute :result, :aliases => :Result
|
||||
attribute :progress, :aliases => :Progress
|
||||
|
||||
def refresh
|
||||
def reload
|
||||
data = service.get_task(id).body
|
||||
data[:id] = data[:href].split('/').last
|
||||
service.tasks.new(data)
|
||||
end
|
||||
|
||||
def ready?
|
||||
status == 'success'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,6 @@ module Fog
|
|||
class Vcloudng
|
||||
|
||||
class Vm < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
|
@ -16,16 +15,45 @@ module Fog
|
|||
attribute :status
|
||||
attribute :operating_system
|
||||
attribute :ip_address
|
||||
attribute :cpu
|
||||
attribute :cpu, :type => :integer
|
||||
attribute :memory
|
||||
# attribute :disks
|
||||
|
||||
|
||||
def customization
|
||||
data = service.get_vm_customization(id).body
|
||||
puts data
|
||||
service.vm_customizations.new(data)
|
||||
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
|
||||
end
|
||||
|
||||
def cpu=(new_cpu)
|
||||
attributes[:old_cpu] ||= attributes[:cpu]
|
||||
attributes[:cpu] = new_cpu.to_i
|
||||
end
|
||||
|
||||
def cpu_changed?
|
||||
return false unless attributes[:old_cpu]
|
||||
attributes[:cpu] != attributes[:old_cpu]
|
||||
end
|
||||
|
||||
def set_cpu(num_cpu)
|
||||
response = service.put_vm_cpu(id, num_cpu)
|
||||
task = response.body
|
||||
task[:id] = task[:href].split('/').last
|
||||
attributes[:cpu_task] = service.tasks.new(task)
|
||||
end
|
||||
|
||||
def cpu_task
|
||||
attributes[:cpu_task]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,28 +10,41 @@ module Fog
|
|||
|
||||
attribute :vapp
|
||||
|
||||
def index(vapp_id = vapp.id)
|
||||
vm_links(vapp_id).map{ |vm| new(vm)}
|
||||
def index
|
||||
vm_links.map{ |vm| new(vm)}
|
||||
end
|
||||
|
||||
def all(vapp_id = vapp.id)
|
||||
index(vapp_id = vapp.id)
|
||||
def all
|
||||
index
|
||||
end
|
||||
|
||||
def get(vm_id, vapp_id = vapp.id)
|
||||
vm = vm_links(vapp_id).detect{ |vm| vm[:id] == vm_id}
|
||||
def get(vm_id)
|
||||
puts vapp.id
|
||||
vm = vm_links.detect{ |vm| vm[:id] == vm_id}
|
||||
puts vm
|
||||
new({ :vapp => vapp }.merge(vm))
|
||||
end
|
||||
|
||||
def get_by_name(vm_name)
|
||||
vm = vm_links.detect{ |vm| vm[:name] == vm_name}
|
||||
new(vm)
|
||||
end
|
||||
|
||||
def get_by_name(vm_name, vapp_id = vapp.id)
|
||||
vm = vm_links(vapp_id).detect{ |vm| vm[:name] == vm_name}
|
||||
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
|
||||
|
||||
def vm_links(vapp_id)
|
||||
data = service.get_vms(vapp_id).body
|
||||
def vm_links
|
||||
data = service.get_vms(vapp.id).body
|
||||
data['vms']
|
||||
end
|
||||
|
||||
|
|
17
lib/fog/vcloudng/requests/compute/get_request.rb
Normal file
17
lib/fog/vcloudng/requests/compute/get_request.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def get_request(uri)
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'GET',
|
||||
:path => uri
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/vcloudng/requests/compute/get_vm_cpu.rb
Normal file
19
lib/fog/vcloudng/requests/compute/get_vm_cpu.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def get_vm_cpu(vm_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,6 +18,10 @@ module Fog
|
|||
end_point + ( vdc_id ? "vdc/#{vdc_id}" : "vdc" )
|
||||
end
|
||||
|
||||
def endpoint
|
||||
end_point
|
||||
end
|
||||
|
||||
# A single organization can have multiple Org vDCs.
|
||||
def default_vdc_id
|
||||
if default_organization_id
|
||||
|
|
33
lib/fog/vcloudng/requests/compute/put_vm_cpu.rb
Normal file
33
lib/fog/vcloudng/requests/compute/put_vm_cpu.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def put_vm_cpu(vm_id, num_cpus)
|
||||
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/cpu" 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>hertz * 10^6</rasd:AllocationUnits>
|
||||
<rasd:Description>Number of Virtual CPUs</rasd:Description>
|
||||
<rasd:ElementName>#{num_cpus} virtual CPU(s)</rasd:ElementName>
|
||||
<rasd:InstanceID>4</rasd:InstanceID>
|
||||
<rasd:Reservation>0</rasd:Reservation>
|
||||
<rasd:ResourceType>3</rasd:ResourceType>
|
||||
<rasd:VirtualQuantity>#{num_cpus}</rasd:VirtualQuantity>
|
||||
<rasd:Weight>0</rasd:Weight>
|
||||
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/cpu"/>
|
||||
</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/cpu"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue