Class: VagrantPlugins::PersistentStorage::Action::ManageAll

Inherits:
Object
  • Object
show all
Includes:
ManageStorage
Defined in:
lib/vagrant-persistent-storage/action/manage_storage.rb

Instance Method Summary collapse

Methods included from ManageStorage

#manage_volumes, #populate_template, #run_disk_operations

Constructor Details

#initialize(app, env) ⇒ ManageAll

Returns a new instance of ManageAll.



11
12
13
14
15
16
17
# File 'lib/vagrant-persistent-storage/action/manage_storage.rb', line 11

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @global_env = @machine.env
  @provider = @machine.provider_name
  @logger = Log4r::Logger.new('vagrant::persistent_storage::action::manage_storage')
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-persistent-storage/action/manage_storage.rb', line 19

def call(env)
  # skip if machine is not running and the action is destroy, halt or suspend
  return @app.call(env) if @machine.state.id != :running && [:destroy, :halt, :suspend].include?(env[:machine_action])
  # skip if machine is not saved and the action is resume
  return @app.call(env) if @machine.state.id != :saved && env[:machine_action] == :resume
  # skip if machine is powered off and the action is resume
  return @app.call(env) if @machine.state.id == :poweroff && env[:machine_action] == :resume
  # skip if machine is powered off and the action is resume
  return @app.call(env) if @machine.state.id == :saved && env[:machine_action] == :resume
  
  return @app.call(env) unless env[:machine].config.persistent_storage.enabled?
  return @app.call(env) unless env[:machine].config.persistent_storage.manage?
  @logger.info '** Managing Persistent Storage **'

  env[:ui].info I18n.t('vagrant_persistent_storage.action.manage_storage')
  machine = env[:machine]
  manage_volumes(machine)

  @app.call(env)

end