Class: Fission::Command::Suspend
Instance Attribute Summary
#args, #options
Instance Method Summary
collapse
#command_name, help, #ui
#incorrect_arguments, #parse_arguments
Constructor Details
#initialize(args = []) ⇒ Suspend
Returns a new instance of Suspend.
5
6
7
8
|
# File 'lib/fission/command/suspend.rb', line 5
def initialize(args=[])
super
@options.all = false
end
|
Instance Method Details
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fission/command/suspend.rb', line 10
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
|
#option_parser ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/fission/command/suspend.rb', line 42
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
|
57
58
59
|
# File 'lib/fission/command/suspend.rb', line 57
def summary
'Suspend a VM'
end
|
#vms_to_suspend ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/fission/command/suspend.rb', line 26
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
|