knife-ovmcli 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b392fc5de09cd159162052e0e70e2e2c3395757
4
- data.tar.gz: 61024e6d44d3a9b5fd52c7ed9574d8ec0eae03b6
3
+ metadata.gz: 1ca4b8d7413b43ba034295d856dc210bc0479fa1
4
+ data.tar.gz: 4a68816c34d48db63d6d9d341934f018bf8198fd
5
5
  SHA512:
6
- metadata.gz: a1134edb619229bf2be45be0d9ccdf5c568bb8428467694d08c629197ec81e419cb109d4d52b8c242bac4e0cc83641f44f0766248868d66d33d535acccb254cc
7
- data.tar.gz: d9030d249ca3ff5694ba1b46b25154fb50c6505131b7a873026de4513e3dcbad10cc03147f59f652489f3b0ad826f7eb9adaac8c1b4f502846804bebce1e4ff3
6
+ metadata.gz: 7b054d4e3b86eaf731c8316c5d4db6ecef701a1529ffbd9cef013a6005f64c9ae293c5e99bc878679ce4272ad966b59d6bce6bad49cdb957ca50e00270378d2a
7
+ data.tar.gz: c71b2b72f7463470d8f244172dbc2fa88ea6ab7acd4d202f0857fa243cc453a3d2f2ff449e7b8894a028032c6efe96ff4e38c89e0e6edda2fc975ac7213c1036
@@ -2,7 +2,7 @@
2
2
  # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
3
  # Contributor:: Michael Huisman michhuis@gmail.com
4
4
  # License:: Apache License, Version 2.0
5
- #
5
+ # Version::0.0.8
6
6
 
7
7
  require 'chef/knife'
8
8
 
@@ -270,6 +270,30 @@ class Chef
270
270
  return current
271
271
  end
272
272
  #
273
+ # kill_vm, given a vmname issue a kill request
274
+ #
275
+ def kill_vm(vmname)
276
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
277
+
278
+ conn_opts=get_cli_connection
279
+ Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
280
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
281
+ output = ssh.exec!("kill vm name=#{vmname}")
282
+ output.each_line do |line|
283
+ if line.match(/Status:/)
284
+ current[:status]=line.split[1].strip
285
+ elsif line.match(/Time:/)
286
+ line["Time: "]=""
287
+ current[:time]=line.strip
288
+ elsif line.match(/Error Msg:/)
289
+ line["Error Msg: "]=""
290
+ current[:errormsg]=line.strip
291
+ end
292
+ end
293
+ end
294
+ return current
295
+ end
296
+ #
273
297
  # list_vm, display all vm's
274
298
  #
275
299
  def list_vm(vmname)
@@ -459,7 +483,55 @@ class Chef
459
483
  end
460
484
  end
461
485
  return current
462
- end
486
+ end
487
+ #
488
+ # remove_vdisk, delete vdisk diskmapping
489
+ #
490
+ def remove_vdisk(vdiskid)
491
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
492
+
493
+ conn_opts=get_cli_connection
494
+ Chef::Log.debug("#{conn_opts[:host]}...delete VmDiskMapping id=#{vdiskid}")
495
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
496
+ output = ssh.exec!("delete VmDiskMapping id=#{vdiskid}")
497
+ output.each_line do |line|
498
+ if line.match(/Status:/)
499
+ current[:status]=line.split[1].strip
500
+ elsif line.match(/Time:/)
501
+ line["Time: "]=""
502
+ current[:time]=line.strip
503
+ elsif line.match(/Error Msg:/)
504
+ line["Error Msg: "]=""
505
+ current[:errormsg]=line.strip
506
+ end
507
+ end
508
+ end
509
+ return current
510
+ end
511
+ #
512
+ # delete_vdisk, delete vdisk
513
+ #
514
+ def delete_vdisk(vdisk)
515
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
516
+
517
+ conn_opts=get_cli_connection
518
+ Chef::Log.debug("#{conn_opts[:host]}...delete VirtualDisk name=#{vdisk}")
519
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
520
+ output = ssh.exec!("delete VirtualDisk name=#{vdisk}")
521
+ output.each_line do |line|
522
+ if line.match(/Status:/)
523
+ current[:status]=line.split[1].strip
524
+ elsif line.match(/Time:/)
525
+ line["Time: "]=""
526
+ current[:time]=line.strip
527
+ elsif line.match(/Error Msg:/)
528
+ line["Error Msg: "]=""
529
+ current[:errormsg]=line.strip
530
+ end
531
+ end
532
+ end
533
+ return current
534
+ end
463
535
  #
464
536
  # edit_vm, edit VM cpu and memory
465
537
  #
@@ -485,6 +557,30 @@ class Chef
485
557
  return current
486
558
  end
487
559
  #
560
+ # migrate_vm, migrate VM to another server
561
+ #
562
+ def migrate_vm(vmname, server)
563
+ current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
564
+
565
+ conn_opts=get_cli_connection
566
+ Chef::Log.debug("#{conn_opts[:host]}...migrate vm name=#{vmname},destServer=#{server}")
567
+ Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
568
+ output = ssh.exec!("migrate vm name=#{vmname} destServer=#{server}")
569
+ output.each_line do |line|
570
+ if line.match(/Status:/)
571
+ current[:status]=line.split[1].strip
572
+ elsif line.match(/Time:/)
573
+ line["Time: "]=""
574
+ current[:time]=line.strip
575
+ elsif line.match(/Error Msg:/)
576
+ line["Error Msg: "]=""
577
+ current[:errormsg]=line.strip
578
+ end
579
+ end
580
+ end
581
+ return current
582
+ end
583
+ #
488
584
  # add_vnic, add vnic on vm
