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

add support for openstack network quota endpoints

This commit is contained in:
Evan Petrie 2013-07-26 16:18:50 -07:00
parent 079f6ba456
commit a970f3853a
6 changed files with 209 additions and 0 deletions

View file

@ -109,6 +109,12 @@ module Fog
# Tenant # Tenant
request :set_tenant request :set_tenant
# Quota
request :get_quotas
request :get_quota
request :update_quota
request :delete_quota
class Mock class Mock
def self.data def self.data
@data ||= Hash.new do |hash, key| @data ||= Hash.new do |hash, key|
@ -122,6 +128,23 @@ module Fog
:lb_members => {}, :lb_members => {},
:lb_health_monitors => {}, :lb_health_monitors => {},
:lb_vips => {}, :lb_vips => {},
:quota => {
"subnet" => 10,
"router" => 10,
"port" => 50,
"network" => 10,
"floatingip" => 50
},
:quotas => [
{
"subnet" => 10,
"network" => 10,
"floatingip" => 50,
"tenant_id" => Fog::Mock.random_hex(8),
"router" => 10,
"port" => 30
}
],
} }
end end
end end

View file

@ -0,0 +1,26 @@
module Fog
module Network
class OpenStack
class Real
def delete_quota(tenant_id)
request(
:expects => 204,
:method => 'DELETE',
:path => "/quotas/#{tenant_id}"
)
end
end
class Mock
def delete_quota(tenant_id)
response = Excon::Response.new
response.status = 204
response
end
end
end
end
end

View file

@ -0,0 +1,31 @@
module Fog
module Network
class OpenStack
class Real
def get_quota(tenant_id)
request(
:expects => 200,
:method => 'GET',
:path => "/quotas/#{tenant_id}"
)
end
end
class Mock
def get_quota(tenant_id)
response = Excon::Response.new
response.status = 200
response.body = {
'quota' => (self.data[:quota_updated] or self.data[:quota])
}
response
end
end
end
end
end

View file

@ -0,0 +1,31 @@
module Fog
module Network
class OpenStack
class Real
def get_quotas
request(
:expects => 200,
:method => 'GET',
:path => "/quotas"
)
end
end
class Mock
def get_quotas
response = Excon::Response.new
response.status = 200
response.body = {
'quotas' => self.data[:quotas]
}
response
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module Network
class OpenStack
class Real
def update_quota(tenant_id, options = {})
request(
:body => Fog::JSON.encode({ 'quota' => options} ),
:expects => 200,
:method => 'PUT',
:path => "/quotas/#{tenant_id}"
)
end
end
class Mock
def update_quota(tenant_id, options = {})
self.data[:quota_updated] = self.data[:quota].merge options
response = Excon::Response.new
response.status = 200
response.body = { 'quota' => self.data[:quota_updated] }
response
end
end
end
end
end

View file

@ -0,0 +1,65 @@
Shindo.tests('Fog::Network[:openstack] | quota requests', ['openstack']) do
@tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id']
@quota_format = {
'subnet' => Fog::Nullable::Integer,
'router' => Fog::Nullable::Integer,
'port' => Fog::Nullable::Integer,
'network' => Fog::Nullable::Integer,
'floatingip' => Fog::Nullable::Integer
}
@quotas_format = [{
'subnet' => Fog::Nullable::Integer,
'router' => Fog::Nullable::Integer,
'port' => Fog::Nullable::Integer,
'network' => Fog::Nullable::Integer,
'floatingip' => Fog::Nullable::Integer,
'tenant_id' => Fog::Nullable::String
}]
tests('success') do
tests('#get_quotas').formats({ 'quotas' => @quotas_format }) do
Fog::Network[:openstack].get_quotas.body
end
tests('#get_quota').formats(@quota_format) do
@quota = Fog::Network[:openstack].get_quota(@tenant_id).body['quota']
end
tests('#update_quota') do
new_values = @quota.merge({
'volumes' => @quota['subnet']/2,
'snapshots' => @quota['router']/2
})
succeeds do
Fog::Network[:openstack].update_quota(@tenant_id, new_values.clone)
end
returns(new_values, 'returns new values') do
Fog::Network[:openstack].get_quota(@tenant_id).body['quota']
end
# set quota back to old values
succeeds do
Fog::Network[:openstack].update_quota(@tenant_id, @quota.clone)
end
# ensure old values are restored
returns(@quota, 'old values restored') do
Fog::Network[:openstack].get_quota(@tenant_id).body['quota']
end
end
tests('#delete_quota') do
succeeds do
Fog::Network[:openstack].delete_quota(@tenant_id)
end
end
end
end