mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2787 from fog/isolate_vsphere_helper
[Vsphere] Isolate helper from core
This commit is contained in:
commit
2c1b464286
4 changed files with 28 additions and 6 deletions
|
@ -13,5 +13,28 @@ module Fog
|
|||
|
||||
service(:compute, 'Compute')
|
||||
|
||||
# This helper was originally added as Fog.class_as_string and moved to core but only used here
|
||||
def self.class_from_string classname, defaultpath=""
|
||||
if classname and classname.is_a? String then
|
||||
chain = classname.split("::")
|
||||
klass = Kernel
|
||||
chain.each do |klass_string|
|
||||
klass = klass.const_get klass_string
|
||||
end
|
||||
if klass.is_a? Class then
|
||||
klass
|
||||
elsif defaultpath != nil then
|
||||
class_from_string((defaultpath.split("::")+chain).join("::"), nil)
|
||||
else
|
||||
nil
|
||||
end
|
||||
elsif classname and classname.is_a? Class then
|
||||
classname
|
||||
else
|
||||
nil
|
||||
end
|
||||
rescue NameError
|
||||
defaultpath != nil ? class_from_string((defaultpath.split("::")+chain).join("::"), nil) : nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,10 +24,10 @@ module Fog
|
|||
|
||||
if attributes.has_key? :type then
|
||||
if attributes[:type].is_a? String then
|
||||
attributes[:type] = Fog.class_from_string(attributes[:type], "RbVmomi::VIM")
|
||||
attributes[:type] = Fog::Vsphere.class_from_string(attributes[:type], "RbVmomi::VIM")
|
||||
end
|
||||
else
|
||||
attributes[:type] = Fog.class_from_string("VirtualE1000", "RbVmomi::VIM")
|
||||
attributes[:type] = Fog::Vsphere.class_from_string("VirtualE1000", "RbVmomi::VIM")
|
||||
end
|
||||
|
||||
super defaults.merge(attributes)
|
||||
|
@ -84,7 +84,7 @@ module Fog
|
|||
:name=>"Network adapter",
|
||||
:network=>"VM Network",
|
||||
:summary=>"VM Network",
|
||||
:type=> Fog.class_from_string(default_type, "RbVmomi::VIM"),
|
||||
:type=> Fog::Vsphere.class_from_string(default_type, "RbVmomi::VIM"),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ module Fog
|
|||
controller_default_options
|
||||
end
|
||||
controller_class=if options[:type].is_a? String then
|
||||
Fog::class_from_string options[:type], "RbVmomi::VIM"
|
||||
Fog::Vsphere.class_from_string options[:type], "RbVmomi::VIM"
|
||||
else
|
||||
options[:type]
|
||||
end
|
||||
|
|
|
@ -15,8 +15,7 @@ module Fog
|
|||
:id => nic,
|
||||
:name => nic,
|
||||
:datacenter => datacenter,
|
||||
:servertype => servertype,
|
||||
# :class => Fog.class_from_string(nic)
|
||||
:servertype => servertype
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue