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, #run_with_input, #run_without_bundler, #template, #thor_run

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/builderator/tasks/vagrant.rb', line 16

def self.exit_on_failure?
  true
end

Instance Method Details

#clean(profile = :default) ⇒ Object



128
129
130
131
132
133
# File 'lib/builderator/tasks/vagrant.rb', line 128

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

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

#configure(profile = :default) ⇒ Object



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

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

  Interface.vagrant.write
end

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



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

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']

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

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



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/builderator/tasks/vagrant.rb', line 43

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(' ')

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

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



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

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(' ')

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

#plugins(project = :default) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/builderator/tasks/vagrant.rb', line 136

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)

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/builderator/tasks/vagrant.rb', line 57

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

  invoke Berkshelf, :vendor, [], options
  invoke :rsync, [profile], options

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

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

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



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/builderator/tasks/vagrant.rb', line 99

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

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

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end

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



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/builderator/tasks/vagrant.rb', line 86

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

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

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command, :childprocess => true
  end
end

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



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/builderator/tasks/vagrant.rb', line 73

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

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

    return run(command) if Interface.vagrant.bundled?
    run_without_bundler command
  end
end