File: info.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 (62 lines) | stat: -rw-r--r-- 1,733 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
61
62
module Fission
  class Command
    class Info < Command

      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

      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

      def summary
        'Show information for a VM'
      end

    end
  end
end