Class: VagrantPlugins::Rackspace::Action::CreateImage

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-rackspace/action/create_image.rb

Overview

Creates an Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ CreateImage

Returns a new instance of CreateImage.



15
16
17
# File 'lib/vagrant-rackspace/action/create_image.rb', line 15

def initialize(app, env)
  @app, @env = app, env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



13
14
15
# File 'lib/vagrant-rackspace/action/create_image.rb', line 13

def env
  @env
end

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/vagrant-rackspace/action/create_image.rb', line 19

def call(env)
  env[:ui].info(I18n.t("vagrant_rackspace.creating_image"))

  server = env[:rackspace_compute].servers.get(env[:machine].id)

  config     = env[:machine].provider_config          
  image_name = config.server_name || env[:machine].name

  image = server.create_image(image_name)

  retryable(:on => Fog::Errors::TimeoutError, :tries => 200) do
    # If we're interrupted don't worry about waiting
    next if env[:interrupted]

    env[:ui].clear_line
    env[:ui].report_progress(image.progress, 100, false)
    
    begin
      image.wait_for(5) { ready? }
    rescue RuntimeError => e
      # If we don't have an error about a state transition, then
      # we just move on.
      raise if e.message !~ /should have transitioned/
      raise Errors::CreateBadState, :state => server.state
    end            
  end

  env[:ui].info(I18n.t("vagrant_rackspace.image_ready"))

  @app.call(env)
end