Module: VagrantPlugins::Azure::Util::VMStatusTranslator

Included in:
Action::ReadState, Action::StartInstance, Action::StopInstance
Defined in:
lib/vagrant-azure/util/vm_status_translator.rb

Constant Summary collapse

PROVISIONING_STATES =
[:provisioned, :deleting]
POWER_STATES =
[:running, :starting, :deallocating, :deallocated]

Instance Method Summary collapse

Instance Method Details

#built?(statuses) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 45

def built?(statuses)
  statuses.any?{ |s| vm_status_to_state(s) == :provisioned }
end

#power_state(statuses) ⇒ Object



37
38
39
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 37

def power_state(statuses)
  vm_status_to_state(statuses.select{ |s| s.code.match(/PowerState/) }.last)
end

#running?(statuses) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 41

def running?(statuses)
  statuses.any?{ |s| vm_status_to_state(s) == :running }
end

#stopped?(statuses) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 49

def stopped?(statuses)
  statuses.any?{ |s| vm_status_to_state(s) == :stopped }
end

#stopping?(statuses) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 53

def stopping?(statuses)
  statuses.any?{ |s| vm_status_to_state(s) == :stopping }
end

#tearing_down?(statuses) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 57

def tearing_down?(statuses)
  statuses.any?{ |s| vm_status_to_state(s) == :deleting }
end

#vm_status_to_state(status) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-azure/util/vm_status_translator.rb', line 13

def vm_status_to_state(status)
  code = status.code
  case
    when code == 'ProvisioningState/succeeded'
      :provisioned
    when code == 'ProvisioningState/deleting'
      :deleting
    when code == 'PowerState/running'
      :running
    when code == 'PowerState/stopping'
      :stopping
    when code == 'PowerState/stopped'
      :stopped
    when code == 'PowerState/starting'
      :starting
    when code == 'PowerState/deallocating'
      :deallocating
    when code == 'PowerState/deallocated'
      :deallocated
    else
      :unknown
  end
end