mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Make .irbrc
service agnostic
Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
parent
34e3b78123
commit
c3a395e64b
2 changed files with 47 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,7 +3,6 @@
|
|||
*.rbc
|
||||
*.sw?
|
||||
.rvmrc
|
||||
.irbrc
|
||||
.bundle
|
||||
.DS_Store
|
||||
.idea
|
||||
|
|
50
.irbrc
50
.irbrc
|
@ -1,3 +1,22 @@
|
|||
## This is primarily used for easier testing and development or
|
||||
# usage of Fog.
|
||||
#
|
||||
# How to use:
|
||||
# 1. Add this at the end of your `.irbrc` in your home directory.
|
||||
#
|
||||
# @working_directory = Dir.pwd
|
||||
# @local_irbrc = File.join(@working_directory, '.irbrc')
|
||||
#
|
||||
# if @working_directory != ENV['HOME']
|
||||
# load @local_irbrc if File.exists?(@local_irbrc)
|
||||
# end
|
||||
#
|
||||
# remove_instance_variable(:@working_directory)
|
||||
# remove_instance_variable(:@local_irbrc)
|
||||
#
|
||||
# 2. Inside the Fog execute `bundle exec irb`
|
||||
#
|
||||
|
||||
require 'fog'
|
||||
|
||||
class ConnectionManager < Hash
|
||||
|
@ -21,7 +40,7 @@ def connection
|
|||
connections[$connection_manager_previous_key]
|
||||
end
|
||||
|
||||
def connect(username, password, tenant = nil, url = 'http://192.168.27.100:35357/')
|
||||
def connect_openstack(username, password, tenant = nil, url = 'http://192.168.27.100:35357/')
|
||||
parameters = {
|
||||
:provider => 'openstack',
|
||||
:openstack_api_key => password,
|
||||
|
@ -32,8 +51,9 @@ def connect(username, password, tenant = nil, url = 'http://192.168.27.100:35357
|
|||
parameters.merge!(:openstack_tenant => tenant) if tenant
|
||||
|
||||
identity = Fog::Identity.new(parameters)
|
||||
compute = Fog::Compute.new(parameters)
|
||||
image = Fog::Image.new(parameters)
|
||||
compute = Fog::Compute.new(parameters)
|
||||
volume = Fog::Volume.new(parameters)
|
||||
image = Fog::Image.new(parameters)
|
||||
|
||||
connections[username.to_sym] = {
|
||||
:identity => identity,
|
||||
|
@ -41,3 +61,27 @@ def connect(username, password, tenant = nil, url = 'http://192.168.27.100:35357
|
|||
:image => image
|
||||
}
|
||||
end
|
||||
|
||||
def connect(parameters)
|
||||
connections_count = connections.count
|
||||
connections[connections_count] = Hash.new
|
||||
|
||||
set_service(connections_count, Fog::Identity, parameters)
|
||||
set_service(connections_count, Fog::Compute , parameters)
|
||||
set_service(connections_count, Fog::Storage , parameters)
|
||||
set_service(connections_count, Fog::Volume , parameters)
|
||||
set_service(connections_count, Fog::Image , parameters)
|
||||
set_service(connections_count, Fog::DNS , parameters)
|
||||
set_service(connections_count, Fog::CDN , parameters)
|
||||
connection
|
||||
end
|
||||
|
||||
def set_service(connections_count, type, parameters)
|
||||
service_symbol = type.to_s.split('::').last.downcase.to_sym
|
||||
|
||||
connections[connections_count].merge!({
|
||||
service_symbol => type.new(parameters)
|
||||
})
|
||||
rescue
|
||||
# Service not available
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue