Sha256: 4ec7525f09cdb91f8daf4ea7c4294dbba64c487099a4bfc7494f13350d01a826

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

require "json"

module Vagrant
  module Action
    module Builtin
      class CleanupDisks
        # Removes any attached disks no longer defined in a Vagrantfile config
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::action::builtin::disk")
        end

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

          # Call into providers machine implementation for disk management
          disk_meta_file = read_disk_metadata(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

        def read_disk_metadata(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

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

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

          @_disks
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/action/builtin/cleanup_disks.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/action/builtin/cleanup_disks.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/action/builtin/cleanup_disks.rb