1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[xenserver|compute] added save and destroy operations to Network

- Added also required tests
This commit is contained in:
Sergio Rubio 2013-03-26 17:33:39 +01:00
parent bf35080b81
commit 0ae1c5b242
2 changed files with 51 additions and 6 deletions

View file

@ -51,6 +51,39 @@ module Fog
v
end
# Creates a new network
#
# service = Fog::Compute[:xenserver]
#
# # create network 'foonet'
# net = service.networks.create :name => 'foonet',
# :description => 'test network'
#
# @returns [Boolean]
#
def save
requires :name
ref = service.create_network name, attributes
data = service.get_record ref, 'network'
merge_attributes data
true
end
# Destroys a network
#
# service = Fog::Compute[:xenserver]
#
# # find network 'foonet' and destroy it
# net = service.networks.find { |net| net.name == 'foonet' }
# net.destroy
#
# @returns [Boolean]
#
def destroy
requires :reference
service.destroy_network reference
true
end
end
end

View file

@ -1,16 +1,14 @@
Shindo.tests('Fog::Compute[:network] | network model', ['xenserver']) do
require 'pp'
networks = Fog::Compute[:xenserver].networks
network = networks.first
tests('The network model should') do
tests('have the action') do
test('reload') { network.respond_to? 'reload' }
#%w{ refresh stop clean_shutdown hard_shutdown start destroy reboot hard_reboot clean_reboot }.each do |action|
# test(action) { server.respond_to? action }
# #test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
#end
%w{ reload refresh destroy save vifs pifs }.each do |action|
test(action) { network.respond_to? action }
#test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
end
end
tests('have attributes') do
model_attribute_hash = network.attributes
@ -64,4 +62,18 @@ Shindo.tests('Fog::Compute[:network] | network model', ['xenserver']) do
end
tests("#save") do
test 'should create a network' do
@net = networks.create :name => 'foo-net'
@net.is_a? Fog::Compute::XenServer::Network
end
end
tests("#destroy") do
test 'should destroy the network' do
@net.destroy
(networks.find { |n| n.reference == @net.reference }).nil?
end
end
end