cloudstack-cli 0.15.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +4 -5
  4. data/cloudstack-cli.gemspec +2 -2
  5. data/lib/cloudstack-cli/base.rb +6 -16
  6. data/lib/cloudstack-cli/cli.rb +16 -4
  7. data/lib/cloudstack-cli/commands/account.rb +2 -4
  8. data/lib/cloudstack-cli/commands/affinity_group.rb +2 -1
  9. data/lib/cloudstack-cli/commands/capacity.rb +27 -26
  10. data/lib/cloudstack-cli/commands/cluster.rb +6 -3
  11. data/lib/cloudstack-cli/commands/compute_offer.rb +13 -11
  12. data/lib/cloudstack-cli/commands/configuration.rb +5 -6
  13. data/lib/cloudstack-cli/commands/disk_offer.rb +4 -3
  14. data/lib/cloudstack-cli/commands/domain.rb +6 -6
  15. data/lib/cloudstack-cli/commands/host.rb +16 -2
  16. data/lib/cloudstack-cli/commands/ip_address.rb +23 -14
  17. data/lib/cloudstack-cli/commands/iso.rb +23 -21
  18. data/lib/cloudstack-cli/commands/job.rb +15 -13
  19. data/lib/cloudstack-cli/commands/load_balancer.rb +63 -25
  20. data/lib/cloudstack-cli/commands/network.rb +25 -70
  21. data/lib/cloudstack-cli/commands/physical_network.rb +4 -4
  22. data/lib/cloudstack-cli/commands/pod.rb +3 -1
  23. data/lib/cloudstack-cli/commands/port_rule.rb +23 -17
  24. data/lib/cloudstack-cli/commands/project.rb +11 -12
  25. data/lib/cloudstack-cli/commands/resource_limit.rb +8 -12
  26. data/lib/cloudstack-cli/commands/router.rb +35 -42
  27. data/lib/cloudstack-cli/commands/snapshot.rb +5 -2
  28. data/lib/cloudstack-cli/commands/ssh_key_pairs.rb +20 -6
  29. data/lib/cloudstack-cli/commands/stack.rb +49 -39
  30. data/lib/cloudstack-cli/commands/storage_pool.rb +4 -3
  31. data/lib/cloudstack-cli/commands/system_vm.rb +11 -14
  32. data/lib/cloudstack-cli/commands/template.rb +11 -14
  33. data/lib/cloudstack-cli/commands/user.rb +4 -9
  34. data/lib/cloudstack-cli/commands/virtual_machine.rb +243 -0
  35. data/lib/cloudstack-cli/commands/volume.rb +117 -2
  36. data/lib/cloudstack-cli/commands/zone.rb +7 -3
  37. data/lib/cloudstack-cli/helper.rb +96 -35
  38. data/lib/cloudstack-cli/option_resolver.rb +176 -0
  39. data/lib/cloudstack-cli/version.rb +1 -1
  40. data/lib/cloudstack-cli.rb +2 -1
  41. metadata +9 -8
  42. data/lib/cloudstack-cli/commands/server.rb +0 -230
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7345dcbef6139ac587c38fb98f9225e19e0e63df
4
- data.tar.gz: 56740cf452feeb2e9a823b9b0ad0db6397973c35
3
+ metadata.gz: abbccb8fdb7cb7d93fb79f33f58f53469e0763fd
4
+ data.tar.gz: 6e4e7df9e6d4f4cbe5e6d79ffa0497426801d0c5
5
5
  SHA512:
