Class: Vagrant::Action::Builtin::CleanupDisks

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/builtin/cleanup_disks.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ CleanupDisks

Removes any attached disks no longer defined in a Vagrantfile config


8
9
10
11
# File 'lib/vagrant/action/builtin/cleanup_disks.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant::action::builtin::disk")
end

Instance Method Details

#call(env) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant/action/builtin/cleanup_disks.rb', line 13

def call(env)
  machine = env[:machine]
  defined_disks = get_disks(machine, env)

  # Call into providers machine implementation for disk management
  disk_meta_file = (machine)

  if !disk_meta_file.empty?
    if machine.provider.capability?(:cleanup_disks)
      machine.provider.capability(:cleanup_disks, defined_disks, disk_meta_file)
    else
      env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported",
                           provider: machine.provider_name))
    end
  end

  # Continue On
  @app.call(env)
end

#get_disks(machine, env) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/vagrant/action/builtin/cleanup_disks.rb', line 45

def get_disks(machine, env)
  return @_disks if @_disks

  @_disks = []
  @_disks = machine.config.vm.disks

  @_disks
end

#read_disk_metadata(machine) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant/action/builtin/cleanup_disks.rb', line 33

def (machine)
  meta_file = machine.data_dir.join("disk_meta")
  if File.file?(meta_file)
    disk_meta = JSON.parse(meta_file.read)
  else
    @logger.info("No previous disk_meta file defined for guest #{machine.name}")
    disk_meta = {}
  end

  return disk_meta
end