cloudstack-cli 0.15.1 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,18 +1,22 @@
1
1
  class LoadBalancer < CloudstackCli::Base
2
-
2
+
3
3
  desc "list", "list load balancer rules"
4
4
  option :project
5
5
  def list
6
- project = find_project if options[:project]
7
- rules = client.list_load_balancer_rules(
8
- { project_name: project ? project['name'] : nil }
9
- )
6
+ resolve_project
7
+ rules = client.list_load_balancer_rules(options)
10
8
  if rules.size < 1
11
9
  puts "No load balancer rules found."
12
10
  else
13
- table = [["Name", "Public-IP", "Public-Port"]]
11
+ table = [%w(Name Public-IP Public-Port Private-Port Algorithm)]
14
12
  rules.each do |rule|
15
- table << [rule['name'], rule['publicip'], rule['publicport']]
13
+ table << [
14
+ rule['name'],
15
+ rule['publicip'],
16
+ rule['publicport'],
17
+ rule['privateport'],
18
+ rule['algorithm']
19
+ ]
16
20
  end
17
21
  print_table table
18
22
  say "Total number of rules: #{rules.count}"
@@ -24,31 +28,65 @@ class LoadBalancer < CloudstackCli::Base
24
28
  option :ip, required: true
25
29
  option :public_port, required: true
26
30
  option :private_port
31
+ option :algorithm,
32
+ enum: %w(source roundrobin leastconn),
33
+ default: "roundrobin"
34
+ option :open_firewall, type: :boolean
35
+ option :cidr_list
36
+ option :protocol
27
37
  def create(name)
28
- project = find_project
38
+ resolve_project
39
+ ip_options = {ip_address: options[:ip]}
40
+ ip_options[:project_id] = options[:project_id] if options[:project_id]
41
+ unless ip = client.list_public_ip_addresses(ip_options).first
42
+ say "Error: IP #{options[:ip]} not found.", :red
43
+ exit 1
44
+ end
29
45
  options[:private_port] = options[:public_port] if options[:private_port] == nil
46
+ options[:name] = name
47
+ options[:publicip_id] = ip['id']
30
48
  say "Create rule #{name}...", :yellow
31
- rule = client.create_load_balancer_rule(
32
- name,
33
- options[:ip],
34
- options[:private_port],
35
- options[:public_port],
36
- )
37
- say "OK!", :green
49
+ rule = client.create_load_balancer_rule(options)
50
+ say " OK!", :green
38
51
  end
39
52
 
40
- desc "add NAME", "assign servers to balancer rule"
41
- option :servers, required: true, type: :array, desc: 'server names'
53
+ desc "add LB-NAME", "assign servers to balancer rule"
54
+ option :servers,
55
+ required: true,
56
+ type: :array,
57
+ desc: "server names"
58
+ option :project
42
59
  def add(name)
