[xenserver] Console model created
This commit is contained in:
parent
2b3b024c72
commit
58aba87c81
|
@ -40,6 +40,8 @@ module Fog
|
|||
model :host_cpu
|
||||
model :vlan
|
||||
collection :vlans
|
||||
model :console
|
||||
collection :consoles
|
||||
|
||||
request_path 'fog/xenserver/requests/compute'
|
||||
request :create_server
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
class Console < Fog::Model
|
||||
# API Reference here:
|
||||
# http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=console
|
||||
|
||||
identity :reference
|
||||
attribute :location
|
||||
attribute :protocol
|
||||
attribute :uuid
|
||||
attribute :__vm, aliases: :VM
|
||||
|
||||
def vm
|
||||
begin
|
||||
vm = service.servers.get __vm
|
||||
rescue Fog::XenServer::RequestFailed => e
|
||||
vm = nil
|
||||
end
|
||||
vm
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
attribute :name, :aliases => :name_label
|
||||
attribute :__affinity, :aliases => :affinity
|
||||
attribute :allowed_operations
|
||||
attribute :consoles
|
||||
attribute :__consoles
|
||||
attribute :domarch
|
||||
attribute :domid
|
||||
attribute :tags
|
||||
|
@ -64,6 +64,10 @@ module Fog
|
|||
service.hosts.get __affinity
|
||||
end
|
||||
|
||||
def consoles
|
||||
__consoles.collect {|console| service.consoles.get console }
|
||||
end
|
||||
|
||||
def destroy
|
||||
# Make sure it's halted
|
||||
stop('hard')
|
||||
|
|
|
@ -9,7 +9,7 @@ Shindo.tests('Fog::Compute[:xenserver]', ['xenserver']) do
|
|||
end
|
||||
|
||||
tests("Compute collections") do
|
||||
%w{ pifs vifs hosts storage_repositories servers networks vbds vdis pools }.each do |collection|
|
||||
%w{ pifs vifs hosts storage_repositories servers networks vbds vdis pools consoles}.each do |collection|
|
||||
test("it should respond to #{collection}") { compute.respond_to? collection }
|
||||
test("it should respond to #{collection}.all") { eval("compute.#{collection}").respond_to? 'all' }
|
||||
test("it should respond to #{collection}.get") { eval("compute.#{collection}").respond_to? 'get' }
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
Shindo.tests('Fog::Compute[:xenserver] | console model', ['xenserver']) do
|
||||
consoles = Fog::Compute[:xenserver].consoles
|
||||
console = consoles.first
|
||||
|
||||
tests('The console model should') do
|
||||
tests('have attributes') do
|
||||
model_attribute_hash = console.attributes
|
||||
attributes = [
|
||||
:reference,
|
||||
:location,
|
||||
:protocol,
|
||||
:uuid,
|
||||
:__vm
|
||||
]
|
||||
tests("The console model should respond to") do
|
||||
attributes.each do |attribute|
|
||||
test("#{attribute}") { console.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::Console') { console.kind_of? Fog::Compute::XenServer::Console }
|
||||
end
|
||||
tests('A real console should') do
|
||||
tests('return valid vm') do
|
||||
test('object') { console.vm.kind_of? Fog::Compute::XenServer::Server }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
Shindo.tests('Fog::Compute[:xenserver] | console collection', ['xenserver']) do
|
||||
conn = Fog::Compute[:xenserver]
|
||||
|
||||
tests('The console collection') do
|
||||
consoles = conn.consoles.all
|
||||
|
||||
test('should not be empty') { !consoles.empty? }
|
||||
|
||||
test('should be a kind of Fog::Compute::XenServer::Consoles') { consoles.kind_of? Fog::Compute::XenServer::Consoles }
|
||||
|
||||
tests('should be able to reload itself').succeeds { consoles.reload }
|
||||
|
||||
tests('should be able to get a model') do
|
||||
tests('by reference').succeeds {
|
||||
consoles.get(hosts.first.reference).is_a? Fog::Compute::XenServer::Console
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -31,7 +31,7 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
:is_a_template,
|
||||
:__affinity,
|
||||
:allowed_operations,
|
||||
:consoles,
|
||||
:__consoles,
|
||||
:domarch,
|
||||
:domid,
|
||||
:__guest_metrics,
|
||||
|
@ -108,7 +108,14 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
tests("return valid vbds") do
|
||||
test("as an array") { server.vbds.kind_of? Array }
|
||||
server.vbds.each { |i|
|
||||
test("and each VBD should be a Fog::Compute::XenServer::VBD") { i.kind_of? Fog::Compute::XenServer::VBD }
|
||||
test("and each VBD should be a Fog::Compute::XenServer::VBD") { i.kind_of? Fog::Compute::XenServer::VBD }
|
||||
}
|
||||
end
|
||||
|
||||
tests('return valid consoles') do
|
||||
test('as an array') { server.consoles.kind_of? Array }
|
||||
server.consoles.each { |i|
|
||||
test('and each Console should be a Fog::Compute::XenServer::Console') { i.kind_of? Fog::Compute::XenServer::Console }
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue