Class: CloudstackNagios::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/cloudstack-nagios/cli.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #command(command, *args) ⇒ Object
- #environments(file = ) ⇒ Object
- #setup(file = options[:config]) ⇒ Object
- #version ⇒ Object
Methods inherited from Base
Methods included from Helper
Instance Method Details
#command(command, *args) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/cloudstack-nagios/cli.rb', line 86 def command(command, *args) params = {'command' => command} args.each do |arg| arg = arg.split('=') params[arg[0]] = arg[1] end puts JSON.pretty_generate(client.send_request params) end |
#environments(file = ) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cloudstack-nagios/cli.rb', line 66 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
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 63 |
# File 'lib/cloudstack-nagios/cli.rb', line 34 def setup(file = [:config]) config = {} unless [:url] say "Configuring #{[: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
24 25 26 |
# File 'lib/cloudstack-nagios/cli.rb', line 24 def version say "cloudstack-nagios v#{CloudstackNagios::VERSION}" end |