mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[xenserver] Console model created
This commit is contained in:
parent
2b3b024c72
commit
58aba87c81
7 changed files with 131 additions and 37 deletions
|
@ -2,17 +2,17 @@ require 'fog/xenserver'
|
|||
require 'fog/compute'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
module Compute
|
||||
class XenServer < Fog::Service
|
||||
|
||||
require 'fog/xenserver/utilities'
|
||||
require 'fog/xenserver/parser'
|
||||
|
||||
|
||||
requires :xenserver_username
|
||||
requires :xenserver_password
|
||||
requires :xenserver_url
|
||||
recognizes :xenserver_defaults
|
||||
|
||||
|
||||
model_path 'fog/xenserver/models/compute'
|
||||
model :server
|
||||
collection :servers
|
||||
|
@ -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
|
||||
|
@ -76,9 +78,9 @@ module Fog
|
|||
request :destroy_vlan
|
||||
request :snapshot_server
|
||||
request :snapshot_revert
|
||||
|
||||
|
||||
class Real
|
||||
|
||||
|
||||
def initialize(options={})
|
||||
@host = options[:xenserver_url]
|
||||
@username = options[:xenserver_username]
|
||||
|
@ -91,7 +93,7 @@ module Fog
|
|||
def reload
|
||||
@connection.authenticate(@username, @password)
|
||||
end
|
||||
|
||||
|
||||
def default_template=(name)
|
||||
@defaults[:template] = name
|
||||
end
|
||||
|
@ -102,13 +104,13 @@ module Fog
|
|||
(s.name == @defaults[:template]) or (s.uuid == @defaults[:template])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def default_network
|
||||
networks.find { |n| n.name == (@defaults[:network] || "Pool-wide network associated with eth0") }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
|
@ -116,13 +118,13 @@ module Fog
|
|||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(options={})
|
||||
@host = options[:xenserver_pool_master]
|
||||
@username = options[:xenserver_username]
|
||||
|
@ -130,7 +132,7 @@ module Fog
|
|||
@connection = Fog::Connection.new(@host)
|
||||
@connection.authenticate(@username, @password)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
27
lib/fog/xenserver/models/compute/console.rb
Normal file
27
lib/fog/xenserver/models/compute/console.rb
Normal file
|
@ -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')
|
||||
|
@ -210,4 +214,4 @@ module Fog
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,30 +9,30 @@ 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' }
|
||||
end
|
||||
# This will fail if there are no PIFs
|
||||
# This will fail if there are no PIFs
|
||||
# (not sure if that's gonna be a real scenario though)
|
||||
tests("PIFs collection") do
|
||||
test("should have at least one PIF") { compute.pifs.size >= 1 }
|
||||
end
|
||||
|
||||
|
||||
# This will fail if there are no VIFs
|
||||
# (not sure if that's gonna be a real scenario though)
|
||||
tests("VIFs collection") do
|
||||
test("should have at least one VIF") { compute.vifs.size >= 1 }
|
||||
end
|
||||
|
||||
|
||||
# This will fail if there are no VIFs
|
||||
# (not sure if that's gonna be a real scenario though)
|
||||
tests("Networks collection") do
|
||||
test("should have at least one Network") { compute.networks.size >= 1 }
|
||||
tests("each network should be a Fog::Compute::XenServer::Network") do
|
||||
ok = true
|
||||
compute.networks.each { |n| ok = false if n.kind_of? Fog::Compute::XenServer::Network }
|
||||
compute.networks.each { |n| ok = false if n.kind_of? Fog::Compute::XenServer::Network }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
35
tests/xenserver/models/compute/console_test.rb
Normal file
35
tests/xenserver/models/compute/console_test.rb
Normal file
|
@ -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
|
19
tests/xenserver/models/compute/consoles_test.rb
Normal file
19
tests/xenserver/models/compute/consoles_test.rb
Normal file
|
@ -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
|
|
@ -10,8 +10,8 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
(servers.templates.find_all { |t| t.name == test_ephemeral_vm_name}).each do |s|
|
||||
s.destroy
|
||||
end
|
||||
|
||||
server = Fog::Compute[:xenserver].servers.create(:name => test_ephemeral_vm_name,
|
||||
|
||||
server = Fog::Compute[:xenserver].servers.create(:name => test_ephemeral_vm_name,
|
||||
:template_name => test_template_name)
|
||||
server.reload
|
||||
|
||||
|
@ -25,13 +25,13 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
end
|
||||
tests('have attributes') do
|
||||
model_attribute_hash = server.attributes
|
||||
attributes = [
|
||||
attributes = [
|
||||
:reference,
|
||||
:uuid,
|
||||
:is_a_template,
|
||||
:__affinity,
|
||||
:allowed_operations,
|
||||
:consoles,
|
||||
:__consoles,
|
||||
:domarch,
|
||||
:domid,
|
||||
:__guest_metrics,
|
||||
|
@ -47,9 +47,9 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
:name_description,
|
||||
:other_config,
|
||||
:power_state,
|
||||
:pv_args,
|
||||
:pv_args,
|
||||
:__resident_on,
|
||||
:__vbds,
|
||||
:__vbds,
|
||||
:__vifs,
|
||||
:vcpus_params,
|
||||
:vcpus_at_startup,
|
||||
|
@ -84,7 +84,7 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
tests("it should create a server") do
|
||||
s = nil
|
||||
test("named #{test_ephemeral_vm_name}") do
|
||||
s = servers.create(:name => test_ephemeral_vm_name,
|
||||
s = servers.create(:name => test_ephemeral_vm_name,
|
||||
:template_name => test_template_name)
|
||||
servers.get(s.reference).name == test_ephemeral_vm_name
|
||||
end
|
||||
|
@ -94,7 +94,7 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
s = nil
|
||||
# The template has 2 VIFs already, we add 2 more
|
||||
test("with 4 NICs") do
|
||||
s = servers.create(:name => test_ephemeral_vm_name,
|
||||
s = servers.create(:name => test_ephemeral_vm_name,
|
||||
:template_name => test_template_name,
|
||||
:networks => [connection.default_network, connection.default_network])
|
||||
s.reload
|
||||
|
@ -107,9 +107,16 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
tests("A real server should") 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 }
|
||||
}
|
||||
server.vbds.each { |i|
|
||||
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
|
||||
|
||||
test("have 0 or more networks") { server.networks.kind_of? Array }
|
||||
|
@ -131,33 +138,33 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
test("always stop when I say stop('hard')") do
|
||||
server.stop 'hard'
|
||||
end
|
||||
|
||||
|
||||
# shutdown is async apparently, we wait
|
||||
test("not be running when it's stopped") do
|
||||
server.wait_for { !server.running? }
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
test("do nothing when I say stop('hard') but it's not running") do
|
||||
server.stop('hard') == false
|
||||
end
|
||||
|
||||
|
||||
test("always start when I say start") do
|
||||
server.start
|
||||
end
|
||||
|
||||
|
||||
# start is async apparently, we wait
|
||||
test("be running if I started the server") do
|
||||
server.wait_for { server.running? }
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
test("set attribute PV_bootloader to supergrub") do
|
||||
server.set_attribute 'PV_bootloader', 'supergrub'
|
||||
server.reload
|
||||
server.pv_bootloader == 'supergrub'
|
||||
end
|
||||
|
||||
|
||||
tests("Creating a snapshot") do
|
||||
snap_ref = server.snapshot('newsnapshot')
|
||||
tests("it should create a snapshot") do
|
||||
|
@ -166,7 +173,7 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|||
end
|
||||
test("and destroy it afterwards") { servers.get(snap_ref).destroy }
|
||||
end
|
||||
|
||||
|
||||
test("be able to be destroyed!") do
|
||||
server.destroy
|
||||
servers.get_by_name('fog-test-server-shindo') == nil
|
||||
|
|
Loading…
Reference in a new issue