Class: VagrantPlugins::DigitalOcean::Actions::Create
- Inherits:
-
Object
- Object
- VagrantPlugins::DigitalOcean::Actions::Create
- Includes:
- Vagrant::Util::Retryable, Helpers::Client
- Defined in:
- lib/vagrant-digitalocean/actions/create.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Create
constructor
A new instance of Create.
-
#recover(env) ⇒ Object
Both the recover and terminate are stolen almost verbatim from the Vagrant AWS provider up action.
- #terminate(env) ⇒ Object
Methods included from Helpers::Client
Constructor Details
#initialize(app, env) ⇒ Create
Returns a new instance of Create.
10 11 12 13 14 |
# File 'lib/vagrant-digitalocean/actions/create.rb', line 10 def initialize(app, env) @app, @env = app, env @client = client @translator = Helpers::Translator.new("actions.create") 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 |
# File 'lib/vagrant-digitalocean/actions/create.rb', line 16 def call(env) ssh_key_id = env[:ssh_key_id] size_id = @client .request("/sizes") .find_id(:sizes, :name => env[:machine].provider_config.size) image_id = @client .request("/images", { :filter => "global" }) .find_id(:images, :name => env[:machine].provider_config.image) region_id = @client .request("/regions") .find_id(:regions, :name => env[:machine].provider_config.region) env[:ui].info @translator.t("create_droplet") result = @client.request("/droplets/new", { :size_id => size_id, :region_id => region_id, :image_id => image_id, # TODO use the current directory name as a post fix :name => "vagrant", :ssh_key_ids => ssh_key_id }) env[:ui].info @translator.t("wait_active") @client.wait_for_event(result["droplet"]["event_id"]) # assign the machine id for reference in other commands env[:machine].id = result["droplet"]["id"].to_s @app.call(env) end |
#recover(env) ⇒ Object
Both the recover and terminate are stolen almost verbatim from the Vagrant AWS provider up action
53 54 55 56 57 58 59 |
# File 'lib/vagrant-digitalocean/actions/create.rb', line 53 def recover(env) return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) if env[:machine].state.id != :not_created terminate(env) end end |
#terminate(env) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/vagrant-digitalocean/actions/create.rb', line 61 def terminate(env) destroy_env = env.dup destroy_env.delete(:interrupted) destroy_env[:config_validate] = false destroy_env[:force_confirm_destroy] = true env[:action_runner].run(Action.new.destroy, destroy_env) end |