Class: Environment

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/environment.rb

Constant Summary

Constants included from CloudstackCli::Helper

CloudstackCli::Helper::ASYNC_STATES

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Methods inherited from CloudstackCli::Base

exit_on_failure?

Methods included from CloudstackCli::Helper

#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #print_job_status, #print_options, #update_job_status, #watch_jobs

Instance Method Details

#add(env = ) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cloudstack-cli/commands/environment.rb', line 18

def add(env = options[:environment])
  config = {}
  unless options[:url]
    say "Add a new environment (#{env || 'default'})."
    say "What's the URL of your Cloudstack API?", :yellow
    say "Example: https://my-cloudstack-service/client/api/", :green
    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 env
    config = {env => config}
  end
  if File.exists? options[:config_file]
    old_config = parse_configfile(options[:config_file])
    say "Warning: #{options[:config_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(options[:config_file], 'w+') {|f| f.write(config.to_yaml) }
  say "OK, config-file written to #{options[:config_file]}.", :green
end

#delete(name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/cloudstack-cli/commands/environment.rb', line 46

def delete(name)
  config = parse_configfile(options[:config_file])
  exit unless yes?("Do you really want delete environment #{name}? [y/N]", :red)
  config.delete(name)
  File.open(options[:config_file], 'w+') {|f| f.write(config.to_yaml) }
  say "OK.", :green
end

#listObject



4
5
6
7
8
9
10
11
12
# File 'lib/cloudstack-cli/commands/environment.rb', line 4

def list
  config = parse_configfile(options[:config_file])
  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