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

* Added new scan_sr request

* Added StorageRepository.scan method
* set_attribute request is now generic and can be used by any model
* Added VDI.set_attribute method
This commit is contained in:
Sergio Rubio 2012-04-16 21:09:52 +02:00
parent d81ab200e8
commit 8dad76cee0
7 changed files with 41 additions and 7 deletions

View file

@ -58,6 +58,7 @@ module Fog
request :set_attribute request :set_attribute
request :reboot_server request :reboot_server
request :provision_server request :provision_server
request :scan_sr
class Real class Real

View file

@ -78,7 +78,7 @@ module Fog
end end
def set_attribute(name, val) def set_attribute(name, val)
data = connection.set_attribute( reference, name, val ) data = connection.set_attribute( 'VM', reference, name, val )
# Do not reload automatically for performance reasons # Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and # We can set multiple attributes at the same time and
# then reload manually # then reload manually

View file

@ -24,6 +24,8 @@ module Fog
attribute :__vdis, :aliases => :VDIs attribute :__vdis, :aliases => :VDIs
attribute :physical_size attribute :physical_size
attribute :physical_utilisation attribute :physical_utilisation
attribute :sm_config
attribute :virtual_allocation
def vdis def vdis
__vdis.collect { |vdi| connection.vdis.get vdi } __vdis.collect { |vdi| connection.vdis.get vdi }
@ -33,6 +35,11 @@ module Fog
__pbds.collect { |pbd| connection.pbds.get pbd } __pbds.collect { |pbd| connection.pbds.get pbd }
end end
def scan
connection.scan_sr reference
reload
end
end end
end end

View file

@ -53,6 +53,10 @@ module Fog
super super
end end
def set_attribute(name, val)
data = connection.set_attribute( 'VDI', reference, name, val )
end
def snapshot_of def snapshot_of
connection.vdis.get __sr connection.vdis.get __sr
end end

View file

@ -0,0 +1,22 @@
module Fog
module Compute
class XenServer
class Real
def scan_sr( ref, extra_args = {})
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.scan'}, ref)
end
end
class Mock
def scan_sr(ref, extra_args = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -6,15 +6,15 @@ module Fog
require 'fog/xenserver/parser' require 'fog/xenserver/parser'
def set_attribute( ref, attr_name, value ) def set_attribute( klass, ref, attr_name, value )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "VM.set_#{attr_name.gsub('-','_')}"}, ref, value) @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "#{klass}.set_#{attr_name.gsub('-','_')}"}, ref, value)
end end
end end
class Mock class Mock
def set_attribute( ref, attr_name, value ) def set_attribute( klass, ref, attr_name, value )
Fog::Mock.not_implemented Fog::Mock.not_implemented
end end

View file

@ -10,17 +10,17 @@ Shindo.tests('Fog::Compute[:xenserver] | set_attribute request', ['xenserver'])
:template_name => test_template_name) :template_name => test_template_name)
tests('Setting an attribute with set_attribute should') do tests('Setting an attribute with set_attribute should') do
test('set the PV_bootloader attr to foobar') do test('set the PV_bootloader attr to foobar') do
response = connection.set_attribute(server.reference, 'PV_bootloader', 'foobar') response = connection.set_attribute('VM', server.reference, 'PV_bootloader', 'foobar')
server.reload server.reload
server.pv_bootloader == 'foobar' server.pv_bootloader == 'foobar'
end end
test('set the PV-bootloader attr to stuff') do test('set the PV-bootloader attr to stuff') do
response = connection.set_attribute(server.reference, 'PV-bootloader', 'stuff') response = connection.set_attribute('VM', server.reference, 'PV-bootloader', 'stuff')
server.reload server.reload
server.pv_bootloader == 'stuff' server.pv_bootloader == 'stuff'
end end
test('set the other_config attr { "foo" => "bar", :stuff => "crap" }') do test('set the other_config attr { "foo" => "bar", :stuff => "crap" }') do
response = connection.set_attribute(server.reference, 'other_config', { "foo" => "bar", :stuff => 'crap' }) response = connection.set_attribute('VM', server.reference, 'other_config', { "foo" => "bar", :stuff => 'crap' })
server.reload server.reload
(server.other_config['foo'] == 'bar') and \ (server.other_config['foo'] == 'bar') and \
(server.other_config['stuff'] == 'crap') (server.other_config['stuff'] == 'crap')