Class: VagrantPlugins::MongoDb::Commands::Initiate

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-mongodb/commands/initiate.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagrant-mongodb/commands/initiate.rb', line 6

def execute
  options = {}
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant mongodb initiate [vm-name]'
    o.separator ''

    o.on('--provider provider', String,
      'Initiates replica set with the specific provider.') do |provider|
      options[:provider] = provider
    end
  end

  argv = parse_options(opts)
  options[:provider] ||= @env.default_provider
  options[:single_target] = true

  with_target_vms(argv, options) do |machine|

    if machine.config.mongodb
      machine.config.mongodb.auto_initiate = true

      env = { :machine => machine, :ui => @env.ui }
      callable = Vagrant::Action::Builder.new.tap do |b|
        b.use Vagrant::Action::Builtin::ConfigValidate
        b.use Actions::Initiate
      end

      @env.action_runner.run(callable, env)
    end
  end

  0
end