Class: VagrantPlugins::XenServer::Action::ReadState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-xenserver/action/read_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



7
8
9
10
# File 'lib/vagrant-xenserver/action/read_state.rb', line 7

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant::xenserver::actions::read_state")
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
# File 'lib/vagrant-xenserver/action/read_state.rb', line 12

def call(env)
  @logger.debug("XXXXX In ReadState")
  env[:machine_state_id] = read_state(env[:xc], env[:session], env[:machine])
  @logger.debug("state="+env[:machine_state_id].to_s)
  @app.call(env)
end

#read_state(xc, session, machine) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-xenserver/action/read_state.rb', line 19

def read_state(xc, session, machine)
  return :not_created if machine.id.nil?
  return :not_created if not machine.id.start_with?("OpaqueRef")

  begin
    result = xc.VM.get_record(machine.id)
    return result['power_state']
  rescue
    @logger.info("Machine not found. Assuming it has been destroyed.")
    machine.id = nil
    return :not_created
  end
end