Class: Chef::Knife::BaseOraclevmCommand

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/BaseOraclevmCommand.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_common_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 24

def self.get_common_options
	unless defined? $default
		$default = Hash.new
	end

	option :ovmmgr_user,
		:short => "-u USERNAME",
		:long => "--ovmmgruser USERNAME",
		:description => "The username for OracleVM Manager"
	$default[:ovmmgr_user] = "admin"

	option :ovmmgr_pass,
		:short => "-p PASSWORD",
		:long => "--ovmmgrpass PASSWORD",
		:description => "The password for OracleVM Manager"

	option :ovmmgr_host,
		:long => "--ovmmgrhost HOST",
		:description => "The OracleVM Manager host"

	option :ovmmgr_port,
		:long => "--ovmmgrport PORT",
		:description => "The OracleVM Manager CLI port number to use"
	$default[:ovmmgr_port] = 10000
end

Instance Method Details

#add_vdisk(vmname, slot, vdisk) ⇒ Object

add_vdisk, add vdisk



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 466

def add_vdisk(vmname, slot, vdisk)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...add vdisk name=#{vmname},#{slot},#{vdisk}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("create VmDiskMapping slot=#{slot} virtualDisk=#{vdisk} name=#{vdisk} on Vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#add_vnic(vmname, network, vnicname) ⇒ Object

add_vnic, add vnic on vm



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 586

def add_vnic(vmname, network, vnicname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...create vnic name=#{vnicname},#{network},#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("create vnic name=#{vnicname} network=#{network} on vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#clone_vm(vmname, desttype, destname, serverpool) ⇒ Object

clone_vm, clone VM



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 418

def clone_vm(vmname, desttype, destname, serverpool)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...clone vm name=#{vmname},#{desttype},#{destname},#{serverpool}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("clone vm name=#{vmname} destType=#{desttype} destname=#{destname} serverPool=#{serverpool}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#create_vdisk(vdisk, size, sparse, reposotory) ⇒ Object

create_vdisk, create vdisk



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 442

def create_vdisk(vdisk, size, sparse, reposotory)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...create vdisk name=#{vdisk},#{size},#{sparse},#{reposotory}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("create VirtualDisk name=#{vdisk} size=#{size} sparse=#{sparse} shareable=No on Repository name=#{reposotory}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#delete_vdisk(vdisk) ⇒ Object

delete_vdisk, delete vdisk



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 514

def delete_vdisk(vdisk)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...delete VirtualDisk name=#{vdisk}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("delete VirtualDisk name=#{vdisk}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#delete_vm(vmname) ⇒ Object

delete_vm, delete VM



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 393

def delete_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...delete vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("delete vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#edit_vm(vmname, memory, memorylimit, cpucount, cpucountlimit) ⇒ Object

edit_vm, edit VM cpu and memory



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 538

def edit_vm(vmname, memory, memorylimit, cpucount, cpucountlimit)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...edit vm name=#{vmname},#{memory},#{memorylimit},#{cpucount},#{cpucountlimit}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("edit vm name=#{vmname} memory=#{memory} memorylimit=#{memorylimit} cpucount=#{cpucount} cpucountlimit=#{cpucountlimit}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#fatal_exit(msg) ⇒ Object



97
98
99
100
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 97

def fatal_exit(msg)
	ui.fatal(msg)
	exit 1
end

#get_cli_connectionObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 57

def get_cli_connection

	conn_opts = {
		:host => get_config(:ovmmgr_host),
		:path => get_config(:ovmmgr_path),
		:port => get_config(:ovmmgr_port),
		:user => get_config(:ovmmgr_user),
		:password => get_config(:ovmmgr_pass),
	}
	
	# Grab the ovmmgr host  from the command line
	# if tt is not in the config file
	if not conn_opts[:host]
                               conn_opts[:host] = get_host
                             end
	# Grab the password from the command line
	# if tt is not in the config file
	if not conn_opts[:password]
                               conn_opts[:password] = get_password
                             end
	if conn_opts[:port] 
	  Chef::Log.debug("Waiting for port #{conn_opts[:port]} on #{conn_opts[:host]}...")
	  tcp_test_port(conn_opts[:host],conn_opts[:port])
	end
        return conn_opts
end

#get_config(key) ⇒ Object



50
51
52
53
54
55
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 50

def get_config(key)
	key = key.to_sym
	rval = config[key] || Chef::Config[:knife][key] || $default[key]
	Chef::Log.debug("value for config item #{key}: #{rval}")
	rval
end

#get_hostObject



84
85
86
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 84

def get_host
  @host ||= ui.ask("Enter your OVM Mgr Host: ") { |q| q.echo = true }
end

#get_passwordObject



88
89
90
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 88

def get_password
  @password ||= ui.ask("Enter your password: ") { |q| q.echo = false }
end

#get_vm(vmname) ⇒ Object



92
93
94
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 92

def get_vm(vmname)
  return retval
end

#kill_vm(vmname) ⇒ Object

kill_vm, given a vmname issue a kill request



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 275

def kill_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("kill vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#list_serverpool(pool) ⇒ Object

list_serverpool, display all server pool’s



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 346

def list_serverpool(pool)
   current = {:errormsg => "", :status => "", :time => "", :poolstatus => ""}

   conn_opts=get_cli_connection
   if not  pool
      Chef::Log.debug("#{conn_opts[:host]}...list serverpool")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("list serverpool")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/ id:/)
               puts line.split(':')[2].strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            end
         end
      end
      return current
   else
      Chef::Log.debug("#{conn_opts[:host]}...show serverpool name=#{pool}")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("show serverpool name=#{pool}")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            elsif line.match(/  /)
               puts line
            end
         end
      end
      return current
   end
end

#list_tag(tag) ⇒ Object

List TAG



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 634

def list_tag(tag)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   if not tag 
      Chef::Log.debug("#{conn_opts[:host]}...list vm")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("list tag")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/ id:/)
               puts line.split(':')[2].strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            end
         end
      end
      return current
   else
      Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{tag}")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("show tag name='#{tag}'")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            elsif line.match(/  /)
               puts line
            end
         end
      end
      return current
   end
end

#list_vm(vmname) ⇒ Object

list_vm, display all vm’s



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 299

def list_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   if not vmname 
      Chef::Log.debug("#{conn_opts[:host]}...list vm")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("list vm")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/ id:/)
               puts line.split(':')[2].strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            end
         end
      end
      return current
   else
      Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
      Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
         output = ssh.exec!("show vm name=#{vmname}")
         output.each_line do |line|
            if line.match(/Status:/)
               current[:status]=line.split[1].strip
            elsif line.match(/Time:/)
               line["Time: "]=""
               current[:time]=line.strip
            elsif line.match(/Error Msg:/)
               line["Error Msg: "]=""
               current[:errormsg]=line.strip
            elsif line.match(/  /)
               puts line
            end
         end
      end
      return current
   end
