Class: VagrantAWS::Action::Create
- Inherits:
-
Object
- Object
- VagrantAWS::Action::Create
- Defined in:
- lib/vagrant-aws/action/create.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Create
constructor
A new instance of Create.
- #recover(env) ⇒ Object
- #server_definition(config) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ Create
Returns a new instance of Create.
4 5 6 |
# File 'lib/vagrant-aws/action/create.rb', line 4 def initialize(app, env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vagrant-aws/action/create.rb', line 8 def call(env) raise Errors::KeyNameNotSpecified if env["config"].aws.key_name.nil? env.ui.info I18n.t("vagrant.plugins.aws.actions.create.creating") server_def = server_definition(env["config"]) # Verify AMI is valid (and in the future enable options specific to EBS-based AMIs) image = env["vm"].connection.images.get(server_def[:image_id]) image.wait_for { state == 'available' } env["vm"].vm = env["vm"].connection.servers.create(server_def) raise VagrantAWS::Errors::VMCreateFailure if env["vm"].vm.nil? || env["vm"].vm.id.nil? env.ui.info I18n.t("vagrant.plugins.aws.actions.create.created", :id => env["vm"].vm.id) env["vm"].vm.wait_for { ready? } env["vm"].connection.(env["vm"].vm.id, { "name" => env["vm"].name }) env.ui.info I18n.t("vagrant.plugins.aws.actions.create.available", :dns => env["vm"].vm.dns_name) @app.call(env) end |
#recover(env) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/vagrant-aws/action/create.rb', line 32 def recover(env) if env["vm"].created? return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) # Interrupted, destroy the VM env["actions"].run(:aws_destroy) end end |
#server_definition(config) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant-aws/action/create.rb', line 41 def server_definition(config) { :image_id => config.aws.image, :groups => config.aws.security_groups, :flavor_id => config.aws.flavor, :key_name => config.aws.key_name, :username => config.aws.username, :private_key_path => config.aws.private_key_path, :availability_zone => config.aws.availability_zone } end |