Class: VagrantPlugins::WinAzure::Action::ReadState

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



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

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_azure::action::read_state')
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
# File 'lib/vagrant-azure/action/read_state.rb', line 17

def call(env)
  env[:machine_state_id] = read_state(env)

  @app.call(env)
end

#read_state(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-azure/action/read_state.rb', line 23

def read_state(env)
  env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id

  env[:machine].id =~ /@/

  env[:ui].info "Attempting to read state for #{$`} in #{$'}"

  vm = env[:azure_vm_service].get_virtual_machine($`, $')

  if vm.nil? || \
    !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine) || \
    [ :DeletingVM ].include?(vm.status.to_sym)
    # Machine can't be found
    @logger.info 'Machine cannot be found'
    env[:machine].id = nil
    return :NotCreated
  end

  env[:ui].info "VM Status: #{vm.status.to_sym}"
  return vm.status.to_sym
end