Class: Fission::Command::Clone
Instance Attribute Summary
#args, #options
Instance Method Summary
collapse
#command_name, help, #ui
#incorrect_arguments, #parse_arguments
Constructor Details
#initialize(args = []) ⇒ Clone
Returns a new instance of Clone.
5
6
7
8
|
# File 'lib/fission/command/clone.rb', line 5
def initialize(args=[])
super
@options.start = false
end
|
Instance Method Details
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
|
# File 'lib/fission/command/clone.rb', line 10
def execute
super
incorrect_arguments unless @args.count > 1
source_vm = Fission::VM.new @args.first
target_vm = Fission::VM.new @args[1]
clone_response = VM.clone source_vm.name, target_vm.name
if clone_response.successful?
output ''
output 'Clone complete!'
if @options.start
output "Starting '#{target_vm.name}'"
start_response = target_vm.start
if start_response.successful?
output "VM '#{target_vm.name}' started"
else
output_and_exit "There was an error starting the VM. The error was:\n#{start_response.message}", start_response.code
end
end
else
output_and_exit "There was an error cloning the VM. The error was:\n#{clone_response.message}", clone_response.code
end
end
|
#option_parser ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/fission/command/clone.rb', line 39
def option_parser
optparse = OptionParser.new do |opts|
opts.banner = "Usage: fission clone SOURCE_VM TARGET_VM [OPTIONS]"
opts.separator ''
opts.separator 'Clones SOURCE_VM to a new VM (TARGET_VM).'
opts.separator ''
opts.separator 'OPTIONS:'
opts.on '--start', 'Start the VM after cloning' do
@options.start = true
end
end
optparse
end
|
54
55
56
|
# File 'lib/fission/command/clone.rb', line 54
def summary
'Clone a VM'
end
|