Class: CloudstackNagios::Cli

Inherits:
Base
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/cloudstack-nagios/cli.rb

Constant Summary

Constants included from Helper

Helper::RETURN_CODES

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Methods included from Helper

#check_data, #cs_routers, #cs_system_vms, #exit_with_failure, #load_template, #storage_pools

Instance Method Details

#environments(file = ) ⇒ 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 = options[: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 = options[:config])
  config = {}
  unless options[: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 options[:api_key]
    config[:api_key] = ask("API Key:", :magenta)
  end
  unless options[:secret_key]
    config[:secret_key] = ask("Secret Key:", :magenta)
  end
  if options[:environment]
    config = {options[: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

#versionObject



25
26
27
# File 'lib/cloudstack-nagios/cli.rb', line 25

def version
  say "cloudstack-nagios v#{CloudstackNagios::VERSION}"
end