Class: Fission::Command::Stop

Inherits:
Fission::Command show all
Defined in:
lib/fission.old/command/stop.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 = []) ⇒ Stop


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

def initialize(args=[])
  super
end

Instance Method Details

#executeObject


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

def execute
  unless @args.count == 1
    Fission.ui.output self.class.help
    Fission.ui.output ""
    Fission.ui.output_and_exit "Incorrect arguments for stop command", 1
  end

  vm_name = @args.first
  vm = Fission::VM.new vm_name

  unless vm.exists? 
    Fission.ui.output_and_exit "VM #{vm_name} does not exist at (#{vm.path})", 1
  end


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

  Fission.ui.output "Stopping '#{vm_name}'"
  task  = vm.stop

  if task.successful?
    Fission.ui.output "VM '#{vm_name}' stopped"
  else
    Fission.ui.output_and_exit "There was an error stopping the VM.  The error was:\n#{response.output}", response.code
  end
end

#option_parserObject


39
40
41
42
43
44
45
# File 'lib/fission.old/command/stop.rb', line 39

def option_parser
  optparse = OptionParser.new do |opts|
    opts.banner = "\nstop usage: fission stop vm"
  end

  optparse
end