Skip to content

Commit

Permalink
Switch to template
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein committed Feb 29, 2024
1 parent 13b7ee3 commit 159687d
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 504 deletions.
6 changes: 3 additions & 3 deletions app/models/nic/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class Base < ApplicationRecord
end
class Jail < ::Safemode::Jail
allow :id, :subnet, :subnet6, :virtual?, :physical?, :mac, :ip, :ip6, :identifier, :attached_to,
:link, :tag, :domain, :vlanid, :mtu, :bond_options, :attached_devices, :mode,
:attached_devices_identifiers, :primary, :provision, :alias?, :inheriting_mac,
:children_mac_addresses, :nic_delay, :fqdn, :shortname, :type, :managed?, :bond?, :bridge?, :bmc?, :provision?
:link, :tag, :domain, :bond_options, :attached_devices, :mode,
:attached_devices_identifiers, :primary, :provision, :inheriting_mac,
:children_mac_addresses, :nic_delay, :fqdn, :shortname, :type, :managed?, :bond?, :bmc?, :provision?
end

# include STI inheritance column in audits
Expand Down
4 changes: 4 additions & 0 deletions app/models/nic/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Interface < Base
alias_method :network, :subnet_network
alias_method :network6, :subnet6_network

class Jail < Nic::Base::Jail
allow :mtu, :vlanid, :bridge?, :alias?
end

def vlanid
# Determine a vlanid according to the following cascading rules:
# 1. if the interface has a tag, use that as the vlanid
Expand Down
11 changes: 10 additions & 1 deletion app/models/operatingsystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Operatingsystem < ApplicationRecord
property :password_hash, String, desc: 'Encrypted hash of the operating system password'
end
class Jail < Safemode::Jail
allow :id, :name, :major, :minor, :family, :to_s, :==, :release, :release_name, :kernel, :initrd, :pxe_type, :boot_files_uri, :password_hash, :mediumpath, :bootfile
allow :id, :name, :major, :minor, :family, :to_s, :==, :release, :release_name, :kernel, :initrd, :pxe_type, :boot_files_uri, :password_hash, :mediumpath, :bootfile, :meets_requirement
end

def self.title_name
Expand Down Expand Up @@ -365,6 +365,15 @@ def has_default_template?(template_kind)
os_default_templates.find_by(template_kind: template_kind) || false
end

# Tells if the OS meets a version requirement. This method should be implemented with correct keyword arguments for each
# operating system family. For example for Redhat, we would implement it as: def meets_requirement(fedora: nil, rhel: nil)
# Main usage for this method is for deciding which features are present on the OS for a given host:
# Example:
# do_something if @host.operatingsystem.meets_requirement(fedora: 21, rhel: 7)
def meets_requirement(**_)
false
end

private

def set_family
Expand Down
11 changes: 1 addition & 10 deletions app/models/operatingsystems/redhat.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
class Redhat < Operatingsystem
PXEFILES = {:kernel => "vmlinuz", :initrd => "initrd.img"}

# Baseline taken from https://docs.fedoraproject.org/en-US/quick-docs/fedora-and-red-hat-enterprise-linux/index.html
FEDORA_MAPPING = [
[13, 6],
[19, 7],
[28, 8],
[34, 9],
[39, 10],
]

class Jail < Operatingsystem::Jail
allow :meets_requirement
allow :fedora?, :rhel_compatible?
end

# outputs kickstart installation medium based on the medium type (NFS or URL)
Expand Down
10 changes: 2 additions & 8 deletions app/services/foreman/renderer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ class Configuration
:update_ip_from_built_request,
]

DEFAULT_ALLOWED_KICKSTART_METHODS = [
:kickstart_network,
]

DEFAULT_ALLOWED_LOADERS = Foreman::Renderer::Scope::Macros::Loaders::LOADERS.map(&:first)

