Class: VagrantPlugins::ProviderIijGp::Action::ReadState
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderIijGp::Action::ReadState
- Defined in:
- lib/vagrant-iijgp/action/read_state.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ReadState
constructor
A new instance of ReadState.
- #read_state(env) ⇒ Object
- #to_snake_sym(str) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ ReadState
Returns a new instance of ReadState.
5 6 7 8 |
# File 'lib/vagrant-iijgp/action/read_state.rb', line 5 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_iijgp::action::read_state") end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 |
# File 'lib/vagrant-iijgp/action/read_state.rb', line 14 def call(env) env[:machine_state] = read_state(env) @app.call(env) end |
#read_state(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-iijgp/action/read_state.rb', line 19 def read_state(env) machine = env[:machine] return :not_created if machine.id.nil? vm = env[:iijapi].gp(machine.provider_config.gp_service_code).gc(machine.id) if contract_status = vm.contract_status if contract_status == "InService" return to_snake_sym(vm.status) elsif contract_status == "InPreparation" return :in_preparation else machine.id = nil return :not_created end else machine.id = nil return :not_created end end |
#to_snake_sym(str) ⇒ Object
10 11 12 |
# File 'lib/vagrant-iijgp/action/read_state.rb', line 10 def to_snake_sym(str) str.gsub(/[A-Z]/) {|s| "_#{s.downcase}" }.sub(/^_/, '').to_sym end |