Class: VagrantPlugins::WindowsDomain::LeaveDomain
- Inherits:
-
Object
- Object
- VagrantPlugins::WindowsDomain::LeaveDomain
- Includes:
- VagrantPlugins::WindowsDomain
- Defined in:
- lib/vagrant-windows-domain/action/leave_domain.rb
Overview
Leave a domain on a ‘vagrant destroy`.
This is an Action middleware component that will detect the state of the machine - and any corresponding configuration and act accordingly. This function accepts user input and will halt the execution of proceeding middleware if the user chooses to cancel.
Also note that it will interfere with a ‘vagrant destroy` user input to avoid duplicate “are you sure..” messages.
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#config ⇒ Object
Returns the value of attribute config.
-
#env ⇒ Object
Returns the value of attribute env.
-
#machine ⇒ Object
Returns the value of attribute machine.
-
#provisioner ⇒ Object
Returns the value of attribute provisioner.
Instance Method Summary collapse
-
#call(env) ⇒ Object
The middleware method that is invoked automatically by the Plugin ecosystem.
-
#initialize(app, env) ⇒ LeaveDomain
constructor
A new instance of LeaveDomain.
Methods included from VagrantPlugins::WindowsDomain
Constructor Details
#initialize(app, env) ⇒ LeaveDomain
Returns a new instance of LeaveDomain.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 25 def initialize(app, env) @logger = Log4r::Logger.new("vagrant::provisioners::vagrant_windows_domain") @logger.debug("Initialising WindowsDomain plugin on destroy action") @app = app @env = env @machine = env[:machine] @machine.config.vm.provisioners.each do |prov| @config = prov.config if prov.config.is_a?(VagrantPlugins::WindowsDomain::Config) end @provisioner = VagrantPlugins::WindowsDomain::Provisioner.new(@machine, @config) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
22 23 24 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 22 def app @app end |
#config ⇒ Object
Returns the value of attribute config.
20 21 22 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 20 def config @config end |
#env ⇒ Object
Returns the value of attribute env.
21 22 23 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 21 def env @env end |
#machine ⇒ Object
Returns the value of attribute machine.
19 20 21 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 19 def machine @machine end |
#provisioner ⇒ Object
Returns the value of attribute provisioner.
23 24 25 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 23 def provisioner @provisioner end |
Instance Method Details
#call(env) ⇒ Object
The middleware method that is invoked automatically by the Plugin ecosystem. Expected to call the next middleware component in the chain if action should proceed.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vagrant-windows-domain/action/leave_domain.rb', line 41 def call(env) if @config and @config.domain != nil if [:not_created].include? @machine.state.id @logger.debug("Machine not created, nothing to do") elsif [:running].include? @machine.state.id if !(env[:force_confirm_box_remove] || env[:force_confirm_destroy]) answer = @machine.env.ui.ask("Are you sure you want to destroy this machine and disconnect from #{@config.domain}? (y/n)") return unless answer.downcase == 'y' # Bail out of destroy and prevent middleware from continuing on end env[:force_confirm_destroy] = true # Prevent the popup dialog again @logger.debug("Valid configuration detected, triggering leave domain action") @provisioner.destroy else @machine.env.ui.say(:warn, "Machine is currently not running. To properly leave the #{@config.domain} network the machine needs to be running and connected to the network in which it was provisioned. Please run `vagrant up` and then `vagrant destroy`.\n") if !(env[:force_confirm_box_remove] || env[:force_confirm_destroy]) answer = @machine.env.ui.ask("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{@config.domain}' network? If so, type 'destroy'") return unless answer.downcase == 'destroy' # Bail out of destroy and prevent middleware from continuing on end # OK, we're being naughty and letting the rest of the middleware do their things (i.e. destroy the machine, and such) env[:force_confirm_destroy] = true # Prevent the popup dialog again @logger.debug("Force destroying this machine and not leaving the domain #{@config.domain}") @machine.env.ui.say(:warn, "Force destroying this machine and not leaving the domain #{@config.domain}. May FSM have mercy on your soul.") end else @logger.debug("No configuration detected, not leaving any domain") end # Continue the rest of the middleware actions @app.call(env) end |