def initialize
Expand All @@ -135,15 +131,13 @@ def initialize
@allowed_generic_helpers = DEFAULT_ALLOWED_GENERIC_HELPERS
@allowed_host_helpers = DEFAULT_ALLOWED_HOST_HELPERS
@allowed_loaders = DEFAULT_ALLOWED_LOADERS
@allowed_kickstart_methods = DEFAULT_ALLOWED_KICKSTART_METHODS
end

attr_accessor :allowed_variables, :allowed_global_settings,
:allowed_generic_helpers, :allowed_host_helpers, :allowed_loaders,
:allowed_kickstart_methods
:allowed_generic_helpers, :allowed_host_helpers, :allowed_loaders

def allowed_helpers
allowed_generic_helpers + allowed_host_helpers + allowed_loaders + allowed_kickstart_methods
allowed_generic_helpers + allowed_host_helpers + allowed_loaders
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/services/foreman/renderer/scope/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Base
include Foreman::Renderer::Scope::Macros::TemplateLogging
include Foreman::Renderer::Scope::Macros::SnippetRendering
include Foreman::Renderer::Scope::Macros::Transpilers
include Foreman::Renderer::Scope::Macros::Kickstart

def self.inherited(child_class)
loaders.each { |loader| child_class.register_loader(loader) }
Expand Down
115 changes: 0 additions & 115 deletions app/services/foreman/renderer/scope/macros/kickstart.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ keyboard <%= host_param('keyboard') || 'us' %>
# start with provisioning interface, then other non-bond interfaces and the bonds at the end
@host.managed_interfaces.sort_by { |iface| iface.bond? ? 0 : iface.provision? ? 20 : 10 }.each do |iface|
-%>
<%= kickstart_network(
iface,
host: @host,
use_slaac: host_param_true?('use-slaac'),
static: @static,
static6: @static6) %>
<%= snippet(
'kickstart_network_interface',
variables: {
iface: iface,
host: @host,
use_slaac: host_param_true?('use-slaac'),
static: @static,
static6: @static6
}
) -%>
<%
end
-%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ liveimg --url=<%= liveimg_url %>
# start with provisioning interface, then other non-bond interfaces and the bonds at the end
@host.managed_interfaces.sort_by { |iface| iface.bond? 0 : iface.provision? 20 : 10 }.each |iface| do
%>
<%= kickstart_network(
iface,
host: @host,
use_slaac: false,
static: @static,
static6: @static6) %>
<%= snippet(
'kickstart_network_interface',
variables: {
iface: iface,
host: @host,
use_slaac: false,
static: @static,
static6: @static6
}
) -%>
<%
end
-%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ kind: snippet
description: |
Generates network directive for a given interface. It is not expected to be used directly.
-%>

<%# Variables: iface, host, use_slaac, static, static6 -%>

<%if @iface.managed? %>
<%#
# Variables: iface, host, use_slaac, static, static6
-%>
<%if @iface.managed? -%>
<%
network_options = []
nameservers = []
Expand All @@ -36,7 +36,9 @@ end
raise("IPv4 and IPv6 subnets have different MTU") if subnet4 && subnet6 && subnet4.mtu.present? && subnet6.mtu.present? && subnet4.mtu != subnet6.mtu

# mtu method is taking into account both ipv4 and ipv6 stacks
network_options.push("--mtu=#{@iface.mtu}") if @iface.mtu
if @iface.respond_to?(:mtu) && @iface.mtu
network_options.push("--mtu=#{@iface.mtu}")
end

# IPv4
if subnet4
Expand Down Expand Up @@ -93,6 +95,6 @@ if @iface.domain && @host.operatingsystem.meets_requirement(fedora: 39, rhel: 10
network_options.push("--ipv4-dns-search=#{@iface.domain}") if subnet4
network_options.push("--ipv6-dns-search=#{@iface.domain}") if subnet6
end
%>
<%= "network #{network_options.join(' ')}" %>
<% end %>
-%>
<%= "network #{network_options.join(' ')}\n" -%>
<% end -%>
Loading

0 comments on commit 159687d

Please sign in to comment.