Sha256: 46073a77b228a026ba9ab1d1762cdc4a8980010e39ea18cc77045c078a0e8611

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'log4r'

require 'vagrant-deltacloud-provider/action/abstract_action'

module VagrantPlugins
  module Deltacloud
    module Action
      # This deletes the running server, if there is one.
      class DeleteServer < AbstractAction
        def initialize(app, _env)
          @app    = app
          @logger = Log4r::Logger.new('vagrant_deltacloud::action::delete_server')
        end

        def execute(env)
          env[:deltacloud_client] = Deltacloud::DeltacloudClient.instance
          if env[:machine].id
            @logger.info "Deleting server #{env[:machine].id}..."
            env[:ui].info(I18n.t('vagrant_deltacloud.deleting_server'))
            instance_details = env[:deltacloud_client].get_instance_details(env, env[:machine].id)
            key_id = instance_details.key_name
            env[:deltacloud_client].destroy_instance(env, env[:machine].id)
            env[:deltacloud_client].delete_public_key(env, key_id)
            env[:machine].id = nil
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-deltacloud-provider-0.0.9 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.8 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.7 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.6 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.5 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.4 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.3 lib/vagrant-deltacloud-provider/action/delete_server.rb
vagrant-deltacloud-provider-0.0.2 lib/vagrant-deltacloud-provider/action/delete_server.rb