Class: Builderator::Tasks::Vagrant

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/builderator/tasks/vagrant.rb

Overview

Wrap vagrant commands

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Thor::Actions

#run_with_input, #template

Class Method Details

.exit_on_failure? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/builderator/tasks/vagrant.rb', line 14

def self.exit_on_failure?
  true
end

Instance Method Details

#clean(profile = :default) ⇒ Object



105
106
107
108
109
110
# File 'lib/builderator/tasks/vagrant.rb', line 105

def clean(profile = :default)
  destroy(profile)

  remove_dir Interface.vagrant.directory.join('.vagrant')
  remove_file Interface.vagrant.source
end

#configure(profile = :default) ⇒ Object



19
20
21
22
23
24
# File 'lib/builderator/tasks/vagrant.rb', line 19

def configure(profile = :default)
  Config.profile.use(profile)
  invoke Tasks::Version, :current, [], options

  Interface.vagrant.write
end

#destroy(profile = :default, *args) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/builderator/tasks/vagrant.rb', line 91

def destroy(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " destroy #{args.join(' ')}"
    command << ' -f' if options['force']

    run command
  end
end

#ec2(profile = :default, *args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/builderator/tasks/vagrant.rb', line 40

def ec2(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " up --provider=#{Config.profile.current.vagrant.ec2.provider} "
    command << args.join(' ')

    run command
  end
end

#local(profile = :default, *args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/builderator/tasks/vagrant.rb', line 27

def local(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " up --provider=#{Config.profile.current.vagrant.local.provider} "
    command << args.join(' ')

    run command
  end
end

#plugins(project = :default) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/builderator/tasks/vagrant.rb', line 113

def plugins(project = :default)
  if Interface.vagrant.bundled?
    say 'Vagrant is already bundled. Required plugins are already part of the bundle as well'
    return
  end

  Config.generator.project.use(project)
  Config.generator.project.current.vagrant.plugin.each do |pname, plugin|
    command = Interface.vagrant.command
    command << " plugin install #{ pname }"
    command << " --plugin-version #{ plugin.version }" if plugin.has?(:version)

    run command
  end
end

#provision(profile = :default, *args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/builderator/tasks/vagrant.rb', line 53

def provision(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " provision #{args.join(' ')}"

    run command
  end
end

#ssh(profile = :default, *args) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/builderator/tasks/vagrant.rb', line 77

def ssh(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " ssh #{args.join(' ')}"

    ## Connect to subprocesses STDIO
    exec(command)
  end
end

#status(profile = :default, *args) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/builderator/tasks/vagrant.rb', line 65

def status(profile = :default, *args)
  invoke :configure, [profile], options

  inside Interface.vagrant.directory do
    command = Interface.vagrant.command
    command << " status #{args.join(' ')}"

    run command
  end
end