Module: ForemanFogProxmox::ProxmoxComputeAttributes
- Included in:
- Proxmox
- Defined in:
- app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb
Constant Summary collapse
- FOREMAN_INTERFACE_ATTRIBUTES =
[:id, :mac, :ip, :ip6].freeze
- PROXMOX_MAC_ATTRIBUTES =
[:macaddr, :hwaddr].freeze
- PROXMOX_INTERFACE_METADATA =
[:identifier, :compute_attributes].freeze
Instance Method Summary collapse
- #host_compute_attrs(host) ⇒ Object
- #interface_compute_attributes(interface_attributes) ⇒ Object
- #not_config_key?(vm, key) ⇒ Boolean
- #vm_compute_attributes(vm) ⇒ Object
- #volume_compute_attributes(volume_attributes) ⇒ Object
Instance Method Details
#host_compute_attrs(host) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb', line 26 def host_compute_attrs(host) config = host.compute_attributes['config_attributes'] || {} ostype = config['ostype'] type = host.compute_attributes['type'] case type when 'lxc' host.compute_attributes['config_attributes'].store('hostname', host.name) when 'qemu' host.compute_attributes['config_attributes'].store('name', host.name) unless compute_os_types(host).include?(ostype) raise ::Foreman::Exception, format(_('Operating system family %<type>s is not consistent with %<ostype>s'), type: host..type, ostype: ostype) end end super end |
#interface_compute_attributes(interface_attributes) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb', line 48 def interface_compute_attributes(interface_attributes) attrs = interface_attributes.with_indifferent_access provider_attrs = attrs[:compute_attributes].present? ? attrs[:compute_attributes].with_indifferent_access : ActiveSupport::HashWithIndifferentAccess.new vm_attrs = FOREMAN_INTERFACE_ATTRIBUTES.index_with do |key| attrs[key] || provider_attrs.delete(key) end.compact vm_attrs[:mac] ||= attrs[:macaddr] || attrs[:hwaddr] || provider_attrs.delete(:macaddr) || provider_attrs.delete(:hwaddr) attrs.except(*FOREMAN_INTERFACE_ATTRIBUTES, *PROXMOX_MAC_ATTRIBUTES, *PROXMOX_INTERFACE_METADATA).each do |key, value| provider_attrs[key] = value end provider_attrs[:dhcp] = (vm_attrs[:ip] == 'dhcp') ? '1' : '0' provider_attrs[:dhcp6] = (vm_attrs[:ip6] == 'dhcp') ? '1' : '0' vm_attrs[:compute_attributes] = provider_attrs vm_attrs end |
#not_config_key?(vm, key) ⇒ Boolean
44 45 46 |
# File 'app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb', line 44 def not_config_key?(vm, key) [:disks, :interfaces, :vmid, :node_id, :node, :type].include?(key) || !vm.config.respond_to?(key) end |
#vm_compute_attributes(vm) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb', line 71 def vm_compute_attributes(vm) vm_attrs = {} vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type) if vm.respond_to?(:config) if vm.config.respond_to?(:disks) vm_attrs[:volumes_attributes] = Hash[vm.config.disks.each_with_index.map do |disk, idx| [idx.to_s, volume_compute_attributes(disk.attributes)] end ] end if vm.config.respond_to?(:interfaces) vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map do |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] end ] end vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value| not_config_key?(vm, key) || ForemanFogProxmox::Value.empty?(value.to_s) || Fog::Proxmox::DiskHelper.disk?(key.to_s) || Fog::Proxmox::NicHelper.nic?(key.to_s) end end vm_attrs end |
#volume_compute_attributes(volume_attributes) ⇒ Object
67 68 69 |
# File 'app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb', line 67 def volume_compute_attributes(volume_attributes) volume_attributes.merge(_delete: '0') end |