Class: Environment
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- Environment
- 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
Instance Method Summary collapse
Methods inherited from CloudstackCli::Base
Methods included from CloudstackCli::OptionResolver
#resolve_account, #resolve_cluster, #resolve_compute_offering, #resolve_disk_offering, #resolve_domain, #resolve_host, #resolve_ip_network_list, #resolve_iso, #resolve_iso_for_vm_deployment, #resolve_networks, #resolve_project, #resolve_snapshot, #resolve_template, #resolve_virtual_machine, #resolve_zone, #vm_options_to_params
Methods included from CloudstackCli::Helper
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #get_server_default_nic, #pf_rule_to_object, #print_job_status, #print_options, #run_background_jobs, #update_job_status, #update_jobs, #watch_jobs
Methods inherited from Thor
banner, basename2, old_subcommand, subcommand
Instance Method Details
#add(env = ) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 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 63 64 65 66 |
# File 'lib/cloudstack-cli/commands/environment.rb', line 21 def add(env = [:environment]) config = {} unless [:url] say "Add a new environment...", :green if env say "Environment name: #{env}" else env = ask("Environment name:", :magenta) end 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 [:api_key] config[:api_key] = ask("API Key:", :magenta) end unless [:secret_key] config[:secret_key] = ask("Secret Key:", :magenta) end if env config = {env => config} config[:default] = env if [:default] end if File.exists? [:config_file] old_config = parse_config_file if !env || old_config.has_key?(env) say "This environment already exists!", :red exit unless yes?("Do you want to override your settings? [y/N]", :yellow) end config = old_config.merge(config) else newfile = true config[:default] = env if env end write_config_file(config) if newfile say "OK. Created configuration file at #{[:config_file]}.", :green else say "Added environment #{env}", :green end end |
#default(env = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cloudstack-cli/commands/environment.rb', line 94 def default(env = nil) config = parse_config_file unless env default_env = config[:default] || '-' say "The current default environment is \"#{default_env}\"" exit 0 end if env == '-' && config.key?(:url) config.delete :default else unless config.has_key?(env) say "Environment #{env} does not exist.", :red exit 1 end config[:default] = env end write_config_file(config) say "Default environment set to #{env}." end |
#delete(env) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cloudstack-cli/commands/environment.rb', line 69 def delete(env) config = parse_config_file if env == '-' config.delete(:url) config.delete(:api_key) config.delete(:secret_key) # check if the config file is empty, delete it if true if config.keys.select { |key| !key.is_a? Symbol}.size == 0 exit unless yes?("Do you really want to delete environment #{env}? [y/N]", :yellow) File.delete([:config_file]) say "OK.", :green exit end elsif config.delete(env) else say "Environment #{env} does not exist.", :red exit 1 end exit unless yes?("Do you really want to delete environment #{env}? [y/N]", :yellow) config.delete :default if config[:default] == env write_config_file(config) say "OK.", :green end |
#list ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cloudstack-cli/commands/environment.rb', line 4 def list config = parse_config_file table = [%w(Name URL Default)] table << ['-', config[:url], !config[:default]] if config.key?(:url) config.each_key do |key| unless key.class == Symbol table << [key, config[key][:url], key == config[:default]] end end print_table table end |