Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1453 from rubiojr/add-host-cpu-model

[xenserver] Added HostCpu model
  • Loading branch information...
commit 200645c1b3755b17db803bdf50e4431db4ee673d 2 parents c755bed + f12faea
@rubiojr rubiojr authored
View
1  lib/fog/xenserver/compute.rb
@@ -37,6 +37,7 @@ class XenServer < Fog::Service
model :guest_metrics
model :vbd_metrics
model :host_metrics
+ model :host_cpu
request_path 'fog/xenserver/requests/compute'
request :create_server
View
25 lib/fog/xenserver/models/compute/host.rb
@@ -22,7 +22,10 @@ class Host < Fog::Model
attribute :__pbds, :aliases => :PBDs
attribute :__pifs, :aliases => :PIFs
attribute :__resident_vms, :aliases => :resident_VMs
-
+ attribute :__host_cpus, :aliases => :host_CPUs
+ attribute :edition
+ attribute :software_version
+
def pifs
__pifs.collect { |pif| service.pifs.get pif }
end
@@ -39,6 +42,16 @@ def resident_vms
resident_servers
end
+ def host_cpus
+ cpus = []
+ (__host_cpus || []).each do |ref|
+ cpu_ref = service.get_record(ref, 'host_cpu' )
+ cpu_ref[:service] = service
+ cpus << Fog::Compute::XenServer::HostCpu.new(cpu_ref)
+ end
+ cpus
+ end
+
def metrics
return nil unless __metrics
rec = service.get_record(__metrics, 'host_metrics' )
@@ -59,7 +72,7 @@ def metrics
#
def reboot(auto_disable = true)
disable if auto_disable
- connection.reboot_host(reference)
+ service.reboot_host(reference)
end
#
@@ -69,7 +82,7 @@ def reboot(auto_disable = true)
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def disable
- connection.disable_host(reference)
+ service.disable_host(reference)
end
#
@@ -78,7 +91,7 @@ def disable
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def enable
- connection.enable_host(reference)
+ service.enable_host(reference)
end
#
@@ -95,11 +108,11 @@ def enable
#
def shutdown(auto_disable = true)
disable if auto_disable
- connection.shutdown_host(reference)
+ service.shutdown_host(reference)
end
def set_attribute(name, *val)
- data = connection.set_attribute( 'host', reference, name, *val )
+ data = service.set_attribute( 'host', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
View
37 lib/fog/xenserver/models/compute/host_cpu.rb
@@ -0,0 +1,37 @@
+require 'fog/core/model'
+
+module Fog
+ module Compute
+ class XenServer
+
+ #
+ # A physical CPU
+ #
+ # @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host_cpu
+ #
+ class HostCpu < Fog::Model
+
+ identity :reference
+
+ attribute :uuid
+ attribute :family
+ attribute :flags
+ attribute :__host, :aliases => :host
+ attribute :model
+ attribute :model_name, :aliases => :modelname
+ attribute :number
+ attribute :other_config
+ attribute :speed
+ attribute :stepping
+ attribute :utilisation
+ attribute :vendor
+
+ def host
+ service.hosts.get __host
+ end
+
+ end
+
+ end
+ end
+end
View
2  lib/fog/xenserver/models/compute/pbd.rb
@@ -28,7 +28,7 @@ def host
end
def unplug
- connection.unplug_pbd reference
+ service.unplug_pbd reference
end
end
View
8 lib/fog/xenserver/models/compute/pool.rb
@@ -27,7 +27,7 @@ def default_sr
end
def default_sr=(sr)
- connection.set_attribute( 'pool', reference, 'default_SR', sr.reference )
+ service.set_attribute( 'pool', reference, 'default_SR', sr.reference )
end
alias :default_storage_repository= :default_sr=
@@ -36,11 +36,11 @@ def default_storage_repository
end
def suspend_image_sr=(sr)
- connection.set_attribute( 'pool', reference, 'suspend_image_SR', sr.reference )
+ service.set_attribute( 'pool', reference, 'suspend_image_SR', sr.reference )
end
def suspend_image_sr
- connection.storage_repositories.get __suspend_image_sr
+ service.storage_repositories.get __suspend_image_sr
end
def master
@@ -48,7 +48,7 @@ def master
end
def set_attribute(name, *val)
- data = connection.set_attribute( 'pool', reference, name, *val )
+ data = service.set_attribute( 'pool', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
View
8 lib/fog/xenserver/models/compute/storage_repository.rb
@@ -41,7 +41,7 @@ def scan
end
def destroy
- connection.destroy_sr reference
+ service.destroy_sr reference
end
def save
@@ -59,8 +59,8 @@ def save
# create_sr request provides sane defaults if some attributes are
# missing
- attr = connection.get_record(
- connection.create_sr( host.reference,
+ attr = service.get_record(
+ service.create_sr( host.reference,
name,
type,
description || '',
@@ -76,7 +76,7 @@ def save
end
def set_attribute(name, *val)
- data = connection.set_attribute( 'SR', reference, name, *val )
+ data = service.set_attribute( 'SR', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
View
58 tests/xenserver/models/compute/host_cpu_tests.rb
@@ -0,0 +1,58 @@
+Shindo.tests('Fog::Compute[:xenserver] | HostCpu model', ['xenserver']) do
+
+ host = Fog::Compute[:xenserver].hosts.first
+ host_cpu = host.host_cpus.first
+
+ tests('The HostCpu model should') do
+ tests('have attributes') do
+ model_attribute_hash = host_cpu.attributes
+ attributes = [
+ :reference,
+ :uuid,
+ :family,
+ :flags,
+ :__host,
+ :model_name,
+ :model,
+ :number,
+ :other_config,
+ :speed,
+ :stepping,
+ :utilisation,
+ :vendor
+ ]
+ tests("The HostCpu model should respond to") do
+ attributes.each do |attribute|
+ test("#{attribute}") { host_cpu.respond_to? attribute }
+ end
+ end
+ tests("The attributes hash should have key") do
+ attributes.each do |attribute|
+ test("#{attribute}") { model_attribute_hash.has_key? attribute }
+ end
+ end
+ end
+
+ test('be a kind of Fog::Compute::XenServer::HostCpu') do
+ host_cpu.kind_of? Fog::Compute::XenServer::HostCpu
+ end
+
+ test("return a valid host") do
+ host_cpu.host.kind_of? Fog::Compute::XenServer::Host
+ end
+
+ test("have a valid vendor string") do
+ host_cpu.vendor.kind_of? String
+ end
+
+ test("have a valid other_config") do
+ host_cpu.other_config.kind_of? Hash
+ end
+
+ test("have a valid utilisation attribute") do
+ host_cpu.utilisation.kind_of? Float
+ end
+
+ end
+
+end
View
2  tests/xenserver/models/compute/host_metrics_tests.rb
@@ -1,4 +1,4 @@
-Shindo.tests('Fog::Compute[:xenserver] | PBD model', ['xenserver']) do
+Shindo.tests('Fog::Compute[:xenserver] | HostMetrics model', ['xenserver']) do
host = Fog::Compute[:xenserver].hosts.first
View
14 tests/xenserver/models/compute/host_tests.rb
@@ -27,7 +27,10 @@
:other_config,
:__pbds,
:__pifs,
- :__resident_vms
+ :__resident_vms,
+ :__host_cpus,
+ :edition,
+ :software_version
]
tests("The host model should respond to") do
attributes.each do |attribute|
@@ -81,6 +84,15 @@
end
end
+ tests('return a list of HostCpu') do
+ test('as an Array') do
+ host.host_cpus.kind_of? Array
+ end
+ test('with one element at least') do
+ host.host_cpus.first.kind_of? Fog::Compute::XenServer::HostCpu
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.