knife-ovmcli 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd4ff98527b955b67add9fc80e2a32ee4d4a6976
4
+ data.tar.gz: dbfd4153b048926fa3b33d5cc13d566dec27878c
5
+ SHA512:
6
+ metadata.gz: d0c9bf631443ed356fd5e9d566a63fb64c9967c88c3cfcb2b1a4ef964d1550c1e7d669900139eb937e9ab771243344496323968429d2c19db63c9e1621a38bbe
7
+ data.tar.gz: 46eecc680fda0331fe7f65b7420150b5801098fefe54d4264efa0b3baa6d6379a70cf000074e0febe0296248ef3db74c66eacf7cfe1f4c44ae173088750a583f
@@ -0,0 +1,536 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Contributor::
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+
9
+ # Base class for OvmCli knife commands
10
+ class Chef
11
+ class Knife
12
+ class BaseOraclevmCommand < Knife
13
+
14
+ deps do
15
+ require 'chef/knife/bootstrap'
16
+ Chef::Knife::Bootstrap.load_deps
17
+ require 'fog'
18
+ require 'socket'
19
+ require 'net/ssh'
20
+ require 'readline'
21
+ require 'chef/json_compat'
22
+ end
23
+
24
+ def self.get_common_options
25
+ unless defined? $default
26
+ $default = Hash.new
27
+ end
28
+
29
+ option :ovmmgr_user,
30
+ :short => "-u USERNAME",
31
+ :long => "--ovmmgruser USERNAME",
32
+ :description => "The username for OracleVM Manager"
33
+ $default[:ovmmgr_user] = "admin"
34
+
35
+ option :ovmmgr_pass,
36
+ :short => "-p PASSWORD",
37
+ :long => "--ovmmgrpass PASSWORD",
38
+ :description => "The password for OracleVM Manager"
39
+
40
+ option :ovmmgr_host,
41
+ :long => "--ovmmgrhost HOST",
42
+ :description => "The OracleVM Manager host"
43
+
44
+ option :ovmmgr_port,
45
+ :long => "--ovmmgrport PORT",
46
+ :description => "The OracleVM Manager CLI port number to use"
47
+ $default[:ovmmgr_port] = 10000
48
+ end
49
+
50
+ def get_config(key)
51
+ key = key.to_sym
52
+ rval = config[key] || Chef::Config[:knife][key] || $default[key]
53
+ Chef::Log.debug("value for config item #{key}: #{rval}")
54
+ rval
55
+ end
56
+
57
+ def get_cli_connection
58
+
59
+ conn_opts = {
60
+ :host => get_config(:ovmmgr_host),
61
+ :path => get_config(:ovmmgr_path),
62
+ :port => get_config(:ovmmgr_port),
63
+ :user => get_config(:ovmmgr_user),
64
+ :password => get_config(:ovmmgr_pass),
65
+ }
66
+
67
+ # Grab the ovmmgr host from the command line
68
+ # if tt is not in the config file
69
+ if not conn_opts[:host]
70
+ conn_opts[:host] = get_host
71
+ end
72
+ # Grab the password from the command line
73
+ # if tt is not in the config file
74
+ if not conn_opts[:password]
75
+ conn_opts[:password] = get_password
76
+ end
77
+ if conn_opts[:port]
78
+ Chef::Log.debug("Waiting for port #{conn_opts[:port]} on #{conn_opts[:host]}...")
79
+ tcp_test_port(conn_opts[:host],conn_opts[:port])
80
+ end
81
+ return conn_opts
82
+ end
83
+
84
+ def get_host
85
+ @host ||= ui.ask("Enter your OVM Mgr Host: ") { |q| q.echo = true }
86
+ end
87
+
88
+ def get_password
89
+ @password ||= ui.ask("Enter your password: ") { |q| q.echo = false }
90
+ end
91
+
92
+ def get_vm(vmname)
93
+ return retval
94
+ end
95
+
96
+
97
+ def fatal_exit(msg)
98
+ ui.fatal(msg)
99
+ exit 1
100
+ end
101
+
102
+ def tcp_test_port(hostname,port)
103
+ tcp_socket = TCPSocket.new(hostname, port)
104
+ readable = IO.select([tcp_socket], nil, nil, 5)
105
+ if readable
106
+ Chef::Log.debug("accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
107
+ true
108
+ else
109
+ false
110
+ end
111
+ rescue Errno::ETIMEDOUT
112
+ false
113
+ rescue Errno::EPERM
114
+ false
115
+ rescue Errno::ECONNREFUSED
116
+ sleep 2
117
+ false
118
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH
119
+ sleep 2
120
+ false
121
+ ensure
122
+ tcp_socket && tcp_socket.close
123
+ end
124
+
125
+ #
126
+ # show_vm_status, given a vmname return the operational status of the vm
127
+ #
128
+ def show_vm_status(vmname)
129
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
130
+
131
+ conn_opts=get_cli_connection
132
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
133
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
134
+ output = ssh.exec!("show vm name=#{vmname}")
135
+ output.each_line do |line|
136
+ if line.match(/Status:/)
137
+ current[:status]=line.split[1].strip
138
+ elsif line.match(/Time:/)
139
+ line["Time: "]=""
140
+ current[:time]=line.strip
141
+ elsif line.match(/ Status = /)
142
+ current[:vmstatus]=line.split('=')[1].strip
143
+ elsif line.match(/Error Msg:/)
144
+ line["Error Msg: "]=""
145
+ current[:errormsg]=line.strip
146
+ end
147
+ end
148
+ end
149
+ return current
150
+ end
151
+
152
+ #
153
+ # start_vm, given a vmname issue a start request
154
+ #
155
+ def start_vm(vmname)
156
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
157
+
158
+ conn_opts=get_cli_connection
159
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
160
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
161
+ output = ssh.exec!("start vm name=#{vmname}")
162
+ output.each_line do |line|
163
+ if line.match(/Status:/)
164
+ current[:status]=line.split[1].strip
165
+ elsif line.match(/Time:/)
166
+ line["Time: "]=""
167
+ current[:time]=line.strip
168
+ elsif line.match(/Error Msg:/)
169
+ line["Error Msg: "]=""
170
+ current[:errormsg]=line.strip
171
+ end
172
+ end
173
+ end
174
+ return current
175
+ end
176
+ #
177
+ # stop_vm, given a vmname issue a stop request
178
+ #
179
+ def stop_vm(vmname)
180
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
181
+
182
+ conn_opts=get_cli_connection
183
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
184
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
185
+ output = ssh.exec!("stop vm name=#{vmname}")
186
+ output.each_line do |line|
187
+ if line.match(/Status:/)
188
+ current[:status]=line.split[1].strip
189
+ elsif line.match(/Time:/)
190
+ line["Time: "]=""
191
+ current[:time]=line.strip
192
+ elsif line.match(/Error Msg:/)
193
+ line["Error Msg: "]=""
194
+ current[:errormsg]=line.strip
195
+ end
196
+ end
197
+ end
198
+ return current
199
+ end
200
+ #
201
+ # suspend_vm, given a vmname issue a suspend request
202
+ #
203
+ def suspend_vm(vmname)
204
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
205
+
206
+ conn_opts=get_cli_connection
207
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
208
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
209
+ output = ssh.exec!("suspend vm name=#{vmname}")
210
+ output.each_line do |line|
211
+ if line.match(/Status:/)
212
+ current[:status]=line.split[1].strip
213
+ elsif line.match(/Time:/)
214
+ line["Time: "]=""
215
+ current[:time]=line.strip
216
+ elsif line.match(/Error Msg:/)
217
+ line["Error Msg: "]=""
218
+ current[:errormsg]=line.strip
219
+ end
220
+ end
221
+ end
222
+ return current
223
+ end
224
+ #
225
+ # resume_vm, given a vmname issue a resume request
226
+ #
227
+ def resume_vm(vmname)
228
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
229
+
230
+ conn_opts=get_cli_connection
231
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
232
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
233
+ output = ssh.exec!("resume vm name=#{vmname}")
234
+ output.each_line do |line|
235
+ if line.match(/Status:/)
236
+ current[:status]=line.split[1].strip
237
+ elsif line.match(/Time:/)
238
+ line["Time: "]=""
239
+ current[:time]=line.strip
240
+ elsif line.match(/Error Msg:/)
241
+ line["Error Msg: "]=""
242
+ current[:errormsg]=line.strip
243
+ end
244
+ end
245
+ end
246
+ return current
247
+ end
248
+ #
249
+ # restart_vm, given a vmname issue a restart request
250
+ #
251
+ def restart_vm(vmname)
252
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
253
+
254
+ conn_opts=get_cli_connection
255
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
256
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
257
+ output = ssh.exec!("restart vm name=#{vmname}")
258
+ output.each_line do |line|
259
+ if line.match(/Status:/)
260
+ current[:status]=line.split[1].strip
261
+ elsif line.match(/Time:/)
262
+ line["Time: "]=""
263
+ current[:time]=line.strip
264
+ elsif line.match(/Error Msg:/)
265
+ line["Error Msg: "]=""
266
+ current[:errormsg]=line.strip
267
+ end
268
+ end
269
+ end
270
+ return current
271
+ end
272
+ #
273
+ # list_vm, display all vm's
274
+ #
275
+ def list_vm(vmname)
276
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
277
+
278
+ conn_opts=get_cli_connection
279
+ if not vmname
280
+ Chef::Log.debug("#{conn_opts[:host]}...list vm")
281
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
282
+ output = ssh.exec!("list vm")
283
+ output.each_line do |line|
284
+ if line.match(/Status:/)
285
+ current[:status]=line.split[1].strip
286
+ elsif line.match(/Time:/)
287
+ line["Time: "]=""
288
+ current[:time]=line.strip
289
+ elsif line.match(/ id:/)
290
+ puts line.split(':')[2].strip
291
+ elsif line.match(/Error Msg:/)
292
+ line["Error Msg: "]=""
293
+ current[:errormsg]=line.strip
294
+ end
295
+ end
296
+ end
297
+ return current
298
+ else
299
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
300
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
301
+ output = ssh.exec!("show vm name=#{vmname}")
302
+ output.each_line do |line|
303
+ if line.match(/Status:/)
304
+ current[:status]=line.split[1].strip
305
+ elsif line.match(/Time:/)
306
+ line["Time: "]=""
307
+ current[:time]=line.strip
308
+ elsif line.match(/Error Msg:/)
309
+ line["Error Msg: "]=""
310
+ current[:errormsg]=line.strip
311
+ elsif line.match(/ /)
312
+ puts line
313
+ end
314
+ end
315
+ end
316
+ return current
317
+ end
318
+ end
319
+ #
320
+ # list_serverpool, display all server pool's
321
+ #
322
+ def list_serverpool(pool)
323
+ current = {:errormsg => "", :status => "", :time => "", :poolstatus => ""}
324
+
325
+ conn_opts=get_cli_connection
326
+ if not pool
327
+ Chef::Log.debug("#{conn_opts[:host]}...list serverpool")
328
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
329
+ output = ssh.exec!("list serverpool")
330
+ output.each_line do |line|
331
+ if line.match(/Status:/)
332
+ current[:status]=line.split[1].strip
333
+ elsif line.match(/Time:/)
334
+ line["Time: "]=""
335
+ current[:time]=line.strip
336
+ elsif line.match(/ id:/)
337
+ puts line.split(':')[2].strip
338
+ elsif line.match(/Error Msg:/)
339
+ line["Error Msg: "]=""
340
+ current[:errormsg]=line.strip
341
+ end
342
+ end
343
+ end
344
+ return current
345
+ else
346
+ Chef::Log.debug("#{conn_opts[:host]}...show serverpool name=#{pool}")
347
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
348
+ output = ssh.exec!("show serverpool name=#{pool}")
349
+ output.each_line do |line|
350
+ if line.match(/Status:/)
351
+ current[:status]=line.split[1].strip
352
+ elsif line.match(/Time:/)
353
+ line["Time: "]=""
354
+ current[:time]=line.strip
355
+ elsif line.match(/Error Msg:/)
356
+ line["Error Msg: "]=""
357
+ current[:errormsg]=line.strip
358
+ elsif line.match(/ /)
359
+ puts line
360
+ end
361
+ end
362
+ end
363
+ return current
364
+ end
365
+ end
366
+ #
367
+ # delete_vm, delete VM
368
+ #
369
+ def delete_vm(vmname)
370
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
371
+
372
+ conn_opts=get_cli_connection
373
+ Chef::Log.debug("#{conn_opts[:host]}...delete vm name=#{vmname}")
374
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
375
+ output = ssh.exec!("delete vm name=#{vmname}")
376
+ output.each_line do |line|
377
+ if line.match(/Status:/)
378
+ current[:status]=line.split[1].strip
379
+ elsif line.match(/Time:/)
380
+ line["Time: "]=""
381
+ current[:time]=line.strip
382
+ elsif line.match(/Error Msg:/)
383
+ line["Error Msg: "]=""
384
+ current[:errormsg]=line.strip
385
+ end
386
+ end
387
+ end
388
+ return current
389
+ end
390
+
391
+ #
392
+ # clone_vm, clone VM
393
+ #
394
+ def clone_vm(vmname, desttype, destname, serverpool)
395
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
396
+
397
+ conn_opts=get_cli_connection
398
+ Chef::Log.debug("#{conn_opts[:host]}...clone vm name=#{vmname},#{desttype},#{destname},#{serverpool}")
399
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
400
+ output = ssh.exec!("clone vm name=#{vmname} destType=#{desttype} destname=#{destname} serverPool=#{serverpool}")
401
+ output.each_line do |line|
402
+ if line.match(/Status:/)
403
+ current[:status]=line.split[1].strip
404
+ elsif line.match(/Time:/)
405
+ line["Time: "]=""
406
+ current[:time]=line.strip
407
+ elsif line.match(/Error Msg:/)
408
+ line["Error Msg: "]=""
409
+ current[:errormsg]=line.strip
410
+ end
411
+ end
412
+ end
413
+ return current
414
+ end
415
+ #
416
+ # edit_vm, edit VM cpu and memory
417
+ #
418
+ def edit_vm(vmname, memory, memorylimit, cpucount, cpucountlimit)
419
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
420
+
421
+ conn_opts=get_cli_connection
422
+ Chef::Log.debug("#{conn_opts[:host]}...edit vm name=#{vmname},#{memory},#{memorylimit},#{cpucount},#{cpucountlimit}")
423
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
424
+ output = ssh.exec!("edit vm name=#{vmname} memory=#{memory} memorylimit=#{memorylimit} cpucount=#{cpucount} cpucountlimit=#{cpucountlimit}")
425
+ output.each_line do |line|
426
+ if line.match(/Status:/)
427
+ current[:status]=line.split[1].strip
428
+ elsif line.match(/Time:/)
429
+ line["Time: "]=""
430
+ current[:time]=line.strip
431
+ elsif line.match(/Error Msg:/)
432
+ line["Error Msg: "]=""
433
+ current[:errormsg]=line.strip
434
+ end
435
+ end
436
+ end
437
+ return current
438
+ end
439
+ #
440
+ # add_vnic, add vnic on vm
441
+ #
442
+ def add_vnic(vmname, network, vnicname)
443
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
444
+
445
+ conn_opts=get_cli_connection
446
+ Chef::Log.debug("#{conn_opts[:host]}...create vnic name=#{vnicname},#{network},#{vmname}")
447
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
448
+ output = ssh.exec!("create vnic name=#{vnicname} network=#{network} on vm name=#{vmname}")
449
+ output.each_line do |line|
450
+ if line.match(/Status:/)
451
+ current[:status]=line.split[1].strip
452
+ elsif line.match(/Time:/)
453
+ line["Time: "]=""
454
+ current[:time]=line.strip
455
+ elsif line.match(/Error Msg:/)
456
+ line["Error Msg: "]=""
457
+ current[:errormsg]=line.strip
458
+ end
459
+ end
460
+ end
461
+ return current
462
+ end
463
+ #
464
+ # send_message, send a vm message to a vm
465
+ #
466
+ def send_message(vmname, key, message)
467
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
468
+
469
+ conn_opts=get_cli_connection
470
+ Chef::Log.debug("#{conn_opts[:host]}...sendvmmessage vm name=#{vmname},#{key},#{message}")
471
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
472
+ output = ssh.exec!("sendvmmessage vm name=#{vmname} key=#{key} message=#{message} log=no")
473
+ output.each_line do |line|
474
+ if line.match(/Status:/)
475
+ current[:status]=line.split[1].strip
476
+ elsif line.match(/Time:/)
477
+ line["Time: "]=""
478
+ current[:time]=line.strip
479
+ elsif line.match(/Error Msg:/)
480
+ line["Error Msg: "]=""
481
+ current[:errormsg]=line.strip
482
+ end
483
+ end
484
+ end
485
+ return current
486
+ end
487
+ #
488
+ # List TAG
489
+ #
490
+ def list_tag(tag)
491
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
492
+
493
+ conn_opts=get_cli_connection
494
+ if not tag
495
+ Chef::Log.debug("#{conn_opts[:host]}...list vm")
496
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
497
+ output = ssh.exec!("list tag")
498
+ output.each_line do |line|
499
+ if line.match(/Status:/)
500
+ current[:status]=line.split[1].strip
501
+ elsif line.match(/Time:/)
502
+ line["Time: "]=""
503
+ current[:time]=line.strip
504
+ elsif line.match(/ id:/)
505
+ puts line.split(':')[2].strip
506
+ elsif line.match(/Error Msg:/)
507
+ line["Error Msg: "]=""
508
+ current[:errormsg]=line.strip
509
+ end
510
+ end
511
+ end
512
+ return current
513
+ else
514
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{tag}")
515
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
516
+ output = ssh.exec!("show tag name='#{tag}'")
517
+ output.each_line do |line|
518
+ if line.match(/Status:/)
519
+ current[:status]=line.split[1].strip
520
+ elsif line.match(/Time:/)
521
+ line["Time: "]=""
522
+ current[:time]=line.strip
523
+ elsif line.match(/Error Msg:/)
524
+ line["Error Msg: "]=""
525
+ current[:errormsg]=line.strip
526
+ elsif line.match(/ /)
527
+ puts line
528
+ end
529
+ end
530
+ end
531
+ return current
532
+ end
533
+ end
534
+ end
535
+ end
536
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+
6
+ require 'chef/knife'
7
+ require 'chef/knife/BaseOraclevmCommand'
8
+ require 'netaddr'
9
+ require 'net/ssh'
10
+
11
+ # list a server pool
12
+ class Chef::Knife::OvmcliServerpoolList < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife ovmcli serverpool list <name>"
15
+
16
+ get_common_options
17
+
18
+ def run
19
+
20
+ $stdout.sync = true
21
+
22
+ pool = @name_args[0]
23
+
24
+ current=list_serverpool(pool)
25
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:poolstatus]}.")
26
+
27
+ if current[:status]!="Success"
28
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Code copied from Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Author:: Michael Huisman michhuis@gmail.com
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+ require 'chef/knife/BaseOraclevmCommand'
9
+ require 'netaddr'
10
+ require 'net/ssh'
11
+
12
+ # list tag
13
+ class Chef::Knife::OvmcliTagList < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli tag list <name>"
16
+
17
+ get_common_options
18
+
19
+ def run
20
+
21
+ $stdout.sync = true
22
+
23
+ tag = @name_args[0]
24
+
25
+ current=list_tag(tag)
26
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
27
+
28
+ if current[:status]!="Success"
29
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Code copied from Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Author:: Michael Huisman michhuis@gmail.com
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+ require 'chef/knife/BaseOraclevmCommand'
9
+ require 'netaddr'
10
+ require 'net/ssh'
11
+
12
+ # Add vnic on a virtual machine
13
+ class Chef::Knife::OvmcliVmAddvnic < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm addvnic VMNAME (options)"
16
+
17
+ option :network,
18
+ :short => "-n VALUE",
19
+ :long => "--network VALUE",
20
+ :description => "The name of the network."
21
+
22
+ option :vnicname,
23
+ :short => "-s VALUE",
24
+ :long => "--vnicname VALUE",
25
+ :description => "The name of the vnic."
26
+
27
+ get_common_options
28
+
29
+ def run
30
+
31
+ $stdout.sync = true
32
+
33
+ vmname = @name_args[0]
34
+
35
+ network=get_config(:network)
36
+ vnicname=get_config(:vnicname)
37
+
38
+ current=add_vnic(vmname, network, vnicname)
39
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
40
+
41
+ if current[:status]!="Success"
42
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Code copied from Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Author:: Michael Huisman michhuis@gmail.com
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+ require 'chef/knife/BaseOraclevmCommand'
9
+ require 'netaddr'
10
+ require 'net/ssh'
11
+
12
+ # Clone a virtual machine
13
+ class Chef::Knife::OvmcliVmClone < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm clone VMNAME (options)"
16
+
17
+ option :desttype,
18
+ :short => "-t VALUE",
19
+ :long => "--desttype VALUE",
20
+ :description => "The object to create from the virtual machine can be a virtual machine or a template."
21
+
22
+ option :destname,
23
+ :short => "-n VALUE",
24
+ :long => "--destname VALUE",
25
+ :description => "The name of the cloned virtual machine or template."
26
+
27
+ option :serverpool,
28
+ :short => "-p VALUE",
29
+ :long => "--serverpool VALUE",
30
+ :description => "The server pool on which to deploy the cloned virtual machine or template."
31
+
32
+ get_common_options
33
+
34
+ def run
35
+
36
+ $stdout.sync = true
37
+
38
+ vmname = @name_args[0]
39
+
40
+ desttype=get_config(:desttype)
41
+ destname=get_config(:destname)
42
+ serverpool=get_config(:serverpool)
43
+
44
+ current=clone_vm(vmname, desttype, destname, serverpool)
45
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
46
+
47
+ if current[:status]!="Success"
48
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+
6
+ require 'chef/knife'
7
+ require 'chef/knife/BaseOraclevmCommand'
8
+ require 'netaddr'
9
+ require 'net/ssh'
10
+
11
+ # delete a VM
12
+ class Chef::Knife::OvmcliVmDelete < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife ovmcli vm delete VMNAME"
15
+
16
+ get_common_options
17
+
18
+
19
+ def run
20
+
21
+ $stdout.sync = true
22
+
23
+ vmname = @name_args[0]
24
+ if vmname.nil?
25
+ show_usage
26
+ ui.fatal("You must specify a virtual machine name")
27
+ exit 1
28
+ end
29
+ current=show_vm_status(vmname)
30
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
31
+
32
+ if current[:status]=="Success"
33
+ dstatus=delete_vm(vmname)
34
+ if dstatus[:status] == "Success"
35
+ puts "#{dstatus[:status]}"
36
+ else
37
+ puts "Failed with #{dstatus[:errormsg]}"
38
+ end
39
+ else
40
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Code copied from Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Author:: Michael Huisman michhuis@gmail.com
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+ require 'chef/knife/BaseOraclevmCommand'
9
+ require 'netaddr'
10
+ require 'net/ssh'
11
+
12
+ # Add vnic on a virtual machine
13
+ class Chef::Knife::OvmcliVmEdit < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm edit VMNAME (options)"
16
+
17
+ option :memory,
18
+ :short => "-m VALUE",
19
+ :long => "--memory VALUE",
20
+ :description => "The memory size the virtual machine is allocated in MB."
21
+
22
+ option :memorylimit,
23
+ :short => "-l VALUE",
24
+ :long => "--memoryLimit VALUE",
25
+ :description => "The maximum memory size the virtual machine can be allocated in MB."
26
+
27
+ option :cpucount,
28
+ :short => "-c VALUE",
29
+ :long => "--cpucount VALUE",
30
+ :description => "The number of processors the virtual machine is allocated."
31
+
32
+ option :cpucountlimit,
33
+ :short => "-x VALUE",
34
+ :long => "--cpucountlimit VALUE",
35
+ :description => "The maximum number of processors the virtual machine can be allocated."
36
+
37
+ get_common_options
38
+
39
+ def run
40
+
41
+ $stdout.sync = true
42
+
43
+ vmname = @name_args[0]
44
+
45
+ memory=get_config(:memory)
46
+ memorylimit=get_config(:memorylimit)
47
+ cpucount=get_config(:cpucount)
48
+ cpucountlimit=get_config(:cpucountlimit)
49
+
50
+ current=edit_vm(vmname, memory, memorylimit, cpucount, cpucountlimit)
51
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
52
+
53
+ if current[:status]!="Success"
54
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+
6
+ require 'chef/knife'
7
+ require 'chef/knife/BaseOraclevmCommand'
8
+ require 'netaddr'
9
+ require 'net/ssh'
10
+
11
+ # Manage power state of a virtual machine
12
+ class Chef::Knife::OvmcliVmList < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife ovmcli vm list <name>"
15
+
16
+ get_common_options
17
+
18
+ def run
19
+
20
+ $stdout.sync = true
21
+
22
+ vmname = @name_args[0]
23
+
24
+ current=list_vm(vmname)
25
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
26
+
27
+ if current[:status]!="Success"
28
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Code copied from Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Author:: Michael Huisman michhuis@gmail.com
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+
7
+ require 'chef/knife'
8
+ require 'chef/knife/BaseOraclevmCommand'
9
+ require 'netaddr'
10
+ require 'net/ssh'
11
+
12
+ # Add vnic on a virtual machine
13
+ class Chef::Knife::OvmcliVmMessage < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm message VMNAME (options)"
16
+
17
+ option :key,
18
+ :short => "-k VALUE",
19
+ :long => "--key VALUE",
20
+ :description => "The name of the key."
21
+
22
+ option :message,
23
+ :short => "-m VALUE",
24
+ :long => "--message VALUE",
25
+ :description => "The value of the message."
26
+
27
+ get_common_options
28
+
29
+ def run
30
+
31
+ $stdout.sync = true
32
+
33
+ vmname = @name_args[0]
34
+
35
+ key=get_config(:key)
36
+ message=get_config(:message)
37
+
38
+ current=send_message(vmname, key, message)
39
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
40
+
41
+ if current[:status]!="Success"
42
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+
6
+ require 'chef/knife'
7
+ require 'chef/knife/BaseOraclevmCommand'
8
+ require 'netaddr'
9
+ require 'net/ssh'
10
+
11
+ # Manage power state of a virtual machine
12
+ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife ovmcli vm state VMNAME (options)"
15
+
16
+ get_common_options
17
+
18
+ option :state,
19
+ :short => "-s STATE",
20
+ :long => "--state STATE",
21
+ :description => "The power state to transition the VM into; one of on|off|suspend|resume|restart"
22
+
23
+
24
+ def run
25
+
26
+ $stdout.sync = true
27
+
28
+ vmname = @name_args[0]
29
+ if vmname.nil?
30
+ show_usage
31
+ ui.fatal("You must specify a virtual machine name")
32
+ exit 1
33
+ end
34
+ current=show_vm_status(vmname)
35
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
36
+
37
+ state=get_config(:state)
38
+
39
+ if current[:status]=="Success"
40
+ if not state
41
+ puts "Virtual machine #{vmname} is in state #{current[:vmstatus]}"
42
+ else
43
+ case current[:vmstatus]
44
+ when 'Running'
45
+ case state
46
+ when 'on'
47
+ puts "Virtual machine #{vmname} was already powered on"
48
+ when 'off'
49
+ result=stop_vm(vmname)
50
+ puts "Power off virtual machine #{vmname} : #{result[:status]}"
51
+ when 'suspend'
52
+ result=suspend_vm(vmname)
53
+ puts "Suspend virtual machine #{vmname} : #{result[:status]}"
54
+ when 'restart'
55
+ result=restart_vm(vmname)
56
+ puts "Restart virtual machine #{vmname} : #{result[:status]}"
57
+ when 'resume'
58
+ puts "Cannot Resume virtual machine #{vmname} as it is on"
59
+ else
60
+ show_usage
61
+ end
62
+ when 'Stopped'
63
+ case state
64
+ when 'on'
65
+ result=start_vm(vmname)
66
+ puts "Power on virtual machine #{vmname} : #{result[:status]}"
67
+ when 'off'
68
+ puts "virtual machine #{vmname} was already off"
69
+ when 'suspend'
70
+ puts "Cannot Suspend virtual machine #{vmname} as it is off"
71
+ when 'restart'
72
+ puts "Cannot Restrt virtual machine #{vmname} as it is off"
73
+ when 'resume'
74
+ puts "Cannot Resume virtual machine #{vmname} as it is off"
75
+ else
76
+ show_usage
77
+ end
78
+ when 'Stopping'
79
+ case state
80
+ when 'on'
81
+ puts "Cannot power on virtual machine #{vmname} as it is Stopping"
82
+ when 'off'
83
+ puts "Cannot power off virtual machine #{vmname} as it is Stopping"
84
+ when 'suspend'
85
+ puts "Cannot Suspend virtual machine #{vmname} as it is Stopping"
86
+ when 'restart'
87
+ puts "Cannot Restrt virtual machine #{vmname} as it is Stopping"
88
+ when 'resume'
89
+ puts "Cannot Resume virtual machine #{vmname} as it is Stopping"
90
+ else
91
+ show_usage
92
+ end
93
+ when 'Suspended'
94
+ case state
95
+ when 'on'
96
+ puts "Cannot Power on virtual machine #{vmname} as it is suspended"
97
+ when 'off'
98
+ puts "Cannot Power off virtual machine #{vmname} as it is suspended"
99
+ when 'suspend'
100
+ puts "Cannot Suspend virtual machine #{vmname} as it is already suspended"
101
+ when 'restart'
102
+ puts "Cannot Restart virtual machine #{vmname} as it is suspended"
103
+ when 'resume'
104
+ result=resume_vm(vmname)
105
+ puts "Resume virtual machine #{vmname} : #{result[:status]}"
106
+ else
107
+ show_usage
108
+ end
109
+ else
110
+ puts "I don't know what a state of #{current[:vmstatus]} is on #{vmname}"
111
+ end
112
+ end
113
+ else
114
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,4 @@
1
+ module KnifeOvmCli
2
+ VERSION = "0.0.5"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-ovmcli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Geoff O'Callaghan / Michael Huisman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: netaddr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ description: OracleVM Support for Chef's Knife Command
42
+ email: geoffocallaghan@gmail.com / michhuis@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/chef/knife/BaseOraclevmCommand.rb
48
+ - lib/chef/knife/ovmcli_serverpool_list.rb
49
+ - lib/chef/knife/ovmcli_tag_list.rb
50
+ - lib/chef/knife/ovmcli_vm_addvnic.rb
51
+ - lib/chef/knife/ovmcli_vm_clone.rb
52
+ - lib/chef/knife/ovmcli_vm_delete.rb
53
+ - lib/chef/knife/ovmcli_vm_edit.rb
54
+ - lib/chef/knife/ovmcli_vm_list.rb
55
+ - lib/chef/knife/ovmcli_vm_message.rb
56
+ - lib/chef/knife/ovmcli_vm_state.rb
57
+ - lib/knife-ovmcli/version.rb
58
+ homepage: http://github.com/michaelhuisman/knife-oraclevm
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.4
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: OracleVM Support for Knife
81
+ test_files: []
82
+ has_rdoc: