Class: VagrantPlugins::Abiquo::Actions::CheckState
- Inherits:
-
Object
- Object
- VagrantPlugins::Abiquo::Actions::CheckState
- Defined in:
- lib/vagrant_abiquo/actions/check_state.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CheckState
constructor
A new instance of CheckState.
Constructor Details
#initialize(app, env) ⇒ CheckState
Returns a new instance of CheckState.
7 8 9 10 11 |
# File 'lib/vagrant_abiquo/actions/check_state.rb', line 7 def initialize(app, env) @app = app @machine = env[:machine] @logger = Log4r::Logger.new('vagrant::abiquo::check_state') end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant_abiquo/actions/check_state.rb', line 13 def call(env) vapp_name = @machine.provider_config.virtualappliance.nil? ? File.basename(@machine.env.cwd) : @machine.provider_config.virtualappliance # If machine ID is nil try to lookup by name if @machine.id.nil? vms_lnk = AbiquoAPI::Link.new :href => 'cloud/virtualmachines', :type => 'application/vnd.abiquo.virtualmachines+json', :client => env[:abiquo_client] @vm = vms_lnk.get.select {|v| v.label == @machine.name.to_s and v.link(:virtualappliance).title == vapp_name }.first @machine.id = @vm.url unless @vm.nil? else # ID is the URL of the VM begin vm_lnk = AbiquoAPI::Link.new :href => @machine.id, :type => 'application/vnd.abiquo.virtualmachine+json', :client => env[:abiquo_client] @vm = vm_lnk.get rescue AbiquoAPIClient::NotFound nil end end env[:machine_state] = @vm.nil? ? :not_created : @vm.state.to_sym @logger.info "Machine state is '#{env[:machine_state]}'" @app.call(env) end |