Class: VagrantPlugins::VCloud::Action::DisconnectVCloud

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vcloud/action/disconnect_vcloud.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DisconnectVCloud

Returns a new instance of DisconnectVCloud.



5
6
7
8
9
10
# File 'lib/vagrant-vcloud/action/disconnect_vcloud.rb', line 5

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new(
    'vagrant_vcloud::action::disconnect_vcloud'
  )
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-vcloud/action/disconnect_vcloud.rb', line 12

def call(env)
  begin
    @logger.info('Disconnecting from vCloud Director...')

    # Fetch the global vCloud Director connection handle
    cnx = env[:machine].provider_config.vcloud_cnx.driver

    # Delete the current vCloud Director Session
    cnx.logout

    # If session key doesn't exist, we are disconnected
    if !cnx.auth_key
      @logger.info('Disconnected from vCloud Director successfully!')
    end

  rescue Exception => e
    # Raise a properly namespaced error for Vagrant
    raise Errors::VCloudError, :message => e.message
  end
end