Class: Fog::Networking::Services

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/networking/services.rb

Class Method Summary collapse

Class Method Details

.connect_instances(instance_from, instance_to, port) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/networking/services.rb', line 5

def self.connect_instances(instance_from, instance_to, port)
	if instance_from == nil || instance_to == nil then
		raise ArgumentError.new('Need to a Fog instance of both from and to');
	end

	# Not sure if this is the best approach. I had considered extending the actual
	# fog libraries and adding the extra functions we need, but then I'd have to
	# include all the fog modules as dependencies to this one, regardless if the 
	# end user wanted to use them all or not. Simple approach seemed to be to 
	# just record which objects map to which classes in here. 
	registry = YAML.load_file( File.join(File.dirname(File.expand_path(__FILE__)), 'registry.yaml'))
	if !registry[instance_to.class.to_s] then
		raise ArgumentError.new("Fog::Networking does not currently support #{instance_to.class.to_s}")
	end
	if !registry[instance_from.class.to_s] then
		raise ArgumentError.new("Fog::Networking does not currently support #{instance_from.class.to_s}")
	end

	service_to = Object.const_get(registry[instance_to.class.to_s]).new(instance_to)
	service_to.prepare
	service_from = Object.const_get(registry[instance_from.class.to_s]).new(instance_from)
	service_from.prepare

	# connect the two instances
	service_to.connect(service_from.get_ip_address, port)
end