Sha256: 8f5572e19d287b034b19f8d2d12a1c2b38090e2773e57b924227edc2a948c4d3

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

require 'log4r'
require 'open3'

module VagrantPlugins
  module Qubes
    module Action
      class Boot
        def initialize(app, _env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_qubes::action::boot')
        end

        def call(env)
          boot(env)
          @app.call(env)
        end

        def boot(env)
          @logger.info('vagrant-qubes, boot: start...')

          # Get config
          machine = env[:machine]
          config = env[:machine].provider_config

          @logger.info("vagrant-qubes, boot: machine id: #{machine.id}")
          @logger.info('vagrant-qubes, boot: current state: '\
                       "#{env[:machine_state]}")

          if env[:machine_state].to_s == 'running'
            env[:ui].info I18n.t('vagrant_qubes.already_running')
          elsif env[:machine_state].to_s == 'not_created'
            env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message',
              message: 'Cannot boot in state' + env[:machine_state].to_s)
          else
            command = 'qrexec-client-vm dom0 vagrant_start+' + env[:machine].config.vm.hostname
            stdout, stderr, status = Open3.capture3(command)
            if status != 0
              raise Errors::QRExecError,
                    message: 'qrexec failed with status' + status.to_s
            end
            env[:ui].info I18n.t('vagrant_qubes.states.running.long')
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-qubes-0.0.5 lib/vagrant-qubes/action/boot.rb
vagrant-qubes-0.0.4 lib/vagrant-qubes/action/boot.rb
vagrant-qubes-0.0.3 lib/vagrant-qubes/action/boot.rb
vagrant-qubes-0.0.2 lib/vagrant-qubes/action/boot.rb
vagrant-qubes-0.0.1 lib/vagrant-qubes/action/boot.rb