knife-oraclevm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -272,21 +272,113 @@ class Chef
272
272
  #
273
273
  # list_vm, display all vm's
274
274
  #
275
- def list_vm
275
+ def list_vm(vmname)
276
276
  current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
277
277
 
278
278
  conn_opts=get_cli_connection
279
- Chef::Log.debug("#{conn_opts[:host]}...list vm")
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}")
280
374
  Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
281
- output = ssh.exec!("list vm")
375
+ output = ssh.exec!("delete vm name=#{vmname}")
282
376
  output.each_line do |line|
283
377
  if line.match(/Status:/)
284
378
  current[:status]=line.split[1].strip
285
379
  elsif line.match(/Time:/)
286
380
  line["Time: "]=""
287
381
  current[:time]=line.strip
288
- elsif line.match(/ id:/)
289
- puts line.split(':')[2].strip
290
382
  elsif line.match(/Error Msg:/)
291
383
  line["Error Msg: "]=""
292
384
  current[:errormsg]=line.strip
@@ -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::OraclevmServerpoolList < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife oraclevm 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,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::OraclevmVmDelete < Chef::Knife::BaseOraclevmCommand
13
+
14
+ banner "knife oraclevm 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
@@ -11,7 +11,7 @@ require 'net/ssh'
11
11
  # Manage power state of a virtual machine
12
12
  class Chef::Knife::OraclevmVmList < Chef::Knife::BaseOraclevmCommand
13
13
 
14
- banner "knife oraclevm vm list (options)"
14
+ banner "knife oraclevm vm list <name>"
15
15
 
16
16
  get_common_options
17
17
 
@@ -21,7 +21,12 @@ class Chef::Knife::OraclevmVmList < Chef::Knife::BaseOraclevmCommand
21
21
 
22
22
  vmname = @name_args[0]
23
23
 
24
- list_vm
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
25
30
 
26
31
  end
27
32
  end
@@ -1,4 +1,4 @@
1
1
  module KnifeOracleVM
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-oraclevm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff O'Callaghan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-08-07 00:00:00 +10:00
18
+ date: 2013-08-10 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,7 +62,9 @@ files:
62
62
  - lib/knife-oraclevm/version.rb
63
63
  - lib/chef/knife/BaseOraclevmCommand.rb
64
64
  - lib/chef/knife/oraclevm_vm_state.rb
65
+ - lib/chef/knife/oraclevm_serverpool_list.rb
65
66
  - lib/chef/knife/oraclevm_vm_list.rb
67
+ - lib/chef/knife/oraclevm_vm_delete.rb
66
68
  has_rdoc: true
67
69
  homepage: http://github.com/gocallag/knife-oraclevm
68
70
  licenses: []