1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
module Fission
class Command
class Suspend < Command
def initialize(args=[])
super
@options.all = false
end
def execute
super
incorrect_arguments if @args.count != 1 && !@options.all
vms_to_suspend.each do |vm|
output "Suspending '#{vm.name}'"
response = vm.suspend
if response.successful?
output "VM '#{vm.name}' suspended"
else
output_and_exit "There was an error suspending the VM. The error was:\n#{response.message}", response.code
end
end
end
def vms_to_suspend
if @options.all
response = VM.all_running
if response.successful?
vms = response.data
else
output_and_exit "There was an error getting the list of running VMs. The error was:\n#{response.message}", response.code
end
else
vms = [ VM.new(@args.first) ]
end
vms
end
def option_parser
optparse = OptionParser.new do |opts|
opts.banner = "Usage: fission suspend [TARGET_VM | --all]"
opts.separator ''
opts.separator 'Suspend TARGET_VM or all VMs.'
opts.separator ''
opts.separator 'OPTIONS:'
opts.on '--all', 'Suspend all running VMs' do
@options.all = true
end
end
optparse
end
def summary
'Suspend a VM'
end
end
end
end
|