Class: CloudstackCli::Cli

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

Instance Method Summary collapse

Instance Method Details

#command(command, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/cloudstack-cli/cli.rb', line 36

def command(command, *args)
  client = CloudstackCli::Helper.new(options[:config])
  params = {'command' => command}
  args.each do |arg|
    arg = arg.split('=')
    params[arg[0]] = arg[1] 
  end
  puts JSON.pretty_generate(client.cs.send_request params)
end

#setup(file = options[:config]) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cloudstack-cli/cli.rb', line 12

def setup(file = options[:config])
  config = {}
  unless options[:url]
    say "What's the URL of your Cloudstack API?", :blue
    say "Example: https://my-cloudstack-server/client/api/", :blue
    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 File.exists? file
    say "Warning: #{file} already exists.", :red
    exit unless yes?("Overwrite [y/N]", :red)
  end
  File.open(file, 'w+') {|f| f.write(config.to_yaml) }
end