Class: VagrantPlugins::Qubes::Action::ReadState

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

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ ReadState

Returns a new instance of ReadState.



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

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  env[:machine_state] = read_state(env)
  @app.call(env)
end

#read_state(env) ⇒ Object



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
# File 'lib/vagrant-qubes/action/read_state.rb', line 18

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

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

  #return :not_created if machine.id.to_i < 1

  state = ''

  command = 'qrexec-client-vm dom0 vagrant_list+' + env[:machine].config.vm.hostname
#          env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message',
#            message: command)
  stdout, stderr, status = Open3.capture3(command)
  stdout.each_line do |line|
    fields = line.split('|')
    state = fields.at(1)
#            env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message',
#              message: 'state ' + state)
  end

  case state
  when 'Running'
    return :running
  when 'Halted'
    return :halted
  when 'Transient'
    return :transient
  else        
    return :not_created
  end
end