Class: Chef::Knife::OvmcliVmState
- Inherits:
-
BaseOraclevmCommand
- Object
- Chef::Knife
- BaseOraclevmCommand
- Chef::Knife::OvmcliVmState
- Defined in:
- lib/chef/knife/ovmcli_vm_state.rb
Overview
Manage power state of a virtual machine
Instance Method Summary collapse
Methods inherited from BaseOraclevmCommand
#add_vdisk, #add_vnic, #clone_vm, #create_vdisk, #delete_vdisk, #delete_vm, #edit_vm, #fatal_exit, #get_cli_connection, get_common_options, #get_config, #get_host, #get_password, #get_vm, #kill_vm, #list_serverpool, #list_tag, #list_vm, #migrate_vm, #remove_vdisk, #restart_vm, #resume_vm, #send_message, #show_vm_status, #start_vm, #stop_vm, #suspend_vm, #tcp_test_port
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/chef/knife/ovmcli_vm_state.rb', line 25 def run $stdout.sync = true vmname = @name_args[0] if vmname.nil? show_usage ui.fatal("You must specify a virtual machine name") exit 1 end current=show_vm_status(vmname) Chef::Log.debug("Status = #{current[:status]}. Time = #{current[:time]}. VM Status = #{current[:vmstatus]}.") state=get_config(:state) if current[:status]=="Success" if not state puts "Virtual machine #{vmname} is in state #{current[:vmstatus]}" else case current[:vmstatus] when 'Running' case state when 'on' puts "Virtual machine #{vmname} was already powered on" when 'off' result=stop_vm(vmname) puts "Power off virtual machine #{vmname} : #{result[:status]}" when 'suspend' result=suspend_vm(vmname) puts "Suspend virtual machine #{vmname} : #{result[:status]}" when 'restart' result=restart_vm(vmname) puts "Restart virtual machine #{vmname} : #{result[:status]}" when 'resume' puts "Cannot Resume virtual machine #{vmname} as it is on" when 'kill' result=kill_vm(vmname) puts "Kill virtual machine #{vmname} : #{result[:status]}" else show_usage end when 'Stopped' case state when 'on' result=start_vm(vmname) puts "Power on virtual machine #{vmname} : #{result[:status]}" when 'off' puts "virtual machine #{vmname} was already off" when 'suspend' puts "Cannot Suspend virtual machine #{vmname} as it is off" when 'restart' puts "Cannot Restrt virtual machine #{vmname} as it is off" when 'resume' puts "Cannot Resume virtual machine #{vmname} as it is off" when 'kill' puts "Cannot Kill virtual machine #{vmname} as it is off" else show_usage end when 'Stopping' case state when 'on' puts "Cannot power on virtual machine #{vmname} as it is Stopping" when 'off' puts "Cannot power off virtual machine #{vmname} as it is Stopping" when 'suspend' puts "Cannot Suspend virtual machine #{vmname} as it is Stopping" when 'restart' puts "Cannot Restrt virtual machine #{vmname} as it is Stopping" when 'resume' puts "Cannot Resume virtual machine #{vmname} as it is Stopping" when 'kill' puts "Cannot Kill virtual machine #{vmname} as it is Stopping" else show_usage end when 'Suspended' case state when 'on' puts "Cannot Power on virtual machine #{vmname} as it is suspended" when 'off' puts "Cannot Power off virtual machine #{vmname} as it is suspended" when 'suspend' puts "Cannot Suspend virtual machine #{vmname} as it is already suspended" when 'restart' puts "Cannot Restart virtual machine #{vmname} as it is suspended" when 'resume' result=resume_vm(vmname) puts "Resume virtual machine #{vmname} : #{result[:status]}" when 'kill' result=kill_vm(vmname) puts "Killing virtual machine #{vmname} : #{result[:status]}" else show_usage end else puts "I don't know what a state of #{current[:vmstatus]} is on #{vmname}" end end else puts "Call to OVM CLI Failed with #{current[:errormsg]}" end end |