Class: VagrantPlugins::SimpleCloud::Actions::Create
- Inherits:
-
Object
- Object
- VagrantPlugins::SimpleCloud::Actions::Create
- Includes:
- Vagrant::Util::Retryable, Helpers::Client, Helpers::ClientService
- Defined in:
- lib/vagrant-simple_cloud/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::ClientService
Methods included from Helpers::Client
Constructor Details
#initialize(app, env) ⇒ Create
Returns a new instance of Create.
12 13 14 15 16 17 18 |
# File 'lib/vagrant-simple_cloud/actions/create.rb', line 12 def initialize(app, env) @app = app @machine = env[:machine] @client = client @clientservice = clientservice @logger = Log4r::Logger.new('vagrant::simple_cloud::create') end |
Instance Method Details
#call(env) ⇒ Object
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 66 67 68 69 70 71 72 |
# File 'lib/vagrant-simple_cloud/actions/create.rb', line 20 def call(env) ssh_key_id = [env[:ssh_key_id]] # submit new droplet request result = @clientservice.post('/v2/vps', { :size => @machine.provider_config.size, :region => @machine.provider_config.region, :image => @machine.provider_config.image, :name => @machine.config.vm.hostname || @machine.name, :ssh_keys => ssh_key_id, :private_networking => @machine.provider_config.private_networking, :backups => @machine.provider_config.backups_enabled, :ipv6 => @machine.provider_config.ipv6, :user_data => @machine.provider_config.user_data }.delete_if { |k, v| v.nil? }) # assign the machine id for reference in other commands @machine.id = result['vps']['id'].to_s #raise 'VPS not ready, no actions_ids' unless result['vps'].has_key?('action_ids') result = @client.request("/v2/vps/#{@machine.id}/actions") # wait for request to complete env[:ui].info I18n.t('vagrant_simple_cloud.info.creating') @client.wait_for_event(env, result['actions'].first['id']) # refresh droplet state with provider and output ip address droplet = Provider.droplet(@machine, :refresh => true) public_network = droplet['networks']['v4'].find { |network| network['type'] == 'public' } private_network = droplet['networks']['v4'].find { |network| network['type'] == 'private' } env[:ui].info I18n.t('vagrant_simple_cloud.info.droplet_ip', { :ip => public_network['ip_address'] }) if private_network env[:ui].info I18n.t('vagrant_simple_cloud.info.droplet_private_ip', { :ip => private_network['ip_address'] }) end # wait for ssh to be ready switch_user = @machine.provider_config.setup? user = @machine.config.ssh.username @machine.config.ssh.username = 'root' if switch_user retryable(:tries => 120, :sleep => 10) do next if env[:interrupted] raise 'not ready' if !@machine.communicate.ready? end @machine.config.ssh.username = user @app.call(env) end |
#recover(env) ⇒ Object
Both the recover and terminate are stolen almost verbatim from the Vagrant AWS provider up action
76 77 78 79 80 81 82 |
# File 'lib/vagrant-simple_cloud/actions/create.rb', line 76 def recover(env) return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError) if @machine.state.id != :not_created terminate(env) end end |
#terminate(env) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/vagrant-simple_cloud/actions/create.rb', line 84 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(Actions.destroy, destroy_env) end |