Sha256: c67cf10eb9756ea1f36e5239f5f1072844901a67843c5761b02a611450954076

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require 'yaml'

module Bellows
  module Util

    @@configs=nil

    def self.load_configs

    return @@configs if not @@configs.nil?

    config_file=ENV['BELLOWS_CONFIG_FILE']
    if config_file.nil? then

      config_file=ENV['HOME']+File::SEPARATOR+".bellows.conf"
      if not File.exists?(config_file) then
        config_file="/etc/bellows.conf"
      end

    end

    if File.exists?(config_file) then
      configs = YAML.load_file(config_file) || {}
      raise_if_nil_or_empty(configs, "smokestack_url")
      raise_if_nil_or_empty(configs, "smokestack_username")
      raise_if_nil_or_empty(configs, "smokestack_password")
      @@configs=configs
    else
      raise "Failed to load bellows config file. Please configure /etc/bellows.conf or create a .bellows.conf config file in your HOME directory."
    end

    @@configs

    end

    def self.raise_if_nil_or_empty(options, key)
      if not options or options[key].nil? or options[key].empty? then
        raise "Please specify a valid #{key.to_s} parameter."
      end
    end

    def self.short_spec(refspec)
      refspec.sub(/\/[^\/]*$/, "")
    end

    VALID_PROJECTS = ['nova', 'glance', 'keystone']
    def self.validate_project(project)
      if not VALID_PROJECTS.include?(project) then
        puts "ERROR: Please specify a valid project name."
        exit 1
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bellows-1.0.10 lib/bellows/util.rb
bellows-1.0.9 lib/bellows/util.rb
bellows-1.0.8 lib/bellows/util.rb
bellows-1.0.7 lib/bellows/util.rb
bellows-1.0.6 lib/bellows/util.rb
bellows-1.0.5 lib/bellows/util.rb