6
- metadata.gz: e5259be78f9c2b6d3ebf34fe5c3cfa79f87d9c430d8a024c245130e33c744058725e11fb2e681b622fc34c889c9f26c08cdbeda2d138c3b7b01940c19e25902c
7
- data.tar.gz: cab48f91652b1e8b6ef8d5345b735a41c1d5f300b49511ff3ff47f4fa27ad6c337bf3b0f11825a9ffcc7e8ee3939bca5febdc5be5354dadc83de79dbbb37ba15
6
+ metadata.gz: 48faa2904edaeb89a5dc81c7068b851ab1b99e241bdc2c836f30ac1dfaccdce608212cd6cc258fe3675dd8bb5fa58a3e3159b34d7649cfc2fd082423af724b22
7
+ data.tar.gz: 3ee41e41a2ab280d2dce91ad2f57eeeb16b362428729b98e47522f514cf743eb72fdbe5e2bd82d2d1c7b5999cfca0b3e9f5fb6807e79d72575b737d936bd3f5e
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'cloudstack_client', git: 'git@github.com:niwo/cloudstack_client.git', branch: 'master'
3
+ gem 'cloudstack_client', git: 'git@github.com:niwo/cloudstack_client.git'
4
4
 
5
5
  # Specify your gem's dependencies in cloudstack-cli.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,15 +1,14 @@
1
1
  GIT
2
2
  remote: git@github.com:niwo/cloudstack_client.git
3
- revision: cc23ab7c336f0933d41ae3976fcac71e357b8b0d
4
- branch: master
3
+ revision: b388af01e7403f65fc1ad5cd4c905a1f005afea3
5
4
  specs:
6
- cloudstack_client (0.9.7)
5
+ cloudstack_client (1.0.0.rc1)
7
6
 
8
7
  PATH
9
8
  remote: .
10
9
  specs:
11
- cloudstack-cli (0.14.1)
12
- cloudstack_client (~> 0.9.7)
10
+ cloudstack-cli (1.0.0.rc1)
11
+ cloudstack_client (~> 1.0.0.rc1)
13
12
  thor (~> 0.19.1)
14
13
 
15
14
  GEM
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{cloudstack-cli is a CloudStack API command line client written in Ruby.}
12
12
  gem.summary = %q{cloudstack-cli CloudStack API client}
13
13
  gem.date = Time.now.utc.strftime("%Y-%m-%d")
14
- gem.homepage = 'http://niwo.github.io/cloudstack-cli/'
14
+ gem.homepage = 'http://github.com/niwo/cloudstack-cli'
15
15
  gem.license = 'MIT'
16
16
 
17
17
  gem.required_ruby_version = '>= 1.9.3'
@@ -25,5 +25,5 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency('rake', '~> 10.4')
26
26
 
27
27
  gem.add_dependency('thor', '~> 0.19.1')
28
- gem.add_dependency('cloudstack_client', '~> 0.9.7')
28
+ gem.add_dependency('cloudstack_client', '~> 1.0.0.rc1')
29
29
  end
@@ -6,6 +6,7 @@ module CloudstackCli
6
6
  class Base < Thor
7
7
  include Thor::Actions
8
8
  include CloudstackCli::Helper
9
+ include CloudstackCli::OptionResolver
9
10
 
10
11
  attr_reader :config
11
12
 
@@ -21,14 +22,15 @@ module CloudstackCli
21
22
  end
22
23
 
23
24
  no_commands do
24
- def client(opts = {})
25
+ def client
25
26
  @config ||= load_configuration
