[openstack|compute] Added requests for quota

This commit is contained in:
Alvin Garcia 2012-04-10 14:14:22 +08:00 committed by Nelvin Driz
parent b74f226483
commit 974954d366
5 changed files with 178 additions and 0 deletions

View File

@ -141,6 +141,11 @@ module Fog
request :list_usages
request :get_usage
# Quota
request :get_quota
request :get_quota_defaults
request :update_quota
class Mock
def self.data

View File

@ -0,0 +1,42 @@
module Fog
module Compute
class OpenStack
class Real
def get_quota(tenant_id)
request(
:expects => 200,
:method => 'GET',
:path => "/os-quota-sets/#{tenant_id}"
)
end
end
class Mock
def get_quota(tenant_id)
response = Excon::Response.new
response.status = 200
response.body = {
'quota_set' => {
'metadata_items' => 128,
'injected_file_content_bytes' => 10240,
'injected_files' => 5,
'gigabytes' => 1000,
'ram' => 51200,
'floating_ips' => 10,
'instances' => 10,
'volumes' => 10,
'cores' => 20,
'id' => tenant_id
}
}
response
end
end
end
end
end

View File

@ -0,0 +1,42 @@
module Fog
module Compute
class OpenStack
class Real
def get_quota_defaults(tenant_id)
request(
:expects => 200,
:method => 'GET',
:path => "/os-quota-sets/#{tenant_id}/defaults"
)
end
end
class Mock
def get_quota_defaults(tenant_id)
response = Excon::Response.new
response.status = 200
response.body = {
'quota_set' => {
'metadata_items' => 128,
'injected_file_content_bytes' => 10240,
'injected_files' => 5,
'gigabytes' => 1000,
'ram' => 51200,
'floating_ips' => 10,
'instances' => 10,
'volumes' => 10,
'cores' => 20,
'id' => tenant_id
}
}
response
end
end
end
end
end

View File

@ -0,0 +1,45 @@
module Fog
module Compute
class OpenStack
class Real
def update_quota(tenant_id, options = {})
options['tenant_id'] = tenant_id
request(
:body => MultiJson.encode({ 'quota_set' => options }),
:expects => 200,
:method => 'PUT',
:path => "/os-quota-sets/#{tenant_id}"
)
end
end
class Mock
def update_quota(tenant_id, options = {})
defaults = {
'metadata_items' => 128,
'injected_file_content_bytes' => 10240,
'injected_files' => 5,
'gigabytes' => 1000,
'ram' => 51200,
'floating_ips' => 10,
'instances' => 10,
'volumes' => 10,
'cores' => 20,
'id' => tenant_id
}
defaults.merge options
response = Excon::Response.new
response.status = 200
response.body = { 'quota_set' => options }
response
end
end
end
end
end

View File

@ -0,0 +1,44 @@
Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do
@tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id']
@quota_set_format = {
'metadata_items' => Fixnum,
'injected_file_content_bytes' => Fixnum,
'injected_files' => Fixnum,
'gigabytes' => Fixnum,
'ram' => Fixnum,
'floating_ips' => Fixnum,
'instances' => Fixnum,
'volumes' => Fixnum,
'cores' => Fixnum,
'id' => String
}
tests('success') do
tests('#get_quota_defaults').formats({ 'quota_set' => @quota_set_format }) do
Fog::Compute[:openstack].get_quota_defaults(@tenant_id).body
end
tests('#get_quota').formats(@quota_set_format) do
@quota = Fog::Compute[:openstack].get_quota(@tenant_id).body['quota_set']
@quota
end
tests('#update_quota') do
new_values = @quota.merge({
'volumes' => @quota['volumes']/2,
'cores' => @quota['cores']/2
})
succeeds do
Fog::Compute[:openstack].update_quota(@tenant_id, new_values.clone)
end
returns(new_values, 'returns new values') do
Fog::Compute[:openstack].get_quota(@tenant_id).body['quota_set']
end
end
end
end