Class: VagrantPlugins::NiftyCloud::Action::ConnectNiftyCloud
- Inherits:
-
Object
- Object
- VagrantPlugins::NiftyCloud::Action::ConnectNiftyCloud
- Defined in:
- lib/vagrant-niftycloud/action/connect_niftycloud.rb
Overview
This action connects to NiftyCloud, verifies credentials work, and puts the NiftyCloud connection object into the ‘:niftycloud_compute` key in the environment.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ConnectNiftyCloud
constructor
A new instance of ConnectNiftyCloud.
Constructor Details
#initialize(app, env) ⇒ ConnectNiftyCloud
Returns a new instance of ConnectNiftyCloud.
11 12 13 14 |
# File 'lib/vagrant-niftycloud/action/connect_niftycloud.rb', line 11 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_niftycloud::action::connect_niftycloud") 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 50 |
# File 'lib/vagrant-niftycloud/action/connect_niftycloud.rb', line 16 def call(env) # Get the zone we're going to booting up in zone = env[:machine].provider_config.zone # Get the configs zone_config = env[:machine].provider_config.get_zone_config(zone) # Build the fog config niftycloud_config = { :access_key => zone_config.access_key_id, :secret_key => zone_config.secret_access_key } # 例外の定義は以下参照 # http://cloud.nifty.com/api/sdk/rdoc/ begin @logger.info("Connecting to NiftyCloud...") env[:niftycloud_compute] = Servers::Servers.new(niftycloud_config) rescue NIFTY::ConfigurationError => e raise Errors::NiftyCloudConfigurationError, :message => e. rescue NIFTY::ArgumentError => e raise Errors::NiftyCloudArgumentError, :message => e. rescue NIFTY::ResponseFormatError => e raise Errors::NiftyCloudResponseFormatError, :message => e. rescue NIFTY::ResponseError => e raise Errors::NiftyCloudResponseError, :code => e.error_code, :message => e. end @app.call(env) end |