mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Update the Linode avail_kernels request and Kernel model.
- Remove the kernelId parameter that is no longer supported by the API. - Add support for the new isXen and isKVM parameters. - Add is_xen, is_kvm and is_pvops to the Kernel model.
This commit is contained in:
parent
b46a2e78c5
commit
cb96248d6c
4 changed files with 35 additions and 34 deletions
|
@ -6,6 +6,9 @@ module Fog
|
|||
class Kernel < Fog::Model
|
||||
identity :id
|
||||
attribute :name
|
||||
attribute :is_xen
|
||||
attribute :is_kvm
|
||||
attribute :is_pvops
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,20 +11,27 @@ module Fog
|
|||
load kernels
|
||||
end
|
||||
|
||||
def all_kvm
|
||||
load kernels(:isKVM => 1)
|
||||
end
|
||||
|
||||
def all_xen
|
||||
load kernels(:isXen => 1)
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new kernels(id).select {|kernel| kernel[:id] == id }.first
|
||||
rescue Fog::Compute::Linode::NotFound
|
||||
nil
|
||||
new kernels.select {|kernel| kernel[:id] == id }.first
|
||||
end
|
||||
|
||||
private
|
||||
def kernels(id=nil)
|
||||
service.avail_kernels(id).body['DATA'].map { |kernel| map_kernel kernel }
|
||||
def kernels(options={})
|
||||
service.avail_kernels(options).body['DATA'].map { |kernel| map_kernel kernel }
|
||||
end
|
||||
|
||||
def map_kernel(kernel)
|
||||
kernel = kernel.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
|
||||
kernel.merge! :id => kernel[:kernelid], :name => kernel[:label]
|
||||
kernel.merge! :id => kernel[:kernelid], :name => kernel[:label],
|
||||
:is_xen => kernel[:isxen], :is_kvm => kernel[:iskvm], :is_pvops => kernel[:ispvops]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,27 +5,30 @@ module Fog
|
|||
# Get available kernels
|
||||
#
|
||||
# ==== Parameters
|
||||
# * kernelId<~Integer>: id to limit results to
|
||||
# * options<~Hash>
|
||||
# * isXen<~Boolean> Show or hide Xen compatible kernels
|
||||
# * isKVM<~Boolean> Show or hide KVM compatible kernels
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def avail_kernels(kernel_id=nil)
|
||||
options = {}
|
||||
if kernel_id
|
||||
options.merge!(:kernelId => kernel_id)
|
||||
end
|
||||
def avail_kernels(options={})
|
||||
# avail.kernels used to accept a kernelId parameter (now removed)
|
||||
raise Fog::Errors::Error.new('avail_kernels no longer accepts a kernelId parameter') unless !options || options.is_a?(Hash)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:query => { :api_action => 'avail.kernels' }.merge!(options)
|
||||
:query => { :api_action => 'avail.kernels' }.merge!(options || {})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def avail_kernels(kernel_id=nil)
|
||||
def avail_kernels(options={})
|
||||
# avail.kernels used to accept a kernelId parameter (now removed)
|
||||
raise Fog::Errors::Error.new('avail_kernels no longer accepts a kernelId parameter') unless !options || options.is_a?(Hash)
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
|
@ -33,17 +36,12 @@ module Fog
|
|||
"ERRORARRAY" => [],
|
||||
"ACTION" => "avail.kernels"
|
||||
}
|
||||
if kernel_id
|
||||
mock_kernel = create_mock_kernel(kernel_id)
|
||||
response.body = body.merge("DATA" => [mock_kernel])
|
||||
else
|
||||
mock_kernels = []
|
||||
10.times do
|
||||
kernel_id = rand(1..200)
|
||||
mock_kernels << create_mock_kernel(kernel_id)
|
||||
end
|
||||
response.body = body.merge("DATA" => mock_kernels)
|
||||
mock_kernels = []
|
||||
10.times do
|
||||
kernel_id = rand(1..200)
|
||||
mock_kernels << create_mock_kernel(kernel_id)
|
||||
end
|
||||
response.body = body.merge("DATA" => mock_kernels)
|
||||
response
|
||||
end
|
||||
|
||||
|
@ -53,6 +51,7 @@ module Fog
|
|||
{
|
||||
"ISPVOPS" => 1,
|
||||
"ISXEN" => 1,
|
||||
"ISKVM" => 1,
|
||||
"KERNELID" => kernel_id,
|
||||
"LABEL" => "Latest 3.0 (3.0.18-linode43)"
|
||||
}
|
||||
|
|
|
@ -4,24 +4,16 @@ Shindo.tests('Fog::Compute[:linode] | kernel requests', ['linode']) do
|
|||
'DATA' => [{
|
||||
'LABEL' => String,
|
||||
'ISXEN' => Integer,
|
||||
'ISKVM' => Integer,
|
||||
'ISPVOPS' => Integer,
|
||||
'KERNELID' => Integer
|
||||
}]
|
||||
})
|
||||
|
||||
tests('success') do
|
||||
@kernel_id = nil
|
||||
|
||||
tests('#avail_kernels').formats(@kernels_format) do
|
||||
pending if Fog.mocking?
|
||||
data = Fog::Compute[:linode].avail_kernels.body
|
||||
@kernel_id = data['DATA'].first['KERNELID']
|
||||
data
|
||||
end
|
||||
|
||||
tests("@avail_kernels(#{@kernel_id})").formats(@kernels_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:linode].avail_kernels(@kernel_id).body
|
||||
Fog::Compute[:linode].avail_kernels.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue