Class: VagrantPlugins::Qubes::Action::Destroy

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

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ Destroy

Returns a new instance of Destroy.



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

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

Instance Method Details

#call(env) ⇒ Object



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

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

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

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

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

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

  if env[:machine_state].to_s == 'not_created'
    env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message',
      message: 'Cannot destroy in state ' + env[:machine_state].to_s)
  elsif env[:machine_state].to_s != 'halted'
    raise Errors::GeneralError,
    message: 'VM should have been halted before destroy'
  else
    command = 'qrexec-client-vm dom0 vagrant_destroy+' + 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.vagrant_qubes_message',
      message: env[:machine].config.vm.hostname + ' Removed')
  end
end