Class: VagrantPlugins::Qubes::Action::OpenFirewall

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-qubes/action/openfirewall.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ OpenFirewall

Returns a new instance of OpenFirewall.



9
10
11
12
# File 'lib/vagrant-qubes/action/openfirewall.rb', line 9

def initialize(app, _env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_qubes::action::openfirewall')
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
# File 'lib/vagrant-qubes/action/openfirewall.rb', line 14

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

#openfirewall(env) ⇒ Object



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/vagrant-qubes/action/openfirewall.rb', line 19

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

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

  if env[:machine_state].to_s == 'running'
    vagrant_ip = Socket.ip_address_list.find {|a| a.ipv4? ? !(a.ipv4_loopback?) : !(a.ipv6_loopback?) }

    env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message',
      message: 'vagrant ip ' + vagrant_ip.ip_address.to_s)

    command = 'echo "' + vagrant_ip.ip_address.to_s\
      + '" | qrexec-client-vm dom0 vagrant_openfw+' + 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
  else
    raise Errors::GeneralError,
    message: 'VM not running so cannot edit firewall policy'
  end
end