end

#migrate_vm(vmname, server) ⇒ Object

migrate_vm, migrate VM to another server



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 562

def migrate_vm(vmname, server)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...migrate vm name=#{vmname},destServer=#{server}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("migrate vm name=#{vmname} destServer=#{server}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#remove_vdisk(vdiskid) ⇒ Object

remove_vdisk, delete vdisk diskmapping



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 490

def remove_vdisk(vdiskid)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...delete VmDiskMapping id=#{vdiskid}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("delete VmDiskMapping id=#{vdiskid}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#restart_vm(vmname) ⇒ Object

restart_vm, given a vmname issue a restart request



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 251

def restart_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("restart vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#resume_vm(vmname) ⇒ Object

resume_vm, given a vmname issue a resume request



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 227

def resume_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("resume vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#send_message(vmname, key, message) ⇒ Object

send_message, send a vm message to a vm



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 610

def send_message(vmname, key, message)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}
						   
   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...sendvmmessage vm  name=#{vmname},#{key},#{message}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("sendvmmessage vm name=#{vmname} key=#{key} message=#{message} log=no")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#show_vm_status(vmname) ⇒ Object

show_vm_status, given a vmname return the operational status of the vm



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 128

def show_vm_status(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("show vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/ Status = /)
            current[:vmstatus]=line.split('=')[1].strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#start_vm(vmname) ⇒ Object

start_vm, given a vmname issue a start request



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 155

def start_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("start vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#stop_vm(vmname) ⇒ Object

stop_vm, given a vmname issue a stop request



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 179

def stop_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("stop vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#suspend_vm(vmname) ⇒ Object

suspend_vm, given a vmname issue a suspend request



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 203

def suspend_vm(vmname)
   current = {:errormsg => "", :status => "", :time => "", :vmstatus => ""}

   conn_opts=get_cli_connection
   Chef::Log.debug("#{conn_opts[:host]}...show vm name=#{vmname}")
   Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh|
      output = ssh.exec!("suspend vm name=#{vmname}")
      output.each_line do |line|
         if line.match(/Status:/)
            current[:status]=line.split[1].strip
         elsif line.match(/Time:/)
            line["Time: "]=""
            current[:time]=line.strip
         elsif line.match(/Error Msg:/)
            line["Error Msg: "]=""
            current[:errormsg]=line.strip
         end
      end
   end
   return current
end

#tcp_test_port(hostname, port) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/chef/knife/BaseOraclevmCommand.rb', line 102

def tcp_test_port(hostname,port)
  tcp_socket = TCPSocket.new(hostname, port)
  readable = IO.select([tcp_socket], nil, nil, 5)
  if readable
    Chef::Log.debug("accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
    true
  else
    false
  end
  rescue Errno::ETIMEDOUT
    false
  rescue Errno::EPERM
    false
  rescue Errno::ECONNREFUSED
    sleep 2
    false
  rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH
    sleep 2
    false
  ensure
    tcp_socket && tcp_socket.close
end