#!/usr/bin/env ruby # require 'csv' headers = [ 'timestamp', # is a Unix timestamp in UTC of when the message was printed. 'target', # is the target of the following output. This is empty if the message is related to Vagrant globally. Otherwise, this is generally a machine name so you can relate output to a specific machine when multi-VM is in use. 'type', # is the type of machine-readable message being outputted. There are a set of standard types which are covered later. 'data', # is zero or more comma-separated values associated with the prior type. The exact amount and meaning of this data is type-dependent, so you must read the documentation associated with the type to understand fully. ] types = [ 'box-name', # Name of a box installed into Vagrant. 'box-provider', # Provider for an installed box. 'cli-command', # A subcommand of vagrant that is available. 'error-exit', # An error occurred that caused Vagrant to exit. This contains that error. Contains two data elements: type of error, error message. 'provider-name', # The provider name of the target machine. targeted 'state', # The state ID of the target machine. targeted 'state-human-long', # Human-readable description of the state of the machine. This is the long version, and may be a paragraph or longer. targeted 'state-human-short', # Human-readable description of the state of the machine. This is the short version, limited to at most a sentence. targeted ] module Vagrant Box = Struct.new(:name, :provider) State = Struct.new(:id, :short, :long) Error = Struct.new(:type, :message) class VM attr_accessor :box, :state, :command, :provider, :error def initialize(target) @target = target @box = Box.new @state = State.new end end end virtual_machines = Hash.new do |vms, target| vms[target] = Vagrant::VM.new(target) end CSV.new(ARGF, headers: headers).each do |message| vm = virtual_machines[message['target']] data = message['data'].split('%!(VAGRANT_COMMA)') case message['type'] when 'box-name' vm.box.name = data when 'box-provider' vm.box.provider = data when 'state' vm.state.id = data when 'state-human-long' vm.state.long = data when 'state-human-short' vm.state.short = data when 'cli-command' vm.command = data when 'error-exit' vm.error = Vagrant::Error.new(data[0], data[1]) when 'provider-name' vm.provider = data else raise "Unknown type: #{message['type']}" end end puts virtual_machines.map{|name, vm| name} #puts virtual_machines.map{|name, vm| "#{name}: #{vm.state.short}"}