1+ ## This is primarily used for easier testing and development or
2+ # usage of Fog.
3+ #
4+ # How to use:
5+ # 1. Add this at the end of your `.irbrc` in your home directory.
6+ #
7+ # @working_directory = Dir.pwd
8+ # @local_irbrc = File.join(@working_directory, '.irbrc')
9+ #
10+ # if @working_directory != ENV['HOME']
11+ # load @local_irbrc if File.exists?(@local_irbrc)
12+ # end
13+ #
14+ # remove_instance_variable(:@working_directory)
15+ # remove_instance_variable(:@local_irbrc)
16+ #
17+ # 2. Inside the Fog execute `bundle exec irb`
18+ #
19+
120require 'fog'
221
322class ConnectionManager < Hash
@@ -21,7 +40,7 @@ def connection
2140 connections [ $connection_manager_previous_key]
2241end
2342
24- def connect ( username , password , tenant = nil , url = 'http://192.168.27.100:35357/' )
43+ def connect_openstack ( username , password , tenant = nil , url = 'http://192.168.27.100:35357/' )
2544 parameters = {
2645 :provider => 'openstack' ,
2746 :openstack_api_key => password ,
@@ -32,12 +51,37 @@ def connect(username, password, tenant = nil, url = 'http://192.168.27.100:35357
3251 parameters . merge! ( :openstack_tenant => tenant ) if tenant
3352
3453 identity = Fog ::Identity . new ( parameters )
35- compute = Fog ::Compute . new ( parameters )
36- image = Fog ::Image . new ( parameters )
54+ compute = Fog ::Compute . new ( parameters )
55+ volume = Fog ::Volume . new ( parameters )
56+ image = Fog ::Image . new ( parameters )
3757
3858 connections [ username . to_sym ] = {
3959 :identity => identity ,
4060 :compute => compute ,
4161 :image => image
4262 }
4363end
64+
65+ def connect ( parameters )
66+ connections_count = connections . count
67+ connections [ connections_count ] = Hash . new
68+
69+ set_service ( connections_count , Fog ::Identity , parameters )
70+ set_service ( connections_count , Fog ::Compute , parameters )
71+ set_service ( connections_count , Fog ::Storage , parameters )
72+ set_service ( connections_count , Fog ::Volume , parameters )
73+ set_service ( connections_count , Fog ::Image , parameters )
74+ set_service ( connections_count , Fog ::DNS , parameters )
75+ set_service ( connections_count , Fog ::CDN , parameters )
76+ connection
77+ end
78+
79+ def set_service ( connections_count , type , parameters )
80+ service_symbol = type . to_s . split ( '::' ) . last . downcase . to_sym
81+
82+ connections [ connections_count ] . merge! ( {
83+ service_symbol => type . new ( parameters )
84+ } )
85+ rescue
86+ # Service not available
87+ end
0 commit comments