Class: Fission::Command::Start

Inherits:
Fission::Command show all
Defined in:
lib/fission.old/command/start.rb

Instance Attribute Summary

Attributes inherited from Fission::Command

#args, #options

Instance Method Summary collapse

Methods inherited from Fission::Command

help

Constructor Details

#initialize(args = []) ⇒ Start

Returns a new instance of Start


5
6
7
8
# File 'lib/fission.old/command/start.rb', line 5

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

Instance Method Details

#executeObject


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
# File 'lib/fission.old/command/start.rb', line 10

def execute
  option_parser.parse! @args

  if @args.empty?
    Fission.ui.output self.class.help
    Fission.ui.output ""
    Fission.ui.output_and_exit "Incorrect arguments for start command", 1
  end

  vm_name = @args.first

  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

  if vm.running?
    Fission.ui.output ''
    Fission.ui.output_and_exit "VM '#{vm_name}' is already running", 0
  end

  Fission.ui.output "Starting '#{vm_name}'"
  start_args = {}

  if @options.headless

    if Fission::Fusion.running?
      Fission.ui.output 'It looks like the Fusion GUI is currently running'
      Fission.ui.output 'A VM cannot be started in headless mode when the Fusion GUI is running'
      Fission.ui.output_and_exit "Exit the Fusion GUI and try again", 1
    else
      start_args[:headless] = true
    end
  end

  task = vm.start(start_args)

  if task.successful?
    Fission.ui.output "VM '#{vm_name}' started"
  else
    Fission.ui.output_and_exit "There was a problem starting the VM.  The error was:\n#{task.output}", task.code
  end
end

#option_parserObject


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fission.old/command/start.rb', line 55

def option_parser
  optparse = OptionParser.new do |opts|
    opts.banner = "\nstart usage: fission start vm [options]"

    opts.on '--headless', 'Start the VM in headless mode (i.e. no Fusion GUI console)' do
      @options.headless = true
    end
  end

  optparse
end