Class: CORL::Machine::Vagrant
- Inherits:
-
Object
- Object
- CORL::Machine::Vagrant
- Includes:
- CORL::Mixin::Machine::SSH
- Defined in:
- lib/CORL/machine/vagrant.rb
Constant Summary collapse
- @@lock =
Mutex.new
Instance Method Summary collapse
-
#command ⇒ Object
—.
-
#create(options = {}) ⇒ Object
—.
-
#create_image(options = {}) ⇒ Object
—.
-
#created? ⇒ Boolean
—————————————————————————– Checks.
-
#destroy(options = {}) ⇒ Object
—.
-
#download(remote_path, local_path, options = {}, &code) ⇒ Object
—.
-
#env ⇒ Object
—.
-
#exec(commands, options = {}, &code) ⇒ Object
—.
-
#load ⇒ Object
—————————————————————————– Management.
-
#machine_types ⇒ Object
—.
-
#normalize(reload) ⇒ Object
—————————————————————————– Machine plugin interface.
-
#reload(options = {}) ⇒ Object
—.
-
#running? ⇒ Boolean
—.
- #server ⇒ Object
-
#server=(id) ⇒ Object
—.
-
#start(options = {}) ⇒ Object
—.
-
#state ⇒ Object
—.
-
#stop(options = {}) ⇒ Object
—.
-
#terminal(user, options = {}) ⇒ Object
—.
-
#upload(local_path, remote_path, options = {}, &code) ⇒ Object
—.
Methods included from CORL::Mixin::Machine::SSH
#close_ssh_session, #init_ssh_session, #ssh_download, #ssh_exec, #ssh_terminal, #ssh_upload, #ssh_wait_for_ready
Instance Method Details
#command ⇒ Object
53 54 55 56 |
# File 'lib/CORL/machine/vagrant.rb', line 53 def command set_command unless @command @command end |
#create(options = {}) ⇒ Object
108 109 110 111 112 |
# File 'lib/CORL/machine/vagrant.rb', line 108 def create( = {}) super do |config| start_machine(config) end end |
#create_image(options = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/CORL/machine/vagrant.rb', line 157 def create_image( = {}) super do |config| stop = config.delete(:stop, false) # TODO: Decide how to handle versions?? # Timestamps stink since these things are huge (>600MB) box_name = sprintf("%s", node.id).gsub(/\s+/, '-') box_path = File.join(node.network.directory, 'boxes', "#{box_name}.box") box_url = "file://#{box_path}" FileUtils.mkdir_p(File.dirname(box_path)) FileUtils.rm_f(box_path) begin close_ssh_session success = run(:package, config.defaults({ 'package.output' => box_path }), false) node.set_cache_setting(:box, box_name) node.set_cache_setting(:box_url, box_url) if success env.action_runner.run(::Vagrant::Action.action_box_add, { :box_name => box_name, :box_url => box_url, :box_clean => false, :box_force => true, :ui => ::Vagrant::UI::Prefixed.new(env.ui, "box") }) load end rescue => error error(error., { :i18n => false }) success = false end success = run(:up, config) if success && ! stop success end end |
#created? ⇒ Boolean
Checks
23 24 25 |
# File 'lib/CORL/machine/vagrant.rb', line 23 def created? server && state != :not_created end |
#destroy(options = {}) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/CORL/machine/vagrant.rb', line 215 def destroy( = {}) super do |config| # We should handle prompting internally to keep it consistent success = run(:destroy, config.defaults({ :force_confirm_destroy => true })) if success box_name = sprintf("%s", node.id).gsub(/\s+/, '-') found = false # TODO: Figure out box versions. env.boxes.all.each do |info| registered_box_name = info[0] registered_box_version = info[1] registered_box_provider = info[2] if box_name == registered_box_name found = true break end end if found env.action_runner.run(::Vagrant::Action.action_box_remove, { :box_name => box_name, :box_provider => node.machine_type }) box_name = sprintf("%s", node.id).gsub(/\s+/, '-') box_path = File.join(node.network.directory, 'boxes', "#{box_name}.box") Util::Disk.delete(box_path) end end close_ssh_session if success success end end |
#download(remote_path, local_path, options = {}, &code) ⇒ Object
116 117 118 119 120 |
# File 'lib/CORL/machine/vagrant.rb', line 116 def download(remote_path, local_path, = {}, &code) super do |config, success| ssh_download(remote_path, local_path, config, &code) end end |
#env ⇒ Object
60 61 62 63 |
# File 'lib/CORL/machine/vagrant.rb', line 60 def env return command.env if command nil end |
#exec(commands, options = {}, &code) ⇒ Object
132 133 134 135 136 |
# File 'lib/CORL/machine/vagrant.rb', line 132 def exec(commands, = {}, &code) super do |config| ssh_exec(commands, config, &code) end end |
#load ⇒ Object
Management
99 100 101 102 103 104 |
# File 'lib/CORL/machine/vagrant.rb', line 99 def load super do myself.server = plugin_name if command && plugin_name ! plugin_name && @server.nil? ? false : true end end |
#machine_types ⇒ Object
92 93 94 |
# File 'lib/CORL/machine/vagrant.rb', line 92 def machine_types [ :virtualbox, :vmware_fusion, :hyperv ] end |
#normalize(reload) ⇒ Object
Machine plugin interface
15 16 17 18 |
# File 'lib/CORL/machine/vagrant.rb', line 15 def normalize(reload) super myself.plugin_name = node.plugin_name if node end |
#reload(options = {}) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/CORL/machine/vagrant.rb', line 148 def reload( = {}) super do |config| success = run(:reload, config) success = init_ssh_session(true, config.get(:tries, 12), config.get(:sleep_time, 5)) if success end end |
#running? ⇒ Boolean
29 30 31 |
# File 'lib/CORL/machine/vagrant.rb', line 29 def running? server && state == :running end |
#server ⇒ Object
77 78 79 80 81 |
# File 'lib/CORL/machine/vagrant.rb', line 77 def server command load unless @server @server end |
#server=(id) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/CORL/machine/vagrant.rb', line 67 def server=id @server = nil if id.is_a?(String) @server = new_machine(id) elsif ! id.nil? @server = id end end |
#start(options = {}) ⇒ Object
207 208 209 210 211 |
# File 'lib/CORL/machine/vagrant.rb', line 207 def start( = {}) super do |config| start_machine(config) end end |
#state ⇒ Object
85 86 87 88 |
# File 'lib/CORL/machine/vagrant.rb', line 85 def state return server.state.id if server :not_loaded end |
#stop(options = {}) ⇒ Object
199 200 201 202 203 |
# File 'lib/CORL/machine/vagrant.rb', line 199 def stop( = {}) super do |config| create_image(config.import({ :stop => true })) end end |
#terminal(user, options = {}) ⇒ Object
140 141 142 143 144 |
# File 'lib/CORL/machine/vagrant.rb', line 140 def terminal(user, = {}) super do |config| ssh_terminal(user, config) end end |
#upload(local_path, remote_path, options = {}, &code) ⇒ Object
124 125 126 127 128 |
# File 'lib/CORL/machine/vagrant.rb', line 124 def upload(local_path, remote_path, = {}, &code) super do |config, success| ssh_upload(local_path, remote_path, config, &code) end end |