From 2990a6eba0fbb5e485fafedf488dc2c69264f7e2 Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Thu, 6 Dec 2012 23:39:50 +0100 Subject: [PATCH] Added missing HostMetrics model Added missing HostMetrics model that wraps Host.metrics OpaqueRef. conn = Fog::Compute.new({ :provider => 'XenServer', :xenserver_url => 'xenserver-test', :xenserver_username => 'root', :xenserver_password => 'secret', }) pp conn.hosts.first.metrics # => yields # --- lib/fog/xenserver/compute.rb | 1 + lib/fog/xenserver/models/compute/host.rb | 8 ++++- .../xenserver/models/compute/host_metrics.rb | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lib/fog/xenserver/models/compute/host_metrics.rb diff --git a/lib/fog/xenserver/compute.rb b/lib/fog/xenserver/compute.rb index d324c0ce4..6bd53b33e 100644 --- a/lib/fog/xenserver/compute.rb +++ b/lib/fog/xenserver/compute.rb @@ -36,6 +36,7 @@ module Fog model :pbd model :guest_metrics model :vbd_metrics + model :host_metrics request_path 'fog/xenserver/requests/compute' request :create_server diff --git a/lib/fog/xenserver/models/compute/host.rb b/lib/fog/xenserver/models/compute/host.rb index 95782050b..11365ff27 100644 --- a/lib/fog/xenserver/models/compute/host.rb +++ b/lib/fog/xenserver/models/compute/host.rb @@ -16,7 +16,7 @@ module Fog attribute :allowed_operations attribute :enabled attribute :hostname - attribute :metrics + attribute :__metrics, :aliases => :metrics attribute :name_description attribute :other_config attribute :__pbds, :aliases => :PBDs @@ -39,6 +39,12 @@ module Fog resident_servers end + def metrics + return nil unless __metrics + rec = connection.get_record(__metrics, 'host_metrics' ) + Fog::Compute::XenServer::HostMetrics.new(rec) + end + end end diff --git a/lib/fog/xenserver/models/compute/host_metrics.rb b/lib/fog/xenserver/models/compute/host_metrics.rb new file mode 100644 index 000000000..d9276c952 --- /dev/null +++ b/lib/fog/xenserver/models/compute/host_metrics.rb @@ -0,0 +1,29 @@ +require 'fog/core/model' + +module Fog + module Compute + class XenServer + + class HostMetrics < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VM_host_metrics + + identity :reference + + attribute :uuid + attribute :live + attribute :memory_free + attribute :memory_total + attribute :other_config + attribute :last_updated + + def initialize(attributes = {}) + super + self.last_updated = attributes[:last_updated].to_time + end + + end + + end + end +end