Class: CloudstackNagios::Cli
- Inherits:
-
Base
- Object
- Base
- CloudstackNagios::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/cloudstack-nagios/cli.rb
Instance Method Summary collapse
- #environments(file = options[:config]) ⇒ Object
- #setup(file = options[:config]) ⇒ Object
- #version ⇒ Object
Instance Method Details
#environments(file = options[:config]) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cloudstack-nagios/cli.rb', line 65 def environments(file = [:config]) config = {} if File.exists? file begin config = YAML::load(IO.read(file)) rescue error "Can't load configuration from file #{config_file}." exit 1 end table = [%w(Name URL)] table << ["default", config[:url]] config.each_key do |key| table << [key, config[key][:url]] unless key.class == Symbol end print_table table end end |
#setup(file = options[:config]) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cloudstack-nagios/cli.rb', line 33 def setup(file = [:config]) config = {} unless [:url] say "Configuring #{options[:environment] || 'default'} environment." say "What's the URL of your Cloudstack API?", :yellow say "Example: https://my-cloudstack-service/client/api/" config[:url] = ask("URL:", :magenta) end unless [:api_key] config[:api_key] = ask("API Key:", :magenta) end unless [:secret_key] config[:secret_key] = ask("Secret Key:", :magenta) end if [:environment] config = {[:environment] => config} end if File.exists? file begin old_config = YAML::load(IO.read(file)) rescue error "Can't load configuration from file #{config_file}." exit 1 end say "Warning: #{file} already exists.", :red exit unless yes?("Do you want to merge your settings? [y/N]", :red) config = old_config.merge(config) end File.open(file, 'w+') {|f| f.write(config.to_yaml) } end |
#version ⇒ Object
25 26 27 |
# File 'lib/cloudstack-nagios/cli.rb', line 25 def version say "cloudstack-nagios v#{CloudstackNagios::VERSION}" end |