Sha256: 4d93d2c3208b160b9899a976e70acb764153bca7f6179f9c4f6fe5128a326c53

Contents?: true

Size: 1.56 KB

Versions: 58

Compression:

Stored size: 1.56 KB

Contents

require "log4r"

require_relative "mixin_provisioners"

module Vagrant
  module Action
    module Builtin
      # This action will run the cleanup methods on provisioners and should
      # be used as part of any Destroy action.
      class ProvisionerCleanup
        include MixinProvisioners

        def initialize(app, env, place=nil)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::action::builtin::provision_cleanup")

          place ||= :after
          @place = place.to_sym
        end

        def call(env)
          do_cleanup(env) if @place == :before

          # Continue, we need the VM to be booted.
          @app.call(env)

          do_cleanup(env) if @place == :after
        end

        def do_cleanup(env)
          type_map = provisioner_type_map(env)

          # Ask the provisioners to modify the configuration if needed
          provisioner_instances(env).each do |p, _|
            name = type_map[p].to_s

            # Check if the subclass defined a cleanup method. The parent
            # provisioning class defines a `cleanup` method, so we cannot use
            # `respond_to?` here. Instead, we have to check if _this_ instance
            # defines a cleanup task.
            if p.public_methods(false).include?(:cleanup)
              env[:ui].info(I18n.t("vagrant.provisioner_cleanup",
                name: name,
              ))
              p.cleanup
            else
              @logger.debug("Skipping cleanup tasks for `#{name}' - not defined")
            end
          end
        end
      end
    end
  end
end

Version data entries

58 entries across 54 versions & 6 rubygems

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