Class: Fission::Command::Info

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

Instance Attribute Summary

Attributes inherited from Fission::Command

#args, #options

Instance Method Summary collapse

Methods inherited from Fission::Command

#command_name, help, #initialize, #ui

Methods included from Fission::CommandHelpers

#incorrect_arguments, #parse_arguments

Constructor Details

This class inherits a constructor from Fission::Command

Instance Method Details

#executeObject



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
# File 'lib/fission/command/info.rb', line 5

def execute
  super
  incorrect_arguments unless @args.count == 1

  vm = VM.new @args.first

  output "name: #{vm.name}"

  guest_os_response = vm.guestos

  if guest_os_response.successful?
    os = guest_os_response.data.empty? ? 'unknown' : guest_os_response.data
    output "os: #{os}"
  else
    output_and_exit "There was an error getting the OS info.  The error was:\n#{guest_os_response.message}", guest_os_response.code
  end

  hardware_response = vm.hardware_info

  if hardware_response.successful?
    hardware_response.data.each_pair do |k, v|
      output "#{k}: #{v}"
    end
  else
    output_and_exit "There was an error getting the hardware info.  The error was:\n#{hardware_response.message}", hardware_response.code
  end

  network_response = vm.network_info

  if network_response.successful?
    network_response.data.each_pair do |int, data|
      data.each_pair do |k, v|
        output "#{int} #{k.gsub(/[-_]/, ' ')}: #{v}"
      end
      output ""
    end
  else
    output_and_exit "There was an error getting the network info.  The error was:\n#{network_response.message}", network_response.code
  end
end

#option_parserObject



46
47
48
49
50
51
52
53
54
# File 'lib/fission/command/info.rb', line 46

def option_parser
  optparse = OptionParser.new do |opts|
    opts.banner = 'Usage: fission info TARGET_VM'
    opts.separator ''
    opts.separator 'Lists known information about TARGET_VM'
  end

  optparse
end

#summaryObject



56
57
58
# File 'lib/fission/command/info.rb', line 56

def summary
  'Show information for a VM'
end