489
585
  #
490
586
  def add_vnic(vmname, network, vnicname)
@@ -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
+ # Delete a virtual disk
13
+ class Chef::Knife::OvmcliVmDeletevdisk < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm deletevdisk VDISK"
16
+
17
+ get_common_options
18
+
19
+ def run
20
+
21
+ $stdout.sync = true
22
+
23
+ vdisk = @name_args[0]
24
+
25
+ current=delete_vdisk(vdisk)
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,50 @@
1
+ #
2
+ # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # 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
+ # Migrate a VM
13
+ class Chef::Knife::OvmcliVmMigrate < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm migrate VMNAME (options)"
16
+
17
+ get_common_options
18
+
19
+ option :server,
20
+ :short => "-s VALUE",
21
+ :long => "--server VALUE",
22
+ :description => "The name of the Oracle VM Server on which to migrate the virtual machine."
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
+
35
+ current=show_vm_status(vmname)
36
+ Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.")
37
+
38
+ if current[:status]=="Success"
39
+ server=get_config(:server)
40
+ mstatus=migrate_vm(vmname, server)
41
+ if mstatus[:status] == "Success"
42
+ puts "#{mstatus[:status]}"
43
+ else
44
+ puts "Failed with #{mstatus[:errormsg]}"
45
+ end
46
+ else
47
+ puts "Call to OVM CLI Failed with #{current[:errormsg]}"
48
+ end
49
+ end
50
+ 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
+ # Remove a virtual disk
13
+ class Chef::Knife::OvmcliVmRemovevdisk < Chef::Knife::BaseOraclevmCommand
14
+
15
+ banner "knife ovmcli vm removevdisk VDISKID"
16
+
17
+ get_common_options
18
+
19
+ def run
20
+
21
+ $stdout.sync = true
22
+
23
+ vdiskid = @name_args[0]
24
+
25
+ current=remove_vdisk(vdiskid)
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
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Geoff O'Callaghan (<geoffocallaghan@gmail.com>)
3
+ # Michael Huisman <michhuis@gmail.com>
3
4
  # License:: Apache License, Version 2.0
4
5
  #
5
6
 
@@ -18,7 +19,7 @@ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
18
19
  option :state,
19
20
  :short => "-s STATE",
20
21
  :long => "--state STATE",
21
- :description => "The power state to transition the VM into; one of on|off|suspend|resume|restart"
22
+ :description => "The power state to transition the VM into; one of on|off|suspend|resume|restart|kill"
22
23
 
23
24
 
24
25
  def run
@@ -56,6 +57,9 @@ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
56
57
  puts "Restart virtual machine #{vmname} : #{result[:status]}"
57
58
  when 'resume'
58
59
  puts "Cannot Resume virtual machine #{vmname} as it is on"
60
+ when 'kill'
61
+ result=kill_vm(vmname)
62
+ puts "Kill virtual machine #{vmname} : #{result[:status]}"
59
63
  else
60
64
  show_usage
61
65
  end
@@ -72,6 +76,8 @@ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
72
76
  puts "Cannot Restrt virtual machine #{vmname} as it is off"
73
77
  when 'resume'
74
78
  puts "Cannot Resume virtual machine #{vmname} as it is off"
79
+ when 'kill'
80
+ puts "Cannot Kill virtual machine #{vmname} as it is off"
75
81
  else
76
82
  show_usage
77
83
  end
@@ -87,6 +93,8 @@ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
87
93
  puts "Cannot Restrt virtual machine #{vmname} as it is Stopping"
88
94
  when 'resume'
89
95
  puts "Cannot Resume virtual machine #{vmname} as it is Stopping"
96
+ when 'kill'
97
+ puts "Cannot Kill virtual machine #{vmname} as it is Stopping"
90
98
  else
91
99
  show_usage
92
100
  end
@@ -103,6 +111,9 @@ class Chef::Knife::OvmcliVmState < Chef::Knife::BaseOraclevmCommand
103
111
  when 'resume'
104
112
  result=resume_vm(vmname)
105
113
  puts "Resume virtual machine #{vmname} : #{result[:status]}"
114
+ when 'kill'
115
+ result=kill_vm(vmname)
116
+ puts "Killing virtual machine #{vmname} : #{result[:status]}"
106
117
  else
107
118
  show_usage
108
119
  end
@@ -1,4 +1,4 @@
1
1
  module KnifeOvmCli
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-ovmcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
- - Geoff O'Callaghan / Michael Huisman
7
+ - Michael Huisman / Geoff O'Callaghan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netaddr
@@ -52,9 +52,12 @@ files:
52
52
  - lib/chef/knife/ovmcli_vm_clone.rb
53
53
  - lib/chef/knife/ovmcli_vm_createvdisk.rb
54
54
  - lib/chef/knife/ovmcli_vm_delete.rb
55
+ - lib/chef/knife/ovmcli_vm_deletevdisk.rb
55
56
  - lib/chef/knife/ovmcli_vm_edit.rb
56
57
  - lib/chef/knife/ovmcli_vm_list.rb
57
58
  - lib/chef/knife/ovmcli_vm_message.rb
59
+ - lib/chef/knife/ovmcli_vm_migrate.rb
60
+ - lib/chef/knife/ovmcli_vm_removevdisk.rb
58
61
  - lib/chef/knife/ovmcli_vm_state.rb
59
62
  - lib/knife-ovmcli/version.rb
60
63
  homepage: http://github.com/michaelhuisman/knife-ovmcli