mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1645 from jmontleon/master
Add support for working with ovirt quotas
This commit is contained in:
commit
800ef9fbc0
9 changed files with 111 additions and 1 deletions
|
@ -16,6 +16,8 @@ module Fog
|
|||
collection :interfaces
|
||||
model :volume
|
||||
collection :volumes
|
||||
model :quota
|
||||
collection :quotas
|
||||
|
||||
request_path 'fog/ovirt/requests/compute'
|
||||
|
||||
|
@ -43,6 +45,8 @@ module Fog
|
|||
request :add_volume
|
||||
request :destroy_volume
|
||||
request :get_api_version
|
||||
request :list_quotas
|
||||
request :get_quota
|
||||
|
||||
module Shared
|
||||
# converts an OVIRT object into an hash for fog to consume.
|
||||
|
|
21
lib/fog/ovirt/models/compute/quota.rb
Normal file
21
lib/fog/ovirt/models/compute/quota.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
|
||||
class Quota < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :description
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
24
lib/fog/ovirt/models/compute/quotas.rb
Normal file
24
lib/fog/ovirt/models/compute/quotas.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ovirt/models/compute/quota'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
|
||||
class Quotas < Fog::Collection
|
||||
|
||||
model Fog::Compute::Ovirt::Quota
|
||||
|
||||
def all(filters = {})
|
||||
load service.list_quotas(filters)
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new service.get_quota(id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -27,7 +27,8 @@ module Fog
|
|||
attribute :interfaces
|
||||
attribute :volumes
|
||||
attribute :raw
|
||||
|
||||
attribute :quota
|
||||
|
||||
def ready?
|
||||
!(status =~ /down/i)
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ module Fog
|
|||
attribute :sparse
|
||||
attribute :size_gb
|
||||
attribute :status
|
||||
attribute :quota
|
||||
|
||||
def size_gb
|
||||
attributes[:size_gb] ||= attributes[:size].to_i / DISK_SIZE_TO_GB if attributes[:size]
|
||||
|
|
19
lib/fog/ovirt/requests/compute/get_quota.rb
Normal file
19
lib/fog/ovirt/requests/compute/get_quota.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
def get_quota(id)
|
||||
ovirt_attrs client.quota(id)
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def get_quota(id)
|
||||
xml = read_xml('quota.xml')
|
||||
ovirt_attrs OVIRT::Quota::new(self, Nokogiri::XML(xml).root)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
21
lib/fog/ovirt/requests/compute/list_quotas.rb
Normal file
21
lib/fog/ovirt/requests/compute/list_quotas.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
def list_quotas(filters = {})
|
||||
client.quotas(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_quotas(filters = {})
|
||||
xml = read_xml 'quotas.xml'
|
||||
Nokogiri::XML(xml).xpath('/quotas/quota').collect do |q|
|
||||
ovirt_attrs OVIRT::Quotas::new(self, q)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
7
lib/fog/ovirt/requests/compute/mock_files/quotas.xml
Normal file
7
lib/fog/ovirt/requests/compute/mock_files/quotas.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<quotas>
|
||||
<quota href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc/quotas/aae6e3f3-0798-4ef7-b4e4-c036f04a98d7" id="aae6e3f3-0798-4ef7-b4e4-c036f04a98d7">
|
||||
<name>DefaultQuota-Datacenter1</name>
|
||||
<description>Automatic generated Quota for Data Center Datacenter1</description>
|
||||
<data_center href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc" id="c0645886-4b4b-11e1-a0ae-5254009970cc"/>
|
||||
</quota>
|
||||
</quotas>
|
12
tests/ovirt/requests/compute/list_quotas_tests.rb
Normal file
12
tests/ovirt/requests/compute/list_quotas_tests.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
Shindo.tests('Fog::Compute[:ovirt] | quotas request', ['ovirt']) do
|
||||
|
||||
compute = Fog::Compute[:ovirt]
|
||||
|
||||
tests("When listing all quotas") do
|
||||
|
||||
response = compute.quotas
|
||||
tests("The response data format ...") do
|
||||
test("it should be a kind of Array") { response.kind_of? Array }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue