Class: VagrantPlugins::VCloud::Action::ConnectVCloud
- Inherits:
-
Object
- Object
- VagrantPlugins::VCloud::Action::ConnectVCloud
- Defined in:
- lib/vagrant-vcloud/action/connect_vcloud.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ConnectVCloud
constructor
A new instance of ConnectVCloud.
Constructor Details
#initialize(app, env) ⇒ ConnectVCloud
Returns a new instance of ConnectVCloud.
7 8 9 10 |
# File 'lib/vagrant-vcloud/action/connect_vcloud.rb', line 7 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_vcloud::action::connect_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 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 |
# File 'lib/vagrant-vcloud/action/connect_vcloud.rb', line 12 def call(env) config = env[:machine].provider_config # begin # Avoid recreating a new session each time. if !config.vcloud_cnx @logger.info("Connecting to vCloud Director...") @logger.debug("config.hostname : #{config.hostname}") @logger.debug("config.username : #{config.username}") @logger.debug("config.password : #{config.password}") @logger.debug("config.org_name : #{config.org_name}") # Create the vcloud-rest connection object with the configuration # information. config.vcloud_cnx = Driver::Meta.new( config.hostname, config.username, config.password, config.org_name ) @logger.info("Logging into vCloud Director...") config.vcloud_cnx.login # Check for the vCloud Director authentication token if config.vcloud_cnx.driver.auth_key @logger.info("Logged in successfully!") @logger.debug( "x-vcloud-authorization=#{config.vcloud_cnx.driver.auth_key}" ) else @logger.info("Login failed in to #{config.hostname}.") env[:ui].error("Login failed in to #{config.hostname}.") raise end else @logger.info("Already logged in, using current session") @logger.debug( "x-vcloud-authorization=#{config.vcloud_cnx.driver.auth_key}" ) end @app.call env # rescue Exception => e # ### When bad credentials, we get here. # @logger.debug("Couldn't connect to vCloud Director: #{e.inspect}") # raise VagrantPlugins::VCloud::Errors::VCloudError, :message => e.message # end end |