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 :reboot_server
request :provision_server
request :scan_sr
class Real

View file

@ -78,7 +78,7 @@ module Fog
end
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
# We can set multiple attributes at the same time and
# then reload manually

View file

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

View file

@ -53,6 +53,10 @@ module Fog
super
end
def set_attribute(name, val)
data = connection.set_attribute( 'VDI', reference, name, val )
end
def snapshot_of
connection.vdis.get __sr
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'
def set_attribute( ref, attr_name, value )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "VM.set_#{attr_name.gsub('-','_')}"}, ref, value)
def set_attribute( klass, ref, attr_name, value )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "#{klass}.set_#{attr_name.gsub('-','_')}"}, ref, value)
end
end
class Mock
def set_attribute( ref, attr_name, value )
def set_attribute( klass, ref, attr_name, value )
Fog::Mock.not_implemented
end

View file

@ -10,17 +10,17 @@ Shindo.tests('Fog::Compute[:xenserver] | set_attribute request', ['xenserver'])
:template_name => test_template_name)
tests('Setting an attribute with set_attribute should') 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.pv_bootloader == 'foobar'
end
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.pv_bootloader == 'stuff'
end
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.other_config['foo'] == 'bar') and \
(server.other_config['stuff'] == 'crap')