Class: Actions::ForemanWreckingball::Host::RemediateVmwareOperatingsystem

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb

Instance Method Summary collapse

Instance Method Details

#append_error(message) ⇒ Object



79
80
81
82
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 79

def append_error(message)
  output[:errors] ||= []
  output[:errors] << message
end

#delay(delay_options, host) ⇒ Object



9
10
11
12
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 9

def delay(delay_options, host)
  action_subject(host)
  super(delay_options, host)
end

#humanized_inputObject



75
76
77
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 75

def humanized_input
  input[:host] && input[:host][:name]
end

#humanized_nameObject



71
72
73
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 71

def humanized_name
  _('Correct VM Operatingsystem')
end

#plan(host) ⇒ Object



14
15
16
17
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 14

def plan(host)
  action_subject(host)
  plan_self
end

#rescue_strategyObject



84
85
86
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 84

def rescue_strategy
  Dynflow::Action::Rescue::Skip
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb', line 19

def run
  host = ::Host.find(input[:host][:id])

  fail _('Foreman does not know the Architecture of this host.') unless host.architecture
  fail _('Foreman does not know the Operatingsystem of this host.') unless host.operatingsystem

  initially_powered_on = host.power.ready?
  output[:initially_powered_on] = initially_powered_on

  current_os_id = host.vmware_facet.guest_id
  current_os = VsphereOsIdentifiers.lookup(current_os_id)

  selectors = {
    :architecture => host.architecture.name,
    :osfamily => host.operatingsystem.family,
    :name => host.operatingsystem.name,
    :major => host.operatingsystem.major.to_i,
    :release => host.facts['os::release::full']
  }

  desired_os = VsphereOsIdentifiers.find_by(selectors)
  desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major))
  desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:release))
  desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :release))
  desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name))
  desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name, :release))

  fail _('Could not auto detect desired operatingsystem.') unless desired_os

  fail _('VMs current and desired OS (%s) already match. No update necessary.') % current_os.description if current_os == desired_os

  output[:old_operatingsystem] = current_os.description
  output[:old_operatingsystem_id] = current_os.id
  output[:new_operatingsytem] = desired_os.description
  output[:new_operatingsytem_id] = desired_os.id

  vm = host.compute_object

  if initially_powered_on
    vm.stop
    vm.wait_for { power_state == 'poweredOff' }
    fail _('Could not shut down VM.') if vm.ready?
  end

  vm.vm_reconfig_hardware('guestId' => desired_os.id)

  state = host.refresh_vmware_facet!
  output[:state] = state
ensure
  vm.start if vm && initially_powered_on
end