43
- say "Add #{names.join(', ')} to rule #{id}...", :yellow
44
- rule = client.assign_to_load_balancer_rule(
45
- name,
46
- options[:servers],
60
+ resolve_project
61
+ default_args = options.dup
62
+ default_args.delete(:servers)
63
+
64
+ servers = options[:servers].map do |server|
65
+ client.list_virtual_machines(default_args.merge(name: server)).first
66
+ end.compact
67
+
68
+ unless servers.size > 0
69
+ say "No servers found with the following name(s): #{options[:servers].join(', ')}", :yellow
70
+ exit 1
71
+ end
72
+
73
+ unless rule = client.list_load_balancer_rules(default_args.merge(name: name)).first
74
+ say "Error: LB rule with name #{name} not found.", :red
75
+ exit 1
76
+ end
77
+
78
+ say "Add #{servers.map{|s| s['name']}.join(', ')} to rule #{name} ", :yellow
79
+ lb = client.assign_to_load_balancer_rule(
80
+ {
81
+ id: rule['id'],
82
+ virtualmachine_ids: servers.map{|s| s['id']}.join(',')
83
+ }.merge(default_args)
47
84
  )
48
- if rule['success']
49
- say "OK!", :green
85
+
86
+ if lb['success']
87
+ say " OK.", :green
50
88
  else
51
- say "Failed!", :red
89
+ say " Failed.", :red
52
90
  end
53
91
  end
54
- end
92
+ end
@@ -3,37 +3,19 @@ class Network < CloudstackCli::Base
3
3
  desc "list", "list networks"
4
4
  option :project, desc: 'the project name of the network'
5
5
  option :account, desc: 'the owner of the network'
6
- option :zone, desc: 'typehe name of the zone the network belongs to'
6
+ option :zone, desc: 'the name of the zone the network belongs to'
7
7
  option :type, desc: 'the type of the network'
8
8
  option :showid, type: :boolean, desc: 'show the network id'
9
9
  option :showvlan, type: :boolean, desc: 'show the VLAN'
10
10
  def list
11
- project = find_project if options[:project]
12
- if options[:zone]
13
- unless zone = client.get_zone(options[:zone])
14
- say "Zone '#{options[:zone]}' not found.", :red
15
- exit 1
16
- end
17
- zone_id = zone['id']
18
- end
19
-
20
- networks = []
21
- if project
22
- networks = client.list_networks(project_id: project['id'], zone_id: zone_id)
23
- elsif options[:account]
24
- networks = client.list_networks(account: options[:account], zone_id: zone_id)
25
- else
26
- networks = client.list_networks(zone_id: zone_id)
27
- networks += client.list_networks(project_id: -1, zone_id: zone_id)
28
- end
29
-
30
- if options[:type]
31
- networks = filter_by(networks, 'type', options[:type])
32
- end
11
+ resolve_zone if options[:zone]
12
+ resolve_project
13
+ networks = client.list_networks(options)
33
14
 
34
15
  if networks.size < 1
35
16
  puts "No networks found."
36
17
  else
18
+ networks = filter_by(networks, 'type', options[:type]) if options[:type]
37
19
  table = [%w(Name Displaytext Account/Project Zone Domain State Type Offering)]
38
20
  table[0] << "ID" if options[:showid]
39
21
  table[0] << "VLAN" if options[:showvlan]
@@ -56,72 +38,45 @@ class Network < CloudstackCli::Base
56
38
  end
57
39
  end
58
40
 
59
- desc "default", "get the default network"
60
- option :zone
61
- def default
62
- network = client.get_default_network(options[:zone])
63
- unless network
64
- puts "No default network found."
65
- else
66
- table = [["Name", "Displaytext", "Domain", "Zone"]]
67
- table[0] << "ID" if options[:showid]
68
- table << [
69
- network["name"],
70
- network["displaytext"],
71
- network["domain"],
72
- network["zonename"]
73
- ]
74
- table[-1] << network["id"] if options[:showid]
75
- print_table table
76
- end
77
- end
78
-
79
41
  desc "show NAME", "show detailed infos about a network"
80
42
  option :project
81
43
  def show(name)
82
- if options[:project]
83
- if options[:project].downcase == "all"
84
- options[:project_id] = -1
85
- else
86
- project = find_project
87
- options[:project_id] = project['id']
88
- end
44
+ resolve_project
45
+ unless network = client.list_networks(options).find {|n| n['name'] == name}
46
+ say "Error: No network with name '#{name}' found.", :red
47
+ exit
89
48
  end
90
- unless server = client.get_network(name, options[:project_id])
91
- puts "No network found."
92
- else
93
- table = server.map do |key, value|
94
- [ set_color("#{key}:", :yellow), "#{value}" ]
95
- end
96
- print_table table
49
+ table = network.map do |key, value|
50
+ [ set_color("#{key}:", :yellow), "#{value}" ]
97
51
  end
52
+ print_table table
98
53
  end
99
54
 
100
55
  desc "restart NAME", "restart network"
101
- option :cleanup, type: :boolean, default: true
56
+ option :cleanup, type: :boolean, default: false
57
+ option :project
102
58
  def restart(name)
103
- network = client.get_network(name)
104
- network = client.get_network(name, -1) unless network
105
- unless network
106
- say "Network #{name} not found."
59
+ resolve_project
60
+ unless network = client.list_networks(options).find {|n| n['name'] == name}
61
+ say "Network with name '#{name}' not found."
107
62
  exit 1
108
63
  end
109
64
  if yes? "Restart network \"#{network['name']}\" (cleanup=#{options[:cleanup]})?"
110
- p client.restart_network(network['id'], options[:cleanup])
65
+ client.restart_network(id: network['id'], cleanup: options[:cleanup])
111
66
  end
112
67
  end
113
68
 
114
69
  desc "delete NAME", "delete network"
70
+ option :project
115
71
  def delete(name)
116
- network = client.get_network(name)
117
- network = client.get_network(name, -1) unless network
118
- unless network
119
- say "Network \"#{name}\" not found."
72
+ resolve_project
73
+ unless network = client.list_networks(options).find {|n| n['name'] == name}
74
+ say "Error: Network with name '#{name}' not found.", :red
120
75
  exit 1
121
76
  end
122
- if yes? "Destroy network \"#{network['name']}\"?"
123
- p client.delete_network(network['id'])
77
+ if yes? "Delete network \"#{network['name']}\"?"
78
+ client.delete_network(id: network['id'])
124
79
  end
125
80
  end
126
81
 
127
- end
82
+ end
@@ -3,8 +3,8 @@ class PhysicalNetwork < CloudstackCli::Base
3
3
  desc "list", "list physical networks"
4
4
  option :project
5
5
  def list
6
- project = find_project if options[:project]
7
- networks = client.list_physical_networks
6
+ resolve_project
7
+ networks = client.list_physical_networks(options)
8
8
  zones = client.list_zones
9
9
  if networks.size < 1
10
10
  puts "No networks found"
@@ -14,7 +14,7 @@ class PhysicalNetwork < CloudstackCli::Base
14
14
  table << [
15
15
  network["name"],
16
16
  network["state"],
17
- zones.select{|zone| zone['id'] == network["zoneid"]}.first["name"],
17
+ zones.select{|zone| zone['id'] == network["zoneid"]}.first["name"],
18
18
  network["id"]
19
19
  ]
20
20
  end
@@ -23,4 +23,4 @@ class PhysicalNetwork < CloudstackCli::Base
23
23
  end
24
24
  end
25
25
 
26
- end
26
+ end
@@ -1,7 +1,9 @@
1
1
  class Pod < CloudstackCli::Base
2
2
 
3
3
  desc 'list', 'list pods'
4
+ option :zone
4
5
  def list
6
+ resolve_zone
5
7
  pods = client.list_pods(options)
6
8
  if pods.size < 1
7
9
  say "No pods found."
@@ -18,4 +20,4 @@ class Pod < CloudstackCli::Base
18
20
  end
19
21
  end
20
22
 
21
- end
23
+ end
@@ -1,6 +1,6 @@
1
1
  class PortRule < CloudstackCli::Base
2
2
 
3
- desc "create SERVER", "create portforwarding rules for a given server"
3
+ desc "create VM-NAME", "create portforwarding rules for a given VM"
4
4
  option :rules, type: :array,
5
5
  required: true,
6
6
  desc: "Port Forwarding Rules [public_ip]:port ...",
@@ -9,38 +9,44 @@ class PortRule < CloudstackCli::Base
9
9
  option :project
10
10
  option :keyword, desc: "list by keyword"
11
11
  def create(server_name)
12
- projectid = find_project['id'] if options[:project]
13
- unless server = client.get_server(server_name, projectid)
12
+ resolve_project
13
+ unless server = client.list_virtual_machines(name: server_name, project_id: options[:project_id]).first
14
14
  error "Server #{server_name} not found."
15
15
  exit 1
16
16
  end
17
- frontendip = nil
18
17
  options[:rules].each do |pf_rule|
19
18
  ip = pf_rule.split(":")[0]
20
- if ip != ''
21
- ip_addr = client.get_public_ip_address(ip, projectid)
22
- unless ip_addr
23
- say "Error: IP #{ip} not found.", :red
19
+ unless ip == ''
20
+ unless ip_addr = client.list_public_ip_addresses(ipaddress: ip, project_id: options[:project_id]).first
21
+ say "Error: IP #{ip} not found.", :yellow
24
22
  next
25
23
  end
26
24
  else
27
- ip_addr = frontendip ||= client.associate_ip_address(
28
- client.get_network(options[:network], projectid)
25
+ say "Assign a new IP address ", :yellow
26
+ say(" OK", :green) if ip_addr = client.associate_ip_address(
27
+ networkid: client.list_networks(
28
+ project_id: options[:project_id]
29
+ ).find {|n| n['name'] == options[:network]}['id'],
30
+ project_id: options[:project_id]
29
31
  )
30
32
  end
31
33
  port = pf_rule.split(":")[1]
32
- puts
33
- say "Create port forwarding rule #{ip_addr["ipaddress"]}:#{port} for server #{server_name}.", :yellow
34
- client.create_port_forwarding_rule(ip_addr["id"], port, 'TCP', port, server["id"])
35
- puts
34
+ say "Create port forwarding rule #{ip_addr["ipaddress"]}:#{port} for server #{server_name} ", :yellow
35
+ say(" OK.", :green) if client.create_port_forwarding_rule(
36
+ ipaddress_id: ip_addr["id"],
37
+ public_port: port,
38
+ private_port: port,
39
+ virtualmachine_id: server["id"],
40
+ protocol: "TCP"
41
+ )
36
42
  end
37
43
  end
38
44
 
39
45
  desc "list", "list portforwarding rules"
40
46
  option :project
41
47
  def list
42
- project_id = find_project['id'] if options[:project]
43
- rules = client.list_port_forwarding_rules(ip_address_id=nil, project_id)
48
+ resolve_project
49
+ rules = client.list_port_forwarding_rules(options)
44
50
  if rules.size < 1
45
51
  puts "No rules found."
46
52
  else
@@ -69,4 +75,4 @@ class PortRule < CloudstackCli::Base
69
75
  end
70
76
  end
71
77
  end
72
- end
78
+ end
@@ -2,8 +2,8 @@ class Project < CloudstackCli::Base
2
2
 
3
3
  desc "show NAME", "show detailed infos about a project"
4
4
  def show(name)
5
- unless project = client.get_project(name)
6
- puts "No project with name #{name} found."
5
+ unless project = client.list_projects(name: name, listall: true).first
6
+ say "Error: No project with name '#{name}' found.", :red
7
7
  else
8
8
  table = project.map do |key, value|
9
9
  [ set_color("#{key}", :yellow), "#{value}" ]
@@ -14,7 +14,7 @@ class Project < CloudstackCli::Base
14
14
 
15
15
  desc "list", "list projects"
16
16
  def list
17
- projects = client.list_projects
17
+ projects = client.list_projects(listall: true)
18
18
  if projects.size < 1
19
19
  puts "No projects found."
20
20
  else
@@ -29,25 +29,24 @@ class Project < CloudstackCli::Base
29
29
 
30
30
  desc "list_accounts PROJECT_NAME", "show accounts belonging to a project"
31
31
  def list_accounts(name)
32
- unless project = client.get_project(name)
33
- say "No project with name #{name} found."
32
+ unless project = client.list_projects(name: name, listall: true).first
33
+ say "Error: No project with name '#{name}' found.", :red
34
34
  else
35
- accounts = client.list_project_accounts(project['id'], options)
35
+ accounts = client.list_project_accounts(project_id: project['id'])
36
36
  if accounts.size < 1
37
37
  say "No project accounts found."
38
38
  else
39
- table = [%w(Name Type Domain State)]
39
+ table = [%w(Account-Name Account-Type Role Domain)]
40
40
  accounts.each do |account|
41
41
  table << [
42
- account['name'],
43
- TYPES[account['accounttype']],
44
- account['domain'],
45
- account['state']
42
+ account['account'],
43
+ Account::TYPES[account['accounttype']],
44
+ account['role'],
45
+ account['domain']
46
46
  ]
47
47
  end
48
48
  print_table table
49
49
  say "Total number of project accounts: #{accounts.size}"
50
- print_table table
51
50
  end
52
51
  end
53
52
  end
@@ -19,6 +19,8 @@ class ResourceLimit < CloudstackCli::Base
19
19
  option :project
20
20
  option :type, desc: "specify type, see types for a list of types"
21
21
  def list
22
+ resolve_account
23
+ resolve_project
22
24
  limits = client.list_resource_limits(options)
23
25
  table = []
24
26
  header = options[:project] ? ["Project"] : ["Account"]
@@ -42,7 +44,9 @@ class ResourceLimit < CloudstackCli::Base
42
44
  option :project, desc: "refresh resource for a specified project"
43
45
  option :type, desc: "specify type, see types for a list of types"
44
46
  def refresh
45
- set_domain_id if options[:domain]
47
+ resolve_domain
48
+ resolve_account
49
+ resolve_project
46
50
  options[:resource_type] = options[:type] if options[:type]
47
51
 
48
52
  unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
@@ -69,7 +73,9 @@ class ResourceLimit < CloudstackCli::Base
69
73
  desc: "Maximum resource limit.",
70
74
  required: true
71
75
  def update
72
- set_domain_id if options[:domain]
76
+ resolve_domain
77
+ resolve_account
78
+ resolve_project
73
79
  options[:resource_type] = options[:type]
74
80
 
75
81
  unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
@@ -106,16 +112,6 @@ class ResourceLimit < CloudstackCli::Base
106
112
  value.to_s
107
113
  end
108
114
 
109
- def set_domain_id
110
- domains = client.list_domains(options[:domain])
111
- if domains.size < 1
112
- say "Domain #{options[:domain]} not found.", :red
113
- exit -1
114
- else
115
- options[:domain_id] = domains.first['id']
116
- end
117
- end
118
-
119
115
  end
120
116
 
121
117
  end
@@ -7,35 +7,26 @@ class Router < CloudstackCli::Base
7
7
  option :status, desc: "the status of the router"
8
8
  option :redundant_state, desc: "the state of redundant virtual router",
9
9
  enum: %w(master backup fault unknown)
10
- option :listall, type: :boolean, desc: "list all routers"
10
+ option :listall, type: :boolean, desc: "list all routers", default: true
11
11
  option :showid, type: :boolean, desc: "display the router ID"
12
- option :reverse, type: :boolean, default: false, desc: "reverse listing of routers"
12
+ option :reverse, type: :boolean, default: false, desc: "reverse listing of routers"
13
13
  option :command,
14
14
  desc: "command to execute for each router",
15
15
  enum: %w(START STOP REBOOT)
16
- option :concurrency, type: :numeric, default: 10, aliases: '-C',
17
- desc: "number of concurrent command to execute"
16
+ option :concurrency, type: :numeric, default: 10, aliases: '-C',
17
+ desc: "number of concurrent command to execute"
18
18
  def list
19
- projectid = find_project['id'] if options[:project]
20
- routers = client.list_routers(
21
- {
22
- account: options[:account],
23
- projectid: projectid,
24
- status: options[:status],
25
- zone: options[:zone]
26
- }
27
- )
19
+ resolve_project
20
+ resolve_zone
21
+ resolve_account
22
+
23
+ routers = client.list_routers(options)
28
24
 
29
25
  if options[:listall]
30
26
  projects = client.list_projects
31
27
  projects.each do |project|
32
28
  routers = routers + client.list_routers(
33
- {
34
- account: options[:account],
35
- projectid: project['id'],
36
- status: options[:status],
37
- zone: options[:zone]
38
- }
29
+ options.merge(projectid: project['id'])
39
30
  )
40
31
  end
41
32
  end
@@ -54,69 +45,69 @@ class Router < CloudstackCli::Base
54
45
  exit 1
55
46
  end
56
47
  exit unless yes?("\n#{command.capitalize} the router(s) above? [y/N]:", :magenta)
57
- routers.each_slice(options[:concurrency]) do | batch |
58
- jobs = batch.map do |router|
59
- {id: client.send("#{command}_router", router['id'], async: false)['jobid'], name: "#{command.capitalize} router #{router['name']}"}
60
- end
61
- puts
62
- watch_jobs(jobs)
63
- end
48
+ routers.each_slice(options[:concurrency]) do | batch |
49
+ jobs = batch.map do |router|
50
+ {id: client.send("#{command}_router", router['id'], async: false)['jobid'], name: "#{command.capitalize} router #{router['name']}"}
51
+ end
52
+ puts
53
+ watch_jobs(jobs)
54
+ end
64
55
  end
65
56
  end
66
57
 
67
58
  desc "stop NAME [NAME2 ..]", "stop virtual router(s)"
68
- option :force, desc: "stop without asking", type: :boolean, aliases: '-f'
59
+ option :force, desc: "stop without confirmation", type: :boolean, aliases: '-f'
69
60
  def stop(*names)
70
61
  routers = names.map {|name| get_router(name)}
71
62
  print_routers(routers)
72
63
  exit unless options[:force] || yes?("\nStop router(s) above? [y/N]:", :magenta)
73
64
  jobs = routers.map do |router|
74
- {id: client.stop_router(router['id'], async: false)['jobid'], name: "Stop router #{router['name']}"}
65
+ {id: client.stop_router({id: router['id']}, {sync: true})['jobid'], name: "Stop router #{router['name']}"}
75
66
  end
76
67
  puts
77
68
  watch_jobs(jobs)
78
69
  end
79
70
 
80
71
  desc "start NAME [NAME2 ..]", "start virtual router(s)"
81
- option :force, desc: "start without asking", type: :boolean, aliases: '-f'
72
+ option :force, desc: "start without confirmation", type: :boolean, aliases: '-f'
82
73
  def start(*names)
83
74
  routers = names.map {|name| get_router(name)}
84
75
  print_routers(routers)
85
76
  exit unless options[:force] || yes?("\nStart router(s) above? [y/N]:", :magenta)
86
77
  jobs = routers.map do |router|
87
- {id: client.start_router(router['id'], async: false)['jobid'], name: "Start router #{router['name']}"}
78
+ {id: client.start_router({id: router['id']}, {sync: true})['jobid'], name: "Start router #{router['name']}"}
88
79
  end
89
80
  puts
90
81
  watch_jobs(jobs)
91
82
  end
92
83
 
93
84
  desc "reboot NAME [NAME2 ..]", "reboot virtual router(s)"
94
- option :force, desc: "start without asking", type: :boolean, aliases: '-f'
85
+ option :force, desc: "start without confirmation", type: :boolean, aliases: '-f'
95
86
  def reboot(*names)
96
- routers = names.map {|name| get_router(name)}
87
+ routers = names.map {|name| client.list_routers(name: name).first}
97
88
  print_routers(routers)
98
89
  exit unless options[:force] || yes?("\nReboot router(s) above? [y/N]:", :magenta)
99
90
  jobs = routers.map do |router|
100
- {id: client.reboot_router(router['id'], async: false)['jobid'], name: "Reboot router #{router['name']}"}
91
+ {id: client.reboot_router({id: router['id']}, {sync: true})['jobid'], name: "Reboot router #{router['name']}"}
101
92
  end
102
93
  puts
103
94
  watch_jobs(jobs)
104
95
  end
105
96
 
106
- desc "restart NAME [NAME2 ..]", "restart virtual router(s) (stop and start)"
107
- option :force, desc: "restart without asking", type: :boolean, aliases: '-f'
108
- def restart(*names)
97
+ desc "stop_start NAME [NAME2 ..]", "stops and starts virtual router(s)"
98
+ option :force, desc: "stop_start without confirmation", type: :boolean, aliases: '-f'
99
+ def stop_start(*names)
109
100
  routers = names.map {|name| get_router(name)}
110
101
  print_routers(routers)
111
102
  exit unless options[:force] || yes?("\nRestart router(s) above? [y/N]:", :magenta)
112
103
  jobs = routers.map do |router|
113
- {id: client.stop_router(router['id'], async: false)['jobid'], name: "Stop router #{router['name']}"}
104
+ {id: client.stop_router({id: router['id']}, {sync: true})['jobid'], name: "Stop router #{router['name']}"}
114
105
  end
115
106
  puts
116
107
  watch_jobs(jobs)
117
108
 
118
109
  jobs = routers.map do |router|
119
- {id: client.start_router(router['id'], async: false)['jobid'], name: "Start router #{router['name']}"}
110
+ {id: client.start_router({id: router['id']}, {sync: true})['jobid'], name: "Start router #{router['name']}"}
120
111
  end
121
112
  puts
122
113
  watch_jobs(jobs)
@@ -131,7 +122,7 @@ class Router < CloudstackCli::Base
131
122
  print_routers(routers)
132
123
  exit unless options[:force] || yes?("\nDestroy router(s) above? [y/N]:", :magenta)
133
124
  jobs = routers.map do |router|
134
- {id: client.destroy_router(router['id'], async: false)['jobid'], name: "Destroy router #{router['name']}"}
125
+ {id: client.destroy_router({id: router['id']}, {sync: true})['jobid'], name: "Destroy router #{router['name']}"}
135
126
  end
136
127
  puts
137
128
  watch_jobs(jobs)
@@ -140,8 +131,8 @@ class Router < CloudstackCli::Base
140
131
  no_commands do
141
132
 
142
133
  def get_router(name)
143
- unless router = client.get_router(name)
144
- unless router = client.get_router(name, -1)
134
+ unless router = client.list_routers(name: name, listall: true).first
135
+ unless router = client.list_routers(name: name, project_id: -1).first
145
136
  say "Can't find router with name #{name}.", :red
146
137
  exit 1
147
138
  end
@@ -154,7 +145,7 @@ class Router < CloudstackCli::Base
154
145
  say "No routers found."
155
146
  else
156
147
  table = [[
157
- 'Name', 'Zone', 'Account', 'Project', 'Redundant-State', 'IP', 'Linklocal IP', 'Status', 'Redundant', 'ID'
148
+ 'Name', 'Zone', 'Account', 'Project', 'Redundant-State', 'IP', 'Linklocal IP', 'Status', 'Redundant', 'OfferingID', 'Offering', 'ID'
158
149
  ]]
159
150
  table[0].delete('ID') unless options[:showid]
160
151
  routers.each do |router|
@@ -168,6 +159,8 @@ class Router < CloudstackCli::Base
168
159
  router["linklocalip"],
169
160
  router["state"],
170
161
  router["isredundantrouter"],
162
+ router["serviceofferingid"],
163
+ router["serviceofferingname"],
171
164
  router["id"]
172
165
  ]
173
166
  table[-1].delete_at(-1) unless table[0].index "ID"
@@ -4,8 +4,11 @@ class Snapshot < CloudstackCli::Base
4
4
  option :account
5
5
  option :project
6
6
  option :domain
7
- option :listall
7
+ option :listall, default: true
8
8
  def list
9
+ resolve_account
10
+ resolve_project
11
+ resolve_domain
9
12
  snapshots = client.list_snapshots(options)
10
13
  if snapshots.size < 1
11
14
  say "No snapshots found."
@@ -22,4 +25,4 @@ class Snapshot < CloudstackCli::Base
22
25
  end
23
26
  end
24
27
 
25
- end
28
+ end