File: clone.rb

package info (click to toggle)
ruby-fission 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 4,664; makefile: 10
file content (60 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (3)
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
module Fission
  class Command
    class Clone < Command

      def initialize(args=[])
        super
        @options.start = false
      end

      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

      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

      def summary
        'Clone a VM'
      end

    end
  end
end