From 268f126b5fd2832001d68d352dc7c2ba7a4cffd1 Mon Sep 17 00:00:00 2001 From: Jason Montleon Date: Fri, 8 Mar 2013 15:42:26 -0500 Subject: [PATCH] add ovirt quota support --- lib/fog/ovirt/compute.rb | 4 ++++ lib/fog/ovirt/models/compute/quota.rb | 21 ++++++++++++++++ lib/fog/ovirt/models/compute/quotas.rb | 24 +++++++++++++++++++ lib/fog/ovirt/models/compute/server.rb | 3 ++- lib/fog/ovirt/models/compute/volume.rb | 1 + lib/fog/ovirt/requests/compute/get_quota.rb | 19 +++++++++++++++ lib/fog/ovirt/requests/compute/list_quotas.rb | 21 ++++++++++++++++ 7 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 lib/fog/ovirt/models/compute/quota.rb create mode 100644 lib/fog/ovirt/models/compute/quotas.rb create mode 100644 lib/fog/ovirt/requests/compute/get_quota.rb create mode 100644 lib/fog/ovirt/requests/compute/list_quotas.rb diff --git a/lib/fog/ovirt/compute.rb b/lib/fog/ovirt/compute.rb index 8defc0207..5b1a50afc 100644 --- a/lib/fog/ovirt/compute.rb +++ b/lib/fog/ovirt/compute.rb @@ -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. diff --git a/lib/fog/ovirt/models/compute/quota.rb b/lib/fog/ovirt/models/compute/quota.rb new file mode 100644 index 000000000..e7bb4f359 --- /dev/null +++ b/lib/fog/ovirt/models/compute/quota.rb @@ -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 + diff --git a/lib/fog/ovirt/models/compute/quotas.rb b/lib/fog/ovirt/models/compute/quotas.rb new file mode 100644 index 000000000..27805cde6 --- /dev/null +++ b/lib/fog/ovirt/models/compute/quotas.rb @@ -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 + diff --git a/lib/fog/ovirt/models/compute/server.rb b/lib/fog/ovirt/models/compute/server.rb index 7256878ee..252b2df42 100644 --- a/lib/fog/ovirt/models/compute/server.rb +++ b/lib/fog/ovirt/models/compute/server.rb @@ -27,7 +27,8 @@ module Fog attribute :interfaces attribute :volumes attribute :raw - + attribute :quota + def ready? !(status =~ /down/i) end diff --git a/lib/fog/ovirt/models/compute/volume.rb b/lib/fog/ovirt/models/compute/volume.rb index af4712ac4..c595e704b 100644 --- a/lib/fog/ovirt/models/compute/volume.rb +++ b/lib/fog/ovirt/models/compute/volume.rb @@ -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] diff --git a/lib/fog/ovirt/requests/compute/get_quota.rb b/lib/fog/ovirt/requests/compute/get_quota.rb new file mode 100644 index 000000000..4a5abc686 --- /dev/null +++ b/lib/fog/ovirt/requests/compute/get_quota.rb @@ -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 + diff --git a/lib/fog/ovirt/requests/compute/list_quotas.rb b/lib/fog/ovirt/requests/compute/list_quotas.rb new file mode 100644 index 000000000..9b56cd29e --- /dev/null +++ b/lib/fog/ovirt/requests/compute/list_quotas.rb @@ -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 +