mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Add get_limits
request
Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
parent
1b522a54ce
commit
a16a9fe12d
3 changed files with 162 additions and 0 deletions
|
@ -126,6 +126,7 @@ module Fog
|
|||
# Tenant
|
||||
request :list_tenants
|
||||
request :set_tenant
|
||||
request :get_limits
|
||||
|
||||
# Volume
|
||||
request :list_volumes
|
||||
|
|
97
lib/fog/openstack/requests/compute/get_limits.rb
Normal file
97
lib/fog/openstack/requests/compute/get_limits.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class OpenStack
|
||||
|
||||
# http://docs.openstack.org/api/openstack-compute/2/content/ProgramaticLimits.html
|
||||
#
|
||||
class Real
|
||||
def get_limits
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/limits.json'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Mock
|
||||
def get_limits
|
||||
rate_limits = [
|
||||
{ 'regex' => '.*',
|
||||
'limit' => [
|
||||
{ 'next-available' => '2012-11-22T16:13:44Z',
|
||||
'unit' => 'MINUTE',
|
||||
'verb' => 'POST',
|
||||
'remaining' => 9,
|
||||
'value' => 10 },
|
||||
{ 'next-available' => '2012-11-23T00:46:14Z',
|
||||
'unit' => 'MINUTE',
|
||||
'verb' => 'PUT',
|
||||
'remaining' => 10,
|
||||
'value' => 10 },
|
||||
{ 'next-available' => '2012-11-22T16:14:30Z',
|
||||
'unit' => 'MINUTE',
|
||||
'verb' => 'DELETE',
|
||||
'remaining' => 99,
|
||||
'value' => 100 } ],
|
||||
'uri' => '*' },
|
||||
{ 'regex' => '^/servers',
|
||||
'limit' => [
|
||||
{ 'next-available' => '2012-11-23T00:46:14Z',
|
||||
'unit' => 'DAY',
|
||||
'verb' => 'POST',
|
||||
'remaining' => 50,
|
||||
'value' => 50} ],
|
||||
'uri'=>'*/servers' },
|
||||
{ 'regex' => '.*changes-since.*',
|
||||
'limit' => [
|
||||
{ 'next-available' => '2012-11-23T00:46:14Z',
|
||||
'unit' => 'MINUTE',
|
||||
'verb' => 'GET',
|
||||
'remaining' => 3,
|
||||
'value' => 3 } ],
|
||||
'uri' => '*changes-since*' }
|
||||
]
|
||||
|
||||
absolute_limits = {
|
||||
# Max
|
||||
'maxServerMeta' => 128,
|
||||
'maxTotalInstances' => 10,
|
||||
'maxPersonality' => 5,
|
||||
'maxImageMeta' => 128,
|
||||
'maxPersonalitySize' => 10240,
|
||||
'maxSecurityGroupRules' => 20,
|
||||
'maxTotalKeypairs' => 100,
|
||||
'maxTotalVolumes' => 10,
|
||||
'maxSecurityGroups' => 10,
|
||||
'maxTotalCores' => 20,
|
||||
'maxTotalFloatingIps' => 10,
|
||||
'maxTotalVolumeGigabytes' => 1000,
|
||||
'maxTotalRAMSize' => 51200,
|
||||
|
||||
# Used
|
||||
'totalVolumesUsed' => 0,
|
||||
'totalCoresUsed' => -1,
|
||||
'totalRAMUsed' => -2048,
|
||||
'totalInstancesUsed' => -1,
|
||||
'totalVolumeGigabytesUsed' => 0,
|
||||
'totalSecurityGroupsUsed' => 0,
|
||||
'totalKeyPairsUsed' => 0
|
||||
}
|
||||
|
||||
|
||||
Excon::Response.new(
|
||||
:status => 200,
|
||||
:body => {
|
||||
'limits' => {
|
||||
'rate' => rate_limits,
|
||||
'absolute' => absolute_limits }
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
64
tests/openstack/requests/compute/limit_tests.rb
Normal file
64
tests/openstack/requests/compute/limit_tests.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
Shindo.tests('Fog::Compute[:openstack] | limits requests', ['openstack']) do
|
||||
@rate_limit_format = {
|
||||
'regex' => String,
|
||||
'uri' => String,
|
||||
'limit' => Array
|
||||
}
|
||||
|
||||
@rate_limit_usage_format = {
|
||||
'next-available' => String,
|
||||
'unit' => String,
|
||||
'verb' => String,
|
||||
'remaining' => Fixnum,
|
||||
'value' => Fixnum
|
||||
}
|
||||
|
||||
@absolute_limits_format = {
|
||||
'maxServerMeta' => Fixnum,
|
||||
'maxTotalInstances' => Fixnum,
|
||||
'maxPersonality' => Fixnum,
|
||||
'maxImageMeta' => Fixnum,
|
||||
'maxPersonalitySize' => Fixnum,
|
||||
'maxSecurityGroupRules' => Fixnum,
|
||||
'maxTotalKeypairs' => Fixnum,
|
||||
'maxTotalVolumes' => Fixnum,
|
||||
'maxSecurityGroups' => Fixnum,
|
||||
'maxTotalCores' => Fixnum,
|
||||
'maxTotalFloatingIps' => Fixnum,
|
||||
'maxTotalVolumeGigabytes' => Fixnum,
|
||||
'maxTotalRAMSize' => Fixnum,
|
||||
'totalVolumesUsed' => Fixnum,
|
||||
'totalCoresUsed' => Fixnum,
|
||||
'totalRAMUsed' => Fixnum,
|
||||
'totalInstancesUsed' => Fixnum,
|
||||
'totalVolumeGigabytesUsed' => Fixnum,
|
||||
'totalSecurityGroupsUsed' => Fixnum,
|
||||
'totalKeyPairsUsed' => Fixnum
|
||||
}
|
||||
|
||||
@limits_format = {
|
||||
'rate' => Array,
|
||||
'absolute' => Hash
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#get_limits') do
|
||||
tests('format').formats(@limits_format) do
|
||||
Fog::Compute[:openstack].get_limits.body['limits']
|
||||
end
|
||||
|
||||
tests('rate limit format').formats(@rate_limit_format) do
|
||||
Fog::Compute[:openstack].get_limits.body['limits']['rate'].first
|
||||
end
|
||||
|
||||
tests('rate limit usage format').formats(@rate_limit_usage_format) do
|
||||
Fog::Compute[:openstack].get_limits.body['limits']['rate'].first['limit'].first
|
||||
end
|
||||
|
||||
tests('absolute limits format').formats(@absolute_limits_format) do
|
||||
Fog::Compute[:openstack].get_limits.body['limits']['absolute']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in a new issue