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
|
# File 'lib/fission.old/command/snapshot_create.rb', line 9
def execute
unless @args.count == 2
Fission.ui.output self.class.help
Fission.ui.output ""
Fission.ui.output_and_exit "Incorrect arguments for snapshot create command", 1
end
vm_name, snap_name = @args.take 2
vm = Fission::VM.new vm_name
unless vm.exists?
Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1
end
unless vm.running?
Fission.ui.output "VM '#{vm_name}' is not running"
Fission.ui.output_and_exit 'A snapshot cannot be created unless the VM is running', 1
end
if vm.snapshots.include? snap_name
Fission.ui.output_and_exit "VM '#{vm_name}' already has a snapshot named '#{snap_name}'", 1
end
Fission.ui.output "Creating snapshot"
task = vm.create_snapshot(snap_name)
if task.successful?
Fission.ui.output "Snapshot '#{snap_name}' created"
else
Fission.ui.output_and_exit "There was an error creating the snapshot. The error was:\n#{task.output}", task.code
end
end
|