Module: Orchestration::Proxmox::Compute

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/orchestration/proxmox/compute.rb

Instance Method Summary collapse

Instance Method Details

#computeIp(foreman_attr, fog_attr) ⇒ Object



60
61
62
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 60

def computeIp(foreman_attr, fog_attr)
  vm.send(fog_attr) || find_address(foreman_attr)
end

#computeValue(foreman_attr, fog_attr) ⇒ Object



64
65
66
67
68
69
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 64

def computeValue(foreman_attr, fog_attr)
  value = ''
  value += compute_resource.id.to_s + '_' if foreman_attr == :uuid
  value += vm.send(fog_attr).to_s
  value
end

#delComputeUpdateObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 39

def delComputeUpdate
  if compute_resource.class != ForemanFogProxmox::Proxmox
    super
  else
    logger.info "Undo Update Proxmox Compute instance for #{name}"
    final_compute_attributes = old.compute_attributes.merge(compute_resource.host_compute_attrs(old))
    compute_resource.save_vm uuid, final_compute_attributes
  end
rescue StandardError => e
  failure format(_('Failed to undo update compute %<compute_resource>s instance %<name>s: %<e>s'), :compute_resource => compute_resource, :name => name, :e => e),
    e
end

#empty_provided_ips?(ip, ip6) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 52

def empty_provided_ips?(ip, ip6)
  ip.blank? && ip6.blank? && (compute_provides?(:ip) || compute_provides?(:ip6))
end

#ips_keysObject



56
57
58
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 56

def ips_keys
  [:ip, :ip6]
end

#setComputeDetailsObject



97
98
99
100
101
102
103
104
105
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 97

def setComputeDetails
  if compute_resource.class != ForemanFogProxmox::Proxmox
    super
  elsif vm
    setVmDetails
  else
    failure format(_('failed to save %<name>s'), name: name)
  end
end

#setComputeUpdateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 25

def setComputeUpdate
  if compute_resource.class != ForemanFogProxmox::Proxmox
    super
  else
    logger.info "Update Proxmox Compute instance for #{name}"
    final_compute_attributes = compute_attributes.merge(compute_resource.host_compute_attrs(self))
    logger.debug("setComputeUpdate: final_compute_attributes=#{final_compute_attributes}")
    compute_resource.save_vm uuid, final_compute_attributes
  end
rescue StandardError => e
  failure format(_('Failed to update a compute %<compute_resource>s instance %<name>s: %<e>s'), :compute_resource => compute_resource, :name => name, :e => e),
    e
end

#setVmDetailsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/concerns/orchestration/proxmox/compute.rb', line 71

def setVmDetails
  attrs = compute_resource.provided_attributes
  result = true
  attrs.each do |foreman_attr, fog_attr|
    if foreman_attr == :mac
      result = false unless match_macs_to_nics(fog_attr)
    elsif ips_keys.include?(foreman_attr)
      value = computeIp(foreman_attr, fog_attr)
      send("#{foreman_attr}=", value)
      result = false if send(foreman_attr).present? && !validate_foreman_attr(value, ::Nic::Base, foreman_attr)
    else
      value = computeValue(foreman_attr, fog_attr)
      send("#{foreman_attr}=", value)
      result = false unless validate_required_foreman_attr(value, Host, foreman_attr)
    end
  end
  if empty_provided_ips?(
    ip, ip6
  )
    return failure(format(_('Failed to acquire IP addresses from compute resource for %<name>s'),
      name: name))
  end

  result
end