2013-07-23 1 views
1

"vm globbing"을 비활성화하는 방법이 있습니까? 즉, 두 개의 VM이 있는데 :dev:prod이 Vagrant 파일에 정의되어 있고 vagrant reload을 실행하는 경우, 상자를 지정하지 않았기 때문에 Vagrant가 명령 수행을 거부하기를 원합니다.상자의 방랑자 globbing 사용 안 함

Vagrant.configure("2") do |config| 
    config.berkshelf.enabled = true 

    config.vm.define :dev do |dev| 
    end 

    config.vm.define :prod do |prod| 
    end 
end 

답변

2

당신은 당신이 VM을 요구하려는 행동과 VALIDATE_ACTIONS를 업데이트하여 Vagrantfile의 맨 위에 다음을 추가 할 수 있습니다 다음과 같이

는 clarities을 위해, 내 설정이다. 단 하나의 VM 만 정의되어있는 경우에도 vagrant destroy (지정된 VM없이) 명령이 허용됩니다.

# Actions to validate 
VALIDATE_ACTIONS = [ 'halt', 'destroy' ] 

# Override default actions to check machine list 
class ValidateCommand < Vagrant.plugin(2, :command) 
    class << self 
    attr_accessor :delegate_action 
    end 

    def initialize argv, env 
    super(argv, env) 
    @argv = argv 
    end 

    def execute 
    vms = [] 
    with_target_vms(@argv, :reverse => true) do | machine | 
     vms << machine 
    end 
    if vms.size > 1 
     puts 'Please specify a single VM' 
     1 
    else 
     with_target_vms(@argv, :reverse => true) do | machine | 
     machine.action(ValidateCommand.delegate_action) 
     end 
     0 
    end 
    end 
end 

# Wrap validate command in plugin and invoke for overridden actions 
class ValidatePlugin < Vagrant.plugin(2) 
    name "Validate" 
    VALIDATE_ACTIONS.each do | action | 
    command action do 
     ValidateCommand.delegate_action = action 
     ValidateCommand 
    end 
    end 
end 
+0

이것은 효과가있었습니다. 고맙습니다! – RubberDucky

+0

굉장합니다. 그것을 듣고 기뻐. – pauljm

+0

매우 유용합니다 !!!!!, thanks !!! – Robert