Class: VagrantPlugins::OVirtProvider::Action::ResizeDisk

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::ScopedHashOverride
Defined in:
lib/vagrant-ovirt4/action/resize_disk.rb

Overview

Resize the disk if necessary, before VM is running.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ResizeDisk

Returns a new instance of ResizeDisk.



11
12
13
14
# File 'lib/vagrant-ovirt4/action/resize_disk.rb', line 11

def initialize(app, env)
  @logger = Log4r::Logger.new("vagrant_ovirt::action::resize_disk")
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vagrant-ovirt4/action/resize_disk.rb', line 16

def call(env)
  # Is it necessary to resize the disk?
  config = env[:machine].provider_config
  if config.disk_size.nil?
    # Nothing to do
    @app.call(env)
    return
  end

  # Get machine first.
  begin
    machine = OVirtProvider::Util::Collection.find_matching(
      env[:ovirt_compute].servers.all, env[:machine].id.to_s)
  rescue => e
    raise Errors::NoVMError,
      :vm_name => env[:machine].id.to_s
  end

  # Extend disk size if necessary
  begin
    machine.update_volume(
      :id      => machine.volumes.first.id,
      :size    => config.disk_size*1024*1024*1024,
    )
  rescue => e
    raise Errors::UpdateVolumeError,
      :error_message => e.message
  end

  # Wait till all volumes are ready.
  env[:ui].info(I18n.t("vagrant_ovirt4.wait_for_ready_volume"))
  for i in 0..10
    ready = true
    machine = env[:ovirt_compute].servers.get(env[:machine].id.to_s)
    machine.volumes.each do |volume|
      if volume.status != 'ok'
        ready = false
        break
      end
    end
    break if ready
    sleep 2
  end

  if not ready
    raise Errors::WaitForReadyResizedVolumeTimeout
  end

  @app.call(env)
end