mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[xenserver|compute] Added Vlans collection and tests
This commit is contained in:
parent
4c3713db9e
commit
bf35080b81
2 changed files with 75 additions and 0 deletions
39
lib/fog/xenserver/models/compute/vlans.rb
Normal file
39
lib/fog/xenserver/models/compute/vlans.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/xenserver/models/compute/vlan'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
|
||||
class Vlans < Fog::Collection
|
||||
|
||||
model Fog::Compute::XenServer::VLAN
|
||||
|
||||
# Return the list of VLANs available
|
||||
#
|
||||
# @return [Array] a list of Fog::Compute::XenServer::VLAN
|
||||
#
|
||||
def all(options = {})
|
||||
data = service.get_records 'VLAN'
|
||||
load(data)
|
||||
end
|
||||
|
||||
# Retrieve a VLAN object by by reference.
|
||||
#
|
||||
# @return [Fog::Compute::XenServer::VLAN]
|
||||
#
|
||||
# Returns nil if not found
|
||||
#
|
||||
def get( ref )
|
||||
if ref && obj = service.get_record( ref, 'VLAN' )
|
||||
new(obj)
|
||||
end
|
||||
rescue Fog::XenServer::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
tests/xenserver/models/compute/vlans_tests.rb
Normal file
36
tests/xenserver/models/compute/vlans_tests.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
Shindo.tests('Fog::Compute[:xenserver] | Vlans collection', ['xenserver']) do
|
||||
|
||||
service = Fog::Compute[:xenserver]
|
||||
|
||||
tests('The Vlans collection') do
|
||||
|
||||
test('should not be empty') { !service.vlans.empty? }
|
||||
|
||||
test('should be a kind of Fog::Compute::XenServer::Vlans') do
|
||||
service.vlans.kind_of? Fog::Compute::XenServer::Vlans
|
||||
end
|
||||
|
||||
tests('should be able to reload itself').succeeds { service.vlans.reload }
|
||||
|
||||
tests('should be able to get a model') do
|
||||
tests('by reference').succeeds {
|
||||
service.vlans.get(service.vlans.first.reference).is_a? \
|
||||
Fog::Compute::XenServer::VLAN
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
test 'with an invalid reference' do
|
||||
raises = false
|
||||
begin
|
||||
service.vlans.get('OpaqueRef:foo')
|
||||
rescue Fog::XenServer::RequestFailed => e
|
||||
raises = true if e.message =~ /HANDLE_INVALID/
|
||||
end
|
||||
raises
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue