-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: ProvisionerCleanup task to run cleanup on provisioners
- Loading branch information
Showing
9 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Vagrant | ||
module Action | ||
module Builtin | ||
module MixinProvisioners | ||
# This returns all the instances of the configured provisioners. | ||
# This is safe to call multiple times since it will cache the results. | ||
# | ||
# @return [Array<Provisioner>] | ||
def provisioner_instances | ||
return @_provisioner_instances if @_provisioner_instances | ||
|
||
# Make the mapping that'll keep track of provisioner => type | ||
@_provisioner_types = {} | ||
|
||
# Get all the configured provisioners | ||
@_provisioner_instances = env[:machine].config.vm.provisioners.map do |provisioner| | ||
# Instantiate the provisioner | ||
klass = Vagrant.plugin("2").manager.provisioners[provisioner.name] | ||
result = klass.new(env[:machine], provisioner.config) | ||
|
||
# Store in the type map so that --provision-with works properly | ||
@_provisioner_types[result] = provisioner.name | ||
|
||
# Return the result | ||
result | ||
end | ||
|
||
return @_provisioner_instances | ||
end | ||
|
||
# This will return a mapping of a provisioner instance to its | ||
# type. | ||
def provisioner_type_map | ||
# Call this in order to initial the map if it hasn't been already | ||
provisioner_instances | ||
|
||
# Return the type map | ||
@_provisioner_types | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "log4r" | ||
|
||
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 | ||
def initialize(app, env) | ||
@app = app | ||
@logger = Log4r::Logger.new("vagrant::action::builtin::provision_cleanup") | ||
end | ||
|
||
def call(env) | ||
# Ask the provisioners to modify the configuration if needed | ||
provisioners.each do |p| | ||
env[:ui].info(I18n.t( | ||
"vagrant.provisioner_cleanup", | ||
name: provisioner_type_map[p].to_s)) | ||
p.cleanup | ||
end | ||
|
||
# Continue, we need the VM to be booted. | ||
@app.call(env) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters