[hp|compute_v2] Add request methods for flavors, along with tests.

This commit is contained in:
Rupak Ganguly 2013-04-26 17:49:49 -04:00
parent 6480a770c3
commit 4b2cddb12c
5 changed files with 211 additions and 3 deletions

View File

@ -43,15 +43,15 @@ module Fog
#request :disassociate_address
#request :get_address
#request :get_console_output
#request :get_flavor_details
request :get_flavor_details
#request :get_image_details
#request :get_meta
#request :get_windows_password
request :get_server_details
#request :get_vnc_console
#request :list_addresses
#request :list_flavors
#request :list_flavors_detail
request :list_flavors
request :list_flavors_detail
#request :list_images
#request :list_images_detail
#request :list_key_pairs

View File

@ -0,0 +1,57 @@
module Fog
module Compute
class HPV2
class Real
# Get details for flavor by id
#
# ==== Parameters
# * 'flavor_id'<~String> - UUId of the flavor to get details for
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'id'<~String> - UUId of the flavor
# * 'name'<~String> - Name of the flavor
# * 'ram'<~Integer> - Amount of ram for the flavor
# * 'vcpus'<~Integer> - Virtual CPUs for the flavor
# * 'disk'<~Integer> - Amount of diskspace for the flavor
# * 'OS-FLV-EXT-DATA:ephemeral'<~Integer> - Amount of ephemeral diskspace for the flavor
# * 'links'<~Array> - array of flavor links
def get_flavor_details(flavor_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "flavors/#{flavor_id}"
)
end
end
class Mock
def get_flavor_details(flavor_id)
response = Excon::Response.new
flavor = {
'1' => { 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => '1', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 1, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
'2' => { 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => '2', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
'3' => { 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => '3', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
'4' => { 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => '4', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
'5' => { 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => '5', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
'6' => { 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => '6', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 8, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
}[flavor_id]
if flavor
response.status = 200
response.body = {
'flavor' => flavor
}
response
else
raise Fog::Compute::HPV2::NotFound
end
end
end
end
end
end

View File

@ -0,0 +1,53 @@
module Fog
module Compute
class HPV2
class Real
# List all flavors (IDs and names only)
#
# ==== Parameters
# * options<~Hash>: filter options
# * 'minDisk'<~Integer> - Filters the list of flavors to those with the specified minimum number of gigabytes of disk storage.
# * 'minRam'<~Integer> - Filters the list of flavors to those with the specified minimum amount of RAM in megabytes.
# * 'marker'<~String> - The ID of the last item in the previous list
# * 'limit'<~Integer> - Sets the page size
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'id'<~String> - UUId of the flavor
# * 'name'<~String> - Name of the flavor
# * 'links'<~Array> - array of flavor links
def list_flavors(options = {})
request(
:expects => [200, 203],
:method => 'GET',
:path => 'flavors',
:query => options
)
end
end
class Mock
def list_flavors
response = Excon::Response.new
response.status = 200
response.body = {
'flavors' => [
{ 'name' => 'standard.xsmall', 'id' => '1', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
{ 'name' => 'standard.small', 'id' => '2', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
{ 'name' => 'standard.medium', 'id' => '3', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
{ 'name' => 'standard.large', 'id' => '4', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
{ 'name' => 'standard.xlarge', 'id' => '5', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
{ 'name' => 'standard.2xlarge', 'id' => '6', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
]
}
response
end
end
end
end
end

View File

@ -0,0 +1,53 @@
module Fog
module Compute
class HPV2
class Real
# List all flavors
#
# ==== Parameters
# * options<~Hash>: filter options
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'id'<~String> - UUId of the flavor
# * 'name'<~String> - Name of the flavor
# * 'ram'<~Integer> - Amount of ram for the flavor
# * 'vcpus'<~Integer> - Virtual CPUs for the flavor
# * 'disk'<~Integer> - Amount of diskspace for the flavor
# * 'OS-FLV-EXT-DATA:ephemeral'<~Integer> - Amount of ephemeral diskspace for the flavor
# * 'links'<~Array> - array of flavor links
def list_flavors_detail(options = {})
request(
:expects => [200, 203],
:method => 'GET',
:path => 'flavors/detail',
:query => options
)
end
end
class Mock
def list_flavors_detail(options = {})
response = Excon::Response.new
response.status = 200
response.body = {
'flavors' => [
{ 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => '1', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 1, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
{ 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => '2', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
{ 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => '3', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
{ 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => '4', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
{ 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => '5', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
{ 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => '6', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 8, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
]
}
response
end
end
end
end
end

View File

@ -0,0 +1,45 @@
Shindo.tests("Fog::Compute::HPV2 | flavor requests", ['hp', 'v2', 'compute']) do
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
@flavor_format = {
'id' => String,
'name' => String,
'vcpus' => Integer,
'disk' => Integer,
'ram' => Integer,
'OS-FLV-EXT-DATA:ephemeral' => Integer,
'links' => [Hash]
}
@list_flavors_format = {
'id' => String,
'name' => String,
'links' => [Hash]
}
tests('success') do
tests('#list_flavors').formats({'flavors' => [@list_flavors_format]}) do
service.list_flavors.body
end
tests('#get_flavor_details("1")').formats(@flavor_format) do
service.get_flavor_details("1").body['flavor']
end
tests('#list_flavors_detail').formats({'flavors' => [@flavor_format]}) do
service.list_flavors_detail.body
end
end
tests('failure') do
tests('#get_flavor_details("9999")').raises(Fog::Compute::HPV2::NotFound) do
service.get_flavor_details('9999')
end
end
end