1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[ninefold|compute] Fix data formats for virtual machines.

This commit is contained in:
Lincoln Stoll 2011-05-11 10:15:39 -07:00
parent 0f36aa31b5
commit 41cbff4acc
2 changed files with 18 additions and 7 deletions

View file

@ -141,6 +141,21 @@ class Ninefold
}]
end
module VirtualMachines
# Sometimes a few fields are missing from VM data - this method
# will fill them in if they don't exist, to ensure the format passes
def fill_virtual_machine_data(vms)
if vms.kind_of? Hash
vms['cpuused'] ||= ''
vms['networkkbsread'] ||= 0
vms['networkkbswrite'] ||= 0
elsif vms.kind_of? Array
vms.each {|vm| fill_virtual_machine_data(vm) }
end
vms
end
module_function :fill_virtual_machine_data
PENDING_VIRTUAL_MACHINE = {"id" => Integer, "jobid" => Integer}
ASYNC_VIRTUAL_MACHINE = {"jobid" => Integer}
VIRTUAL_MACHINE = {

View file

@ -28,12 +28,7 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
pending if Fog.mocking?
vms = Ninefold[:compute].list_virtual_machines
# This is a hack to work around the changing format - these fields may or may not exist.
vms.each do |vm|
vm['cpuused'] ||= ''
vm['networkkbsread'] ||= 0
vm['networkkbswrite'] ||= 0
end
vms
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
end
tests("#reboot_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do
@ -57,8 +52,9 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
tests("#change_service_for_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
Ninefold[:compute].change_service_for_virtual_machine(:id => @newvmid,
vms = Ninefold[:compute].change_service_for_virtual_machine(:id => @newvmid,
:serviceofferingid => Ninefold::Compute::TestSupport::ALT_SERVICE_OFFERING)
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
end
tests("#start_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do