26
- @client ||= CloudstackClient::Connection.new(
27
+ @client ||= CloudstackClient::Client.new(
27
28
  @config[:url],
28
29
  @config[:api_key],
29
- @config[:secret_key],
30
- opts.merge({debug: options[:debug]})
30
+ @config[:secret_key]
31
31
  )
32
+ @client.debug = true if options[:debug]
33
+ @client
32
34
  end
33
35
 
34
36
  def load_configuration(config_file = options[:config_file], env = options[:env])
@@ -61,18 +63,6 @@ module CloudstackCli
61
63
  config
62
64
  end
63
65
 
64
- def find_project(name = options[:project], allow_all = true)
65
- return nil unless name
66
- if allow_all && %w(ALL -1).include?(name)
67
- return {'id' => '-1'}
68
- end
69
- unless project = client.get_project(name)
70
- say "Project '#{name}' not found", :red
71
- exit 1
72
- end
73
- project
74
- end
75
-
76
66
  def filter_by(objects, key, value)
77
67
  objects.select {|r| r[key].downcase == value.downcase}
78
68
  end
@@ -15,7 +15,8 @@ module CloudstackCli
15
15
 
16
16
  class_option :debug,
17
17
  desc: 'Enable debug output',
18
- type: :boolean
18
+ type: :boolean,
19
+ default: false
19
20
 
20
21
  desc "version", "Print cloudstack-cli version number"
21
22
  def version
@@ -45,6 +46,10 @@ module CloudstackCli
45
46
  end
46
47
 
47
48
  desc "command COMMAND [arg1=val1 arg2=val2...]", "Run a custom api command"
49
+ option :format, default: 'json',
50
+ enum: %w(json yaml), desc: "output format"
51
+ option :pretty_print, default: true, type: :boolean,
52
+ desc: "pretty print json output"
48
53
  def command(command, *args)
49
54
  params = {'command' => command}
50
55
  args.each do |arg|
@@ -52,7 +57,12 @@ module CloudstackCli
52
57
  params[arg[0]] = arg[1]
53
58
  end
54
59
  data = client.send_request(params)
55
- puts JSON.pretty_generate(data)
60
+ output = if options[:format] == 'json'
61
+ options[:pretty_print] ? JSON.pretty_generate(data) : data.to_json
62
+ else
63
+ data.to_yaml
64
+ end
65
+ puts output
56
66
  end
57
67
 
58
68
  # require subcommands
@@ -79,8 +89,10 @@ module CloudstackCli
79
89
  desc "project SUBCOMMAND ...ARGS", "Manage servers"
80
90
  subcommand :project, Project
81
91
 
82
- desc "server SUBCOMMAND ...ARGS", "Manage servers"
83
- subcommand :server, Server
92
+ desc "virtual_machine SUBCOMMAND ...ARGS", "Manage virtual machines"
93
+ subcommand :virtual_machine, VirtualMachine
94
+ map 'vm' => :virtual_machine
95
+ map 'server' => :virtual_machine
84
96
 
85
97
  desc "compute_offer SUBCOMMAND ...ARGS", "Manage offerings"
86
98
  subcommand :compute_offer, ComputeOffer
@@ -8,11 +8,9 @@ class Account < CloudstackCli::Base
8
8
 
9
9
  desc "show NAME", "show detailed infos about an account"
10
10
  def show(name)
11
- accounts = client.list_accounts(name: name)
12
- if accounts.size < 1
11
+ unless account = client.list_accounts(name: name).first
13
12
  say "No account named \"#{name}\" found.", :red
14
13
  else
15
- account = accounts.first
16
14
  account.delete 'user'
17
15
  account['accounttype'] = "#{account['accounttype']} (#{TYPES[account['accounttype']]})"
18
16
  table = account.map do |key, value|
@@ -24,7 +22,7 @@ class Account < CloudstackCli::Base
24
22
 
25
23
  desc 'list', 'list accounts'
26
24
  def list
27
- accounts = client.list_accounts
25
+ accounts = client.list_accounts(listall: true)
28
26
  if accounts.size < 1
29
27
  puts "No accounts found."
30
28
  else
@@ -7,6 +7,7 @@ class AffinityGroup < CloudstackCli::Base
7
7
  option :listall
8
8
  option :keyword
9
9
  def list
10
+ resolve_account
10
11
  affinity_groups = client.list_affinity_groups(options)
11
12
  if affinity_groups.size < 1
12
13
  say "No affinity groups found."
@@ -24,4 +25,4 @@ class AffinityGroup < CloudstackCli::Base
24
25
  end
25
26
  end
26
27
 
27
- end
28
+ end
@@ -1,32 +1,33 @@
1
1
  class Capacity < CloudstackCli::Base
2
- CAPACITY_TYPES = {
3
- 0 => {name: "Memory", unit: "GB", divider: 1024.0**3},
4
- 1 => {name: "CPU", unit: "GHz", divider: 1000.0},
5
- 2 => {name: "Storage", unit: "TB", divider: 1024.0**4},
6
- 3 => {name: "Primary Storage", unit: "TB", divider: 1024.0**4},
7
- 4 => {name: "Public IP's"},
8
- 5 => {name: "Private IP's"},
9
- 6 => {name: "Secondary Storage", unit: "TB", divider: 1024.0**4},
10
- 7 => {name: "VLAN"},
11
- 8 => {name: "Direct Attached Public IP's"},
12
- 9 => {name: "Local Storage", unit: "TB", divider: 1024.0**4}
13
- }
2
+ CAPACITY_TYPES = {
3
+ 0 => {name: "Memory", unit: "GB", divider: 1024.0**3},
4
+ 1 => {name: "CPU", unit: "GHz", divider: 1000.0},
5
+ 2 => {name: "Storage", unit: "TB", divider: 1024.0**4},
6
+ 3 => {name: "Primary Storage", unit: "TB", divider: 1024.0**4},
7
+ 4 => {name: "Public IP's"},
8
+ 5 => {name: "Private IP's"},
9
+ 6 => {name: "Secondary Storage", unit: "TB", divider: 1024.0**4},
10
+ 7 => {name: "VLAN"},
11
+ 8 => {name: "Direct Attached Public IP's"},
12
+ 9 => {name: "Local Storage", unit: "TB", divider: 1024.0**4}
13
+ }
14
14
 
15
15
  desc "list", "list system capacity"
16
- option :zone
16
+ option :zone, desc: "lists clusters by zone"
17
17
  option :type, desc: "specify type, see types for a list of types"
18
18
  def list
19
- capacities = client.list_capacity(options)
20
- table = []
19
+ resolve_zone if options[:zone]
20
+ capacities = client.list_capacity(options)
21
+ table = []
21
22
  header = ["Zone", "Type", "Capacity Used", "Capacity Total", "Used"]
22
23
  capacities.each do |c|
23
- table << [
24
- c['zonename'],
25
- CAPACITY_TYPES[c['type']][:name],
26
- capacity_to_s(c, 'capacityused'),
27
- capacity_to_s(c, 'capacitytotal'),
28
- "#{c['percentused']}%"
29
- ]
24
+ table << [
25
+ c['zonename'],
26
+ CAPACITY_TYPES[c['type']][:name],
27
+ capacity_to_s(c, 'capacityused'),
28
+ capacity_to_s(c, 'capacitytotal'),
29
+ "#{c['percentused']}%"
30
+ ]
30
31
  end
31
32
  table = table.sort {|a, b| [a[0], a[1]] <=> [b[0], b[1]]}.insert(0, header)
32
33
  print_table table
@@ -44,14 +45,14 @@ class Capacity < CloudstackCli::Base
44
45
  no_commands do
45
46
 
46
47
  def capacity_to_s(capacity, entity)
47
- value = CAPACITY_TYPES[capacity['type']][:divider] ?
48
- (capacity[entity] / CAPACITY_TYPES[capacity['type']][:divider]).round(1) :
48
+ value = CAPACITY_TYPES[capacity['type']][:divider] ?
49
+ (capacity[entity] / CAPACITY_TYPES[capacity['type']][:divider]).round(1) :
49
50
  capacity[entity]
50
- CAPACITY_TYPES[capacity['type']][:unit] ?
51
+ CAPACITY_TYPES[capacity['type']][:unit] ?
51
52
  "#{value} #{CAPACITY_TYPES[capacity['type']][:unit]}" :
52
53
  value.to_s
53
54
  end
54
55
 
55
56
  end
56
57
 
57
- end
58
+ end
@@ -1,16 +1,19 @@
1
1
  class Cluster < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list clusters'
4
+ option :zone, desc: "lists clusters by zone"
4
5
  def list
6
+ resolve_zone if options[:zone]
5
7
  clusters = client.list_clusters(options)
6
8
  if clusters.size < 1
7
9
  say "No clusters found."
8
10
  else
9
- table = [%w(Name Pod_Name Type Zone)]
11
+ table = [%w(Name Pod_Name Type Zone State)]
10
12
  clusters.each do |cluster|
11
13
  table << [
12
14
  cluster['name'], cluster['podname'],
13
- cluster['hypervisortype'], cluster['zonename']
15
+ cluster['hypervisortype'], cluster['zonename'],
16
+ cluster['managedstate']
14
17
  ]
15
18
  end
16
19
  print_table table
@@ -18,4 +21,4 @@ class Cluster < CloudstackCli::Base
18
21
  end
19
22
  end
20
23
 
21
- end
24
+ end
@@ -1,9 +1,10 @@
1
1
  class ComputeOffer < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list compute offerings'
4
- option :domain
4
+ option :domain, desc: "the domain associated with the compute offering"
5
5
  def list
6
- offerings = client.list_service_offerings(options[:domain])
6
+ resolve_domain
7
+ offerings = client.list_service_offerings(options)
7
8
  if offerings.size < 1
8
9
  puts "No offerings found."
9
10
  else
@@ -21,7 +22,7 @@ class ComputeOffer < CloudstackCli::Base
21
22
  end
22
23
  end
23
24
 
24
- desc 'create NAME', 'create offering'
25
+ desc 'create NAME', 'create compute offering'
25
26
  option :cpunumber, required: true
26
27
  option :cpuspeed, required: true
27
28
  option :displaytext, required: true
@@ -30,31 +31,32 @@ class ComputeOffer < CloudstackCli::Base
30
31
  option :ha, type: :boolean
31
32
  option :tags
32
33
  def create(name)
34
+ resolve_domain
33
35
  options[:name] = name
34
36
  puts "OK" if client.create_offering(options)
35
37
  end
36
38
 
37
- desc 'delete ID', 'delete offering'
39
+ desc 'delete ID', 'delete compute offering'
38
40
  def delete(id)
39
- puts "OK" if client.delete_offering(id)
41
+ puts "OK" if client.delete_service_offering(id: id)
40
42
  end
41
43
 
42
44
  desc 'sort', 'sort by cpu and memory grouped by domain'
43
45
  def sort
44
- offerings = client.list_service_offerings(options[:domain])
46
+ offerings = client.list_service_offerings
45
47
  sortkey = -1
46
48
  offerings.group_by{|o| o["domain"]}.each_value do |offers|
47
49
  offers.sort {
48
50
  |oa, ob| [oa["cpunumber"], oa["memory"]] <=> [ob["cpunumber"], ob["memory"]]
49
51
  }.each do |offer|
50
52
  puts "#{sortkey.abs} #{offer['domain']} - #{offer["displaytext"]}"
51
- client.update_offering({
52
- "id" => offer['id'],
53
- 'sortkey' => sortkey
54
- })
53
+ client.update_service_offering(
54
+ id: offer['id'],
55
+ sortkey: sortkey
56
+ )
55
57
  sortkey -= 1
56
58
  end
57
59
  end
58
60
  end
59
61
 
60
- end
62
+ end
@@ -1,19 +1,18 @@
1
1
  class Configuration < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list configurations'
4
- option :name
5
- option :category
6
- option :keyword
4
+ option :name, desc: "lists configuration by name"
5
+ option :category, desc: "lists configurations by category"
6
+ option :keyword, desc: "lists configuration by keyword"
7
7
  def list
8
8
  configs = client.list_configurations(options)
9
9
  if configs.size < 1
10
10
  say "No configuration found."
11
11
  else
12
- table = [%w(Name Scope Category Value)]
12
+ table = [%w(Name Category Value)]
13
13
  configs.each do |config|
14
14
  table << [
15
15
  config['name'],
16
- config['scope'],
17
16
  config['category'],
18
17
  config['value']
19
18
  ]
@@ -23,4 +22,4 @@ class Configuration < CloudstackCli::Base
23
22
  end
24
23
  end
25
24
 
26
- end
25
+ end
@@ -1,9 +1,10 @@
1
1
  class DiskOffer < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list disk offerings'
4
- option :domain
4
+ option :domain, desc: "the domain of the disk offering"
5
5
  def list
6
- offerings = client.list_disk_offerings(options[:domain])
6
+ resolve_domain
7
+ offerings = client.list_disk_offerings(options)
7
8
  if offerings.size < 1
8
9
  puts "No offerings found."
9
10
  else
@@ -20,4 +21,4 @@ class DiskOffer < CloudstackCli::Base
20
21
  say "Total number of offerings: #{offerings.size}"
21
22
  end
22
23
  end
23
- end
24
+ end
@@ -1,12 +1,12 @@
1
1
  class Domain < CloudstackCli::Base
2
2
 
3
- desc 'list [NAME]', 'list domains'
4
- def list(name = nil)
5
- domains = client.list_domains(name)
3
+ desc 'list', 'list domains'
4
+ def list
5
+ domains = client.list_domains
6
6
  if domains.size < 1
7
7
  puts "No domains found."
8
8
  else
9
- table = [["Name", "Path"]]
9
+ table = [%w(Name Path)]
10
10
  domains.each do |domain|
11
11
  table << [domain['name'], domain['path']]
12
12
  end
@@ -14,5 +14,5 @@ class Domain < CloudstackCli::Base
14
14
  say "Total number of domains: #{domains.size}"
15
15
  end
16
16
  end
17
-
18
- end
17
+
18
+ end
@@ -1,8 +1,10 @@
1
1
  class Host < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list hosts'
4
- option :zone
4
+ option :zone, desc: "lists hosts by zone"
5
+ option :type, desc: "the host type"
5
6
  def list
7
+ resolve_zone if options[:zone]
6
8
  hosts = client.list_hosts(options)
7
9
  if hosts.size < 1
8
10
  say "No hosts found."
@@ -18,4 +20,16 @@ class Host < CloudstackCli::Base
18
20
  end
19
21
  end
20
22
 
21
- end
23
+ desc 'show', 'show host details'
24
+ def show(name)
25
+ unless host = client.list_hosts(name: name).first
26
+ say "No host with name '#{name}' found."
27
+ else
28
+ table = host.map do |key, value|
29
+ [ set_color("#{key}:", :yellow), "#{value}" ]
30
+ end
31
+ print_table table
32
+ end
33
+ end
34
+
35
+ end
@@ -1,21 +1,28 @@
1
1
  class IpAddress < CloudstackCli::Base
2
2
 
3
- desc "release ID", "release public IP address"
4
- def release(id)
5
- say("OK", :green) if client.disassociate_ip_address(id)
3
+ desc "release ID [ID2 ID3]", "release public IP address by ID"
4
+ def release(*ids)
5
+ ids.each do |id|
6
+ say(" OK, released address with ID #{id}", :green) if client.disassociate_ip_address(id: id)
7
+ end
6
8
  end
7
9
 
8
10
  desc "ip_address assign NETWORK", "assign a public IP address"
9
11
  option :project
10
12
  def assign(network)
11
- project = find_project if options[:project]
12
- unless network = client.get_network(network, project ? project["id"] : nil)
13
- error "Network #{network} not found."
14
- exit 1
15
- end
16
- ip = client.associate_ip_address(network["id"])
17
- puts
18
- say ip['ipaddress']
13
+ resolve_project
14
+ options[:name] = network
15
+ unless network = client.list_networks(options).first
16
+ error "Network #{network} not found."
17
+ exit 1
18
+ end
19
+
20
+ if address = client.associate_ip_address(networkid: network["id"])
21
+ say " OK. Assigned IP address:", :green
22
+ table = [%w(ID Address Account Zone)]
23
+ table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
24
+ print_table table
25
+ end
19
26
  end
20
27
 
21
28
  desc "list", "list public IP address"
@@ -23,17 +30,19 @@ class IpAddress < CloudstackCli::Base
23
30
  option :account
24
31
  option :listall
25
32
  def list
26
- table = [["Address", "Account", "Zone"]]
33
+ resolve_account
34
+ resolve_project
27
35
  addresses = client.list_public_ip_addresses(options)
28
36
  if addresses.size < 1
29
37
  say "No ip addresses found."
30
38
  else
39
+ table = [%w(ID Address Account Zone)]
31
40
  addresses.each do |address|
32
- table << [address["ipaddress"], address["account"], address["zonename"]]
41
+ table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
33
42
  end
34
43
  print_table table
35
44
  say "Total number of addresses: #{addresses.size}"
36
45
  end
37
46
  end
38
47
 
39
- end
48
+ end
@@ -1,38 +1,40 @@
1
1
  class Iso < CloudstackCli::Base
2
2
 
3
- desc 'list [TYPE]', "list iso's by type [featured|self|self-executable|executable|community], default is featured"
3
+ desc 'list', "list iso's"
4
4
  option :project
5
5
  option :zone
6
6
  option :account
7
- option :listall
8
- def list(type='featured')
9
- project = find_project if options[:project]
10
- unless %w(featured self self-executable executable community).include?(type)
11
- say "unsupported iso type '#{type}'", :red
12
- exit 1
13
- end
14
- zone = client.get_zone(options[:zone]) if options[:zone]
15
- isos = client.list_isos(
16
- filter: type,
17
- project_id: project ? project['id'] : nil,
18
- zone_id: zone ? zone['id'] : nil
19
- )
7
+ option :type,
8
+ enum: %w(featured self self-executable executable community all)
9
+ def list
10
+ resolve_project
11
+ resolve_zone
12
+ resolve_account
13
+ options[:isofilter] = options[:type]
14
+ options.delete :type
15
+ isos = client.list_isos(options)
20
16
  if isos.size < 1
21
- puts "No iso's found"
17
+ puts "No iso's found."
22
18
  else
23
- table = [["Name", "Zone", "Bootable"]]
19
+ table = [%w(Name Zone Bootable Public Featured)]
24
20
  isos.each do |iso|
25
- table << [iso['name'], iso['zonename'], iso['bootable']]
21
+ table << [
22
+ iso['name'],
23
+ iso['zonename'],
24
+ iso['bootable'],
25
+ iso['ispublic'],
26
+ iso['isfeatured']
27
+ ]
26
28
  end
27
29
  print_table(table)
28
30
  say "Total number of isos: #{isos.size}"
29
31
  end
30
32
  end
31
33
 
32
- desc 'detach <vm-id>', "detaches any ISO file (if any) currently attached to a virtual machine"
34
+ desc 'detach VM_ID', "detaches any ISO file (if any) currently attached to a virtual machine"
33
35
  def detach(vm_id)
34
- client.detach_iso(vm_id, {async: true})
35
- say "OK", :green
36
+ client.detach_iso({virtualmachine_id: vm_id}, {sync: true})
37
+ say " OK", :green
36
38
  end
37
39
 
38
- end
40
+ end
@@ -2,13 +2,19 @@ class Job < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list async jobs'
4
4
  def list
5
- jobs = client.list_jobs()
5
+ jobs = client.list_async_jobs
6
6
  if jobs.size < 1
7
7
  say "No jobs found."
8
8
  else
9
- table = [["Command", "Created", "Status", "ID", "User ID"]]
9
+ table = [%w(Command Created Status ID User-ID)]
10
10
  jobs.each do |job|
11
- table << [job['cmd'].split('.')[-1], job['created'], job['jobstatus'], job['jobid'], job['userid']]
11
+ table << [
12
+ job['cmd'].split('.')[-1],
13
+ job['created'],
14
+ job['jobstatus'],
15
+ job['jobid'],
16
+ job['userid']
17
+ ]
12
18
  end
13
19
  print_table table
14
20
  end
@@ -16,15 +22,11 @@ class Job < CloudstackCli::Base
16
22
 
17
23
  desc 'query ID', 'query async job'
18
24
  def query(id)
19
- job = client.query_job(id)
20
- job.each do |key, value|
21
- say "#{key} : "
22
- if value.is_a?(Hash)
23
- value.each {|subkey, subvalue| say " #{subkey} : #{subvalue}"}
24
- else
25
- say(value)
26
- end
25
+ job = client.query_async_job_result(jobid: id)
26
+ table = job.map do |key, value|
27
+ [ set_color("#{key}:", :yellow), "#{value}" ]
27
28
  end
29
+ print_table table
28
30
  end
29
-
30
- end
31
+
32
+ end