2023-08-10 16:53:25 -04:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2011-12-17 14:14:56 -05:00
|
|
|
require 'optparse'
|
|
|
|
|
|
2012-04-19 16:59:48 -04:00
|
|
|
module VagrantPlugins
|
|
|
|
|
module CommandHalt
|
2012-11-07 00:05:14 -05:00
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2013-11-23 17:00:42 -05:00
|
|
|
def self.synopsis
|
|
|
|
|
"stops the vagrant machine"
|
|
|
|
|
end
|
|
|
|
|
|
2010-08-25 02:10:58 -04:00
|
|
|
def execute
|
2011-12-17 14:14:56 -05:00
|
|
|
options = {}
|
2013-01-29 13:55:40 -05:00
|
|
|
options[:force] = false
|
2011-12-17 14:14:56 -05:00
|
|
|
|
2013-01-29 13:55:40 -05:00
|
|
|
opts = OptionParser.new do |o|
|
2016-05-29 01:06:51 -04:00
|
|
|
o.banner = "Usage: vagrant halt [options] [name|id]"
|
2014-02-08 03:20:50 -05:00
|
|
|
o.separator ""
|
|
|
|
|
o.separator "Options:"
|
2013-01-29 13:55:40 -05:00
|
|
|
o.separator ""
|
2011-12-17 14:14:56 -05:00
|
|
|
|
2013-01-29 13:55:40 -05:00
|
|
|
o.on("-f", "--force", "Force shut down (equivalent of pulling power)") do |f|
|
2011-12-17 14:14:56 -05:00
|
|
|
options[:force] = f
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
|
argv = parse_options(opts)
|
|
|
|
|
return if !argv
|
|
|
|
|
|
|
|
|
|
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
|
2014-05-14 11:28:47 -04:00
|
|
|
with_target_vms(argv, reverse: true) do |vm|
|
2014-05-22 12:35:12 -04:00
|
|
|
vm.action(:halt, force_halt: options[:force])
|
2010-08-25 02:10:58 -04:00
|
|
|
end
|
2012-03-23 11:07:35 -04:00
|
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
|
0
|
2013-01-29 13:55:40 -05:00
|
|
|
end
|
2010-08-25 02:10:58 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|