Class: CloudstackCli::Cli
- Inherits:
-
Base
- Object
- Thor
- Base
- CloudstackCli::Cli
show all
- Includes:
- Thor::Actions
- Defined in:
- lib/cloudstack-cli/cli.rb
Constant Summary
Constants included
from Helper
Helper::ASYNC_STATES
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
exit_on_failure?
Methods included from 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
#command(command, *args) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/cloudstack-cli/cli.rb', line 62
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
|
#setup(file = options[:config]) ⇒ Object
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
|
# File 'lib/cloudstack-cli/cli.rb', line 30
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
|
#version ⇒ Object
22
23
24
|
# File 'lib/cloudstack-cli/cli.rb', line 22
def version
say "cloudstack-cli v#{CloudstackCli::VERSION}"
end
|