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,230 +0,0 @@
1
- class Server < CloudstackCli::Base
2
-
3
- desc "list", "list servers"
4
- option :account, desc: "name of the account"
5
- option :project, desc: "name of the project"
6
- option :zone, desc: "the name of the availability zone"
7
- option :state, desc: "state of the virtual machine"
8
- option :listall, desc: "list all servers"
9
- option :storage_id, desc: "the storage ID where vm's volumes belong to"
10
- option :keyword, desc: "filter by keyword"
11
- option :command,
12
- desc: "command to execute for the given servers",
13
- enum: %w(START STOP REBOOT)
14
- option :concurrency, type: :numeric, default: 10, aliases: '-C',
15
- desc: "number of concurrent command to execute"
16
- option :format, default: "table",
17
- enum: %w(table json yaml)
18
- def list
19
- if options[:project]
20
- options[:project_id] = find_project['id']
21
- options[:project] = nil
22
- end
23
- options[:custom] = { 'storageid' => options[:storage_id] } if options[:storage_id]
24
- client.verbose = true
25
- servers = client.list_servers(options)
26
- if servers.size < 1
27
- puts "No servers found."
28
- else
29
- print_servers(servers)
30
- execute_server_commands(servers) if options[:command]
31
- end
32
- end
33
-
34
- desc "list_from_file FILE", "list servers from file"
35
- option :command,
36
- desc: "command to execute for the given servers",
37
- enum: %w(START STOP REBOOT)
38
- option :concurrency, type: :numeric, default: 10, aliases: '-C',
39
- desc: "number of concurrent command to execute"
40
- option :format, default: :table, enum: %w(table json yaml)
41
- def list_from_file(file)
42
- servers = parse_file(file)["servers"]
43
- if servers.size < 1
44
- puts "No servers found."
45
- else
46
- print_servers(servers)
47
- execute_server_commands(servers) if options[:command]
48
- end
49
- end
50
-
51
- desc "show NAME", "show detailed infos about a server"
52
- option :project
53
- def show(name)
54
- options[:project_id] = find_project['id'] if options[:project]
55
- unless server = client.get_server(name, options)
56
- puts "No server found."
57
- else
58
- table = server.map do |key, value|
59
- [ set_color("#{key}:", :yellow), "#{value}" ]
60
- end
61
- print_table table
62
- end
63
- end
64
-
65
- desc "create NAME [NAME2 ...]", "create server(s)"
66
- option :template, aliases: '-t', desc: "name of the template"
67
- option :iso, desc: "name of the iso template"
68
- option :offering, aliases: '-o', required: true, desc: "computing offering name"
69
- option :zone, aliases: '-z', required: true, desc: "availability zone name"
70
- option :networks, aliases: '-n', type: :array, desc: "network names"
71
- option :project, aliases: '-p', desc: "project name"
72
- option :port_rules, aliases: '-pr', type: :array,
73
- default: [],
74
- desc: "Port Forwarding Rules [public_ip]:port ..."
75
- option :disk_offering, desc: "disk offering (data disk for template, root disk for iso)"
76
- option :disk_size, desc: "disk size in GB"
77
- option :hypervisor, desc: "only used for iso deployments, default: vmware"
78
- option :keypair, desc: "the name of the ssh keypair to use"
79
- option :group, desc: "group name"
80
- option :account, desc: "account name"
81
- def create(*names)
82
- projectid = find_project['id'] if options[:project]
83
- say "Start deploying servers...", :green
84
- jobs = names.map do |name|
85
- server = client(quiet: true).get_server(name, project_id: projectid)
86
- if server
87
- say "Server #{name} (#{server["state"]}) already exists.", :yellow
88
- job = {
89
- id: 0,
90
- name: "Create server #{name}",
91
- status: 1
92
- }
93
- else
94
- job = {
95
- id: client.create_server(options.merge({name: name, sync: true}))['jobid'],
96
- name: "Create server #{name}"
97
- }
98
- end
99
- job
100
- end
101
- watch_jobs(jobs)
102
- if options[:port_rules].size > 0
103
- say "Create port forwarding rules...", :green
104
- jobs = []
105
- names.each do |name|
106
- server = client(quiet: true).get_server(name, project_id: projectid)
107
- create_port_rules(server, options[:port_rules], false).each_with_index do |job_id, index|
108
- jobs << {
109
- id: job_id,
110
- name: "Create port forwarding ##{index + 1} rules for server #{server['name']}"
111
- }
112
- end
113
- end
114
- watch_jobs(jobs)
115
- end
116
- say "Finished.", :green
117
- end
118
-
119
- desc "destroy NAME [NAME2 ..]", "destroy server(s)"
120
- option :project
121
- option :force, desc: "destroy without asking", type: :boolean, aliases: '-f'
122
- option :expunge, desc: "expunge server immediately", type: :boolean, default: false, aliases: '-E'
123
- def destroy(*names)
124
- projectid = find_project['id'] if options[:project]
125
- names.each do |name|
126
- server = client.get_server(name, project_id: projectid)
127
- unless server
128
- say "Server #{name} not found.", :red
129
- else
130
- ask = "Destroy #{name} (#{server['state']})? [y/N]:"
131
- if options[:force] || yes?(ask, :yellow)
132
- say "destroying #{name} "
133
- client.destroy_server(
134
- server["id"], {
135
- sync: false,
136
- expunge: options[:expunge]
137
- }
138
- )
139
- puts
140
- end
141
- end
142
- end
143
- end
144
-
145
- desc "bootstrap", "interactive creation of a server with network access"
146
- def bootstrap
147
- bootstrap_server_interactive
148
- end
149
-
150
- desc "stop NAME", "stop a server"
151
- option :project
152
- option :account
153
- option :force
154
- def stop(name)
155
- options[:project_id] = find_project['id'] if options[:project]
156
- exit unless options[:force] || yes?("Stop server #{name}? [y/N]:", :magenta)
157
- client.stop_server(name, options)
158
- puts
159
- end
160
-
161
- desc "start NAME", "start a server"
162
- option :project
163
- option :account
164
- def start(name)
165
- options[:project_id] = find_project['id'] if options[:project]
166
- say("Starting server #{name}", :magenta)
167
- client.start_server(name, options)
168
- puts
169
- end
170
-
171
- desc "reboot NAME", "reboot a server"
172
- option :project
173
- option :account
174
- option :force
175
- def reboot(name)
176
- options[:project_id] = find_project['id'] if options[:project]
177
- exit unless options[:force] || yes?("Reboot server #{name}? [y/N]:", :magenta)
178
- client.reboot_server(name, options)
179
- puts
180
- end
181
-
182
- no_commands do
183
-
184
- def print_servers(servers)
185
- case options[:format].to_sym
186
- when :yaml
187
- puts({'servers' => servers}.to_yaml)
188
- when :json
189
- say JSON.pretty_generate(servers: servers)
190
- else
191
- table = [["Name", "State", "Offering", "Zone", options[:project_id] ? "Project" : "Account", "IP's"]]
192
- servers.each do |server|
193
- table << [
194
- server['name'],
195
- server['state'],
196
- server['serviceofferingname'],
197
- server['zonename'],
198
- options[:project_id] ? server['project'] : server['account'],
199
- server['nic'].map { |nic| nic['ipaddress']}.join(' ')
200
- ]
201
- end
202
- print_table table
203
- say "Total number of servers: #{servers.count}"
204
- end
205
- end
206
-
207
- def execute_server_commands(servers)
208
- command = options[:command].downcase
209
- unless %w(start stop reboot).include?(command)
210
- say "\nCommand #{options[:command]} not supported.", :red
211
- exit 1
212
- end
213
- exit unless yes?("\n#{command.capitalize} the server(s) above? [y/N]:", :magenta)
214
- servers.each_slice(options[:concurrency]) do | batch |
215
- jobs = batch.map do |server|
216
- args = { sync: true, account: server['account'] }
217
- args[:project_id] = server['projectid'] if server['projectid']
218
- {
219
- id: client.send("#{command}_server", server['name'], args)['jobid'],
220
- name: "#{command.capitalize} server #{server['name']}"
221
- }
222
- end
223
- puts
224
- watch_jobs(jobs)
225
- end
226
- end
227
-
228
- end # no_commands
229
-
230
- end