diff --git a/lib/fog/xenserver/models/compute/host.rb b/lib/fog/xenserver/models/compute/host.rb index 95782050b..982715faa 100644 --- a/lib/fog/xenserver/models/compute/host.rb +++ b/lib/fog/xenserver/models/compute/host.rb @@ -23,6 +23,16 @@ module Fog attribute :__pifs, :aliases => :PIFs attribute :__resident_vms, :aliases => :resident_VMs + def templates + connection.servers.all(:include_templates => true).delete_if { |s| !s.is_a_template } + end + + def custom_templates + connection.servers.all(:include_custom_templates => true).delete_if do |s| + !s.is_a_template + end + end + def pifs __pifs.collect { |pif| connection.pifs.get pif } end diff --git a/tests/xenserver/models/compute/host_tests.rb b/tests/xenserver/models/compute/host_tests.rb index cd5cf1262..81b3a9dc5 100644 --- a/tests/xenserver/models/compute/host_tests.rb +++ b/tests/xenserver/models/compute/host_tests.rb @@ -64,4 +64,26 @@ Shindo.tests('Fog::Compute[:xenserver] | host model', ['xenserver']) do end + tests("The host template list should") do + test("include a #{test_template_name} template in custom_templates") do + found = false + host.custom_templates.each do |s| + found = (s.name == test_template_name) + end + found + end + test("include only one custom template") { host.custom_templates.size == 1 } + tests("not include built-in templates in custom_templates") do + host.custom_templates.each do |s| + test("#{s.name} is NOT a built-in template") {s.allowed_operations.include?('destroy') } + end + end + test("include more than one built-in templates") { host.templates.size >= 1 } + tests("not include real servers") do + host.templates.each do |s| + test("#{s.name} is not a real server") { s.is_a_template } + end + end + end + end