#!/usr/bin/env ruby # (c) Copyright 2014 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'fog' require_relative 'yaml_parse.rb' include YamlParse module Connection def compute credentials = get_credentials compute = 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' }) end def network credentials = get_credentials network = 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'], }) end end def get_credentials home = File.expand_path('~') file = home + '/.hpcloud/.hpcloud' template = YAML.load_file(file) credentials = Hash.new begin credentials['access_key'] = template['default']['access_key'] credentials['secret_key'] = template['default']['secret_key'] credentials['auth_uri'] = template['default']['auth_uri'] credentials['tenant_id'] = template['default']['tenant_id'] credentials['availability_zone'] = template['default']['availability_zone'] rescue puts 'your credentials are not configured, delete the file %s and run forj setup again' % [file] end credentials end