Class: CloudstackCli::Cli

Inherits:
Base 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?, start

Methods included from 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 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

#command(command, *args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cloudstack-cli/cli.rb', line 53

def command(command, *args)
  params = { 'command' => command }
  args.each do |arg|
    arg = arg.split('=')
    params[arg[0]] = arg[1]
  end

  unless client.api.commands.has_key? command
    say "ERROR: ", :red
    say "Unknown API command '#{command}'."
    exit!
  end

  unless client.api.all_required_params?(command, params)
    raise CloudstackClient::ParameterError, client.api.missing_params_msg(command)
  end

  data = client.send_request(params)
  if options[:format] == 'json'
    puts options[:pretty_print] ? JSON.pretty_generate(data) : data.to_json
  else
    puts data.to_yaml
  end
end

#completionObject



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

def completion
  shell_script = File.join(
    File.dirname(__FILE__), '..', '..',
    'completions', "cloudstack-cli.#{options[:shell]}"
  )
  unless File.file? shell_script
    say "Specified cloudstack-cli shell auto-completion rules for #{options[:shell]} not found.", :red
    exit 1
  end
  puts File.read shell_script
end

#setup(env = options[:environment]) ⇒ Object



29
30
31
32
# File 'lib/cloudstack-cli/cli.rb', line 29

def setup(env = options[:environment])
  invoke "environment:add", [env],
    :config_file => options[:config_file]
end

#versionObject



23
24
25
26
# File 'lib/cloudstack-cli/cli.rb', line 23

def version
  say "cloudstack-cli version #{CloudstackCli::VERSION}"
  say " (cloudstack_client version #{CloudstackClient::VERSION})"
end