Class: VagrantPlugins::NiftyCloud::Action::ReadState
- Inherits:
-
Object
- Object
- VagrantPlugins::NiftyCloud::Action::ReadState
- Defined in:
- lib/vagrant-niftycloud/action/read_state.rb
Overview
This action reads the state of the machine and puts it in the ‘:machine_state_id` key in the environment.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ReadState
constructor
A new instance of ReadState.
- #read_state(niftycloud, machine) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ ReadState
Returns a new instance of ReadState.
10 11 12 13 |
# File 'lib/vagrant-niftycloud/action/read_state.rb', line 10 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_niftycloud::action::read_state") end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 |
# File 'lib/vagrant-niftycloud/action/read_state.rb', line 15 def call(env) env[:machine_state_id] = read_state(env[:niftycloud_compute], env[:machine]) @app.call(env) end |
#read_state(niftycloud, machine) ⇒ Object
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 |
# File 'lib/vagrant-niftycloud/action/read_state.rb', line 21 def read_state(niftycloud, machine) return :not_created if machine.id.nil? # Find the machine # 例外の定義は以下参照 # http://cloud.nifty.com/api/sdk/rdoc/ begin server = niftycloud.get(machine) state = server.instanceState.name case state when 'suspending' @logger.info("Machine not found or terminated, assuming it got destroyed.") machine.id = nil return :not_created else @logger.debug("Server State #{state.to_sym}") return state.to_sym end 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 machine.id = nil return :not_created end end |