lib/connection.rb in forj-0.0.21 vs lib/connection.rb in forj-0.0.22
- old
+ new
@@ -23,50 +23,56 @@
#
# Connection module
#
module Connection
-
def compute
- credentials = get_credentials
- Fog::Compute.new({
- :provider => 'HP',
- :hp_access_key => credentials['access_key'],
- :hp_secret_key => credentials['secret_key'],
- :hp_auth_uri => credentials['auth_uri'],
- :hp_tenant_id => credentials['tenant_id'],
- :hp_avl_zone => credentials['availability_zone'],
- :version => 'v2'
- })
+ begin
+ credentials = get_credentials
+ Fog::Compute.new({
+ :provider => 'HP',
+ :hp_access_key => credentials['access_key'],
+ :hp_secret_key => credentials['secret_key'],
+ :hp_auth_uri => credentials['auth_uri'],
+ :hp_tenant_id => credentials['tenant_id'],
+ :hp_avl_zone => credentials['availability_zone'],
+ :version => 'v2'
+ })
+ rescue => e
+ Logging.error(e.message)
+ end
end
def network
- credentials = get_credentials
- Fog::HP::Network.new({
- :hp_access_key => credentials['access_key'],
- :hp_secret_key => credentials['secret_key'],
- :hp_auth_uri => credentials['auth_uri'],
- :hp_tenant_id => credentials['tenant_id'],
- :hp_avl_zone => credentials['availability_zone']
- })
+ begin
+ credentials = get_credentials
+ Fog::HP::Network.new({
+ :hp_access_key => credentials['access_key'],
+ :hp_secret_key => credentials['secret_key'],
+ :hp_auth_uri => credentials['auth_uri'],
+ :hp_tenant_id => credentials['tenant_id'],
+ :hp_avl_zone => credentials['availability_zone']
+ })
+ rescue => e
+ Logging.error(e.message)
+ end
end
-
end
def get_credentials
home = File.expand_path('~')
- creds = '%s/.hpcloud/accounts/hp' % [home]
+ creds = format('%{home}/.hpcloud/accounts/hp', home: home)
template = YAML.load_file(creds)
credentials = Hash.new
begin
credentials['access_key'] = template[:credentials][:account_id]
credentials['secret_key'] = template[:credentials][:secret_key]
credentials['auth_uri'] = template[:credentials][:auth_uri]
credentials['tenant_id'] = template[:credentials][:tenant_id]
- credentials['availability_zone'] = template[:regions][:monitoring]
- rescue
- puts 'your credentials are not configured, delete the file %s and run forj setup again' % [creds]
+ credentials['availability_zone'] = template[:regions][:compute]
+ rescue => e
+ puts format('your credentials are not configured, delete the file %{creds} and run forj setup again', creds: creds)
+ Logging.error(e.message)
end
-
credentials
end