diff --git a/site/profile/functions/getcidr.pp b/site/profile/functions/getcidr.pp deleted file mode 100644 index 23b80a4a8..000000000 --- a/site/profile/functions/getcidr.pp +++ /dev/null @@ -1,7 +0,0 @@ -function profile::getcidr() >> String { - $interface = profile::getlocalinterface() - $masklen = extlib::netmask_to_cidr(profile::getnetmask()) - $ip = $networking['interfaces'][$interface]['ip'] - $network = extlib::cidr_to_network("${ip}/${masklen}") - "${network}/${masklen}" -} diff --git a/site/profile/functions/is_grid_vgpu.pp b/site/profile/functions/gpu/has_vgpu.pp similarity index 84% rename from site/profile/functions/is_grid_vgpu.pp rename to site/profile/functions/gpu/has_vgpu.pp index 7fa432066..93418c2c3 100644 --- a/site/profile/functions/is_grid_vgpu.pp +++ b/site/profile/functions/gpu/has_vgpu.pp @@ -1,4 +1,4 @@ -function profile::is_grid_vgpu() >> Boolean { +function profile::gpu::has_vgpu() >> Boolean { if $facts['nvidia_grid_vgpu'] { true } else { diff --git a/site/profile/functions/generate_slurm_node_line.pp b/site/profile/functions/slurm/generate_node_line.pp similarity index 89% rename from site/profile/functions/generate_slurm_node_line.pp rename to site/profile/functions/slurm/generate_node_line.pp index 5f11f3003..61ec963b8 100644 --- a/site/profile/functions/generate_slurm_node_line.pp +++ b/site/profile/functions/slurm/generate_node_line.pp @@ -1,4 +1,4 @@ -function profile::generate_slurm_node_line($name, $attr, $comp_weight) >> String { +function profile::slurm::generate_node_line($name, $attr, $comp_weight) >> String { if $attr['specs']['gpus'] > 0 { if $attr['specs']['mig'] and ! $attr['specs']['mig'].empty { $gpu = $attr['specs']['mig'].map|$key,$value| { diff --git a/site/profile/functions/utils/getcidr.pp b/site/profile/functions/utils/getcidr.pp new file mode 100644 index 000000000..1d79b9a24 --- /dev/null +++ b/site/profile/functions/utils/getcidr.pp @@ -0,0 +1,7 @@ +function profile::utils::getcidr() >> String { + $interface = profile::utils::getlocalinterface() + $masklen = extlib::netmask_to_cidr(profile::utils::getnetmask()) + $ip = $networking['interfaces'][$interface]['ip'] + $network = extlib::cidr_to_network("${ip}/${masklen}") + "${network}/${masklen}" +} diff --git a/site/profile/functions/gethostnames_with_class.pp b/site/profile/functions/utils/gethostnames_with_class.pp similarity index 84% rename from site/profile/functions/gethostnames_with_class.pp rename to site/profile/functions/utils/gethostnames_with_class.pp index e883be5e0..ee226f797 100644 --- a/site/profile/functions/gethostnames_with_class.pp +++ b/site/profile/functions/utils/gethostnames_with_class.pp @@ -1,4 +1,4 @@ -function profile::gethostnames_with_class($class_name) >> Array[String] { +function profile::utils::gethostnames_with_class($class_name) >> Array[String] { $instances = lookup('terraform.instances') $site_all = lookup('magic_castle::site::all') $site_tags = lookup('magic_castle::site::tags') diff --git a/site/profile/functions/getlocalinterface.pp b/site/profile/functions/utils/getlocalinterface.pp similarity index 80% rename from site/profile/functions/getlocalinterface.pp rename to site/profile/functions/utils/getlocalinterface.pp index 0c5600b90..57a329d29 100644 --- a/site/profile/functions/getlocalinterface.pp +++ b/site/profile/functions/utils/getlocalinterface.pp @@ -1,4 +1,4 @@ -function profile::getlocalinterface() >> String { +function profile::utils::getlocalinterface() >> String { $local_ip = lookup('terraform.self.local_ip') $interfaces = keys($facts['networking']['interfaces']) $search = $interfaces.filter | $interface | { diff --git a/site/profile/functions/getnetmask.pp b/site/profile/functions/utils/getnetmask.pp similarity index 71% rename from site/profile/functions/getnetmask.pp rename to site/profile/functions/utils/getnetmask.pp index d407dfe49..7c6c32a5a 100644 --- a/site/profile/functions/getnetmask.pp +++ b/site/profile/functions/utils/getnetmask.pp @@ -1,9 +1,9 @@ -function profile::getnetmask() >> String { +function profile::utils::getnetmask() >> String { if $facts['gce'] { # GCP instances netmask is set to /32 but the network netmask is available $netmask = $gce['instance']['networkInterfaces'][0]['subnetmask'] } else { - $interface = profile::getlocalinterface() + $interface = profile::utils::getlocalinterface() $netmask = $networking['interfaces'][$interface]['netmask'] } $netmask diff --git a/site/profile/functions/getptrrecord.pp b/site/profile/functions/utils/getptrrecord.pp similarity index 54% rename from site/profile/functions/getptrrecord.pp rename to site/profile/functions/utils/getptrrecord.pp index 1c8047861..6573ba65b 100644 --- a/site/profile/functions/getptrrecord.pp +++ b/site/profile/functions/utils/getptrrecord.pp @@ -1,8 +1,8 @@ -function profile::getptrrecord() >> String { - $interface = profile::getlocalinterface() +function profile::utils::getptrrecord() >> String { + $interface = profile::utils::getlocalinterface() $ip = $networking['interfaces'][$interface]['ip'] $ip_list = split($ip, '[.]') - $netmask_list = split(profile::getnetmask(), '[.]') + $netmask_list = split(profile::utils::getnetmask(), '[.]') $filtered_ip = $ip_list.filter |$i, $v| { $netmask_list[$i] == '0' } diff --git a/site/profile/functions/getreversezone.pp b/site/profile/functions/utils/getreversezone.pp similarity index 61% rename from site/profile/functions/getreversezone.pp rename to site/profile/functions/utils/getreversezone.pp index dd2dc8fbb..98ba2286d 100644 --- a/site/profile/functions/getreversezone.pp +++ b/site/profile/functions/utils/getreversezone.pp @@ -1,8 +1,8 @@ -function profile::getreversezone() >> String { - $interface = profile::getlocalinterface() +function profile::utils::getreversezone() >> String { + $interface = profile::utils::getlocalinterface() $network = $networking['interfaces'][$interface]['network'] $network_list = split($network, '[.]') - $netmask_list = split(profile::getnetmask(), '[.]') + $netmask_list = split(profile::utils::getnetmask(), '[.]') $filtered_network = $network_list.filter |$i, $v| { $netmask_list[$i] != '0' } diff --git a/lib/puppet/functions/slurm_compute_weights.rb b/site/profile/lib/puppet/functions/profile/slurm/compute_weights.rb similarity index 80% rename from lib/puppet/functions/slurm_compute_weights.rb rename to site/profile/lib/puppet/functions/profile/slurm/compute_weights.rb index 3ea7ba964..09bfb7afd 100644 --- a/lib/puppet/functions/slurm_compute_weights.rb +++ b/site/profile/lib/puppet/functions/profile/slurm/compute_weights.rb @@ -1,10 +1,10 @@ -Puppet::Functions.create_function(:slurm_compute_weights) do - dispatch :slurm_compute_weights do +Puppet::Functions.create_function(:'profile::slurm::compute_weights') do + dispatch :compute_weights do param 'Hash', :instances return_type 'Hash' end - def slurm_compute_weights(instances) + def compute_weights(instances) require 'set' unique_specs = Set.new(instances.values.map {|i| i['specs']}) sorted_specs = unique_specs.sort_by{|spec| [spec['gpus'], spec['ram'], spec['cpus']]} diff --git a/lib/puppet/functions/ssh_split_options.rb b/site/profile/lib/puppet/functions/profile/utils/split_options.rb similarity index 50% rename from lib/puppet/functions/ssh_split_options.rb rename to site/profile/lib/puppet/functions/profile/utils/split_options.rb index 069e725ec..305fa1bb8 100644 --- a/lib/puppet/functions/ssh_split_options.rb +++ b/site/profile/lib/puppet/functions/profile/utils/split_options.rb @@ -1,9 +1,9 @@ -Puppet::Functions.create_function(:ssh_split_options) do - dispatch :ssh_split_options do +Puppet::Functions.create_function(:'profile::utils::split_options') do + dispatch :split_options do param 'String', :options return_type 'Array' end - def ssh_split_options(options) + def split_options(options) return options.scan(/(\w+=".*?"|[\w-]+)/).flatten end end \ No newline at end of file diff --git a/site/profile/manifests/base.pp b/site/profile/manifests/base.pp index 85b04ef94..e756b8fc6 100644 --- a/site/profile/manifests/base.pp +++ b/site/profile/manifests/base.pp @@ -67,7 +67,7 @@ firewall { '001 accept all from local network': chain => 'INPUT', proto => 'all', - source => profile::getcidr(), + source => profile::utils::getcidr(), action => 'accept', tag => 'mc_bootstrap', } diff --git a/site/profile/manifests/fail2ban.pp b/site/profile/manifests/fail2ban.pp index 29a64d61c..1d31f9e9a 100644 --- a/site/profile/manifests/fail2ban.pp +++ b/site/profile/manifests/fail2ban.pp @@ -4,7 +4,7 @@ include epel class { 'fail2ban' : - whitelist => ['127.0.0.1/8', profile::getcidr()] + $ignoreip, + whitelist => ['127.0.0.1/8', profile::utils::getcidr()] + $ignoreip, } file_line { 'fail2ban_sshd_recv_disconnect': diff --git a/site/profile/manifests/freeipa.pp b/site/profile/manifests/freeipa.pp index e1733c140..8ccbe8180 100644 --- a/site/profile/manifests/freeipa.pp +++ b/site/profile/manifests/freeipa.pp @@ -236,7 +236,7 @@ $realm = upcase($ipa_domain) $fqdn = "${facts['networking']['hostname']}.${ipa_domain}" - $reverse_zone = profile::getreversezone() + $reverse_zone = profile::utils::getreversezone() $ipaddress = lookup('terraform.self.local_ip') $ipa_server_install_cmd = @("IPASERVERINSTALL"/L) diff --git a/site/profile/manifests/gpu.pp b/site/profile/manifests/gpu.pp index 118c9ffc7..b686fa154 100644 --- a/site/profile/manifests/gpu.pp +++ b/site/profile/manifests/gpu.pp @@ -49,7 +49,7 @@ path => ['/bin', '/sbin'], } - if ! profile::is_grid_vgpu() { + if ! profile::gpu::has_vgpu() { include profile::gpu::install::passthrough Class['profile::gpu::install::passthrough'] -> Exec['dkms_nvidia'] } else { @@ -58,7 +58,7 @@ # Binary installer do not build drivers with DKMS $installer = lookup('profile::gpu::install::vgpu::installer', undef, undef, '') - if ! profile::is_grid_vgpu() or $installer != 'bin' { + if ! profile::gpu::has_vgpu() or $installer != 'bin' { exec { 'dkms_nvidia': command => "dkms autoinstall -m nvidia -k ${facts['kernelrelease']}", path => ['/usr/bin', '/usr/sbin'], @@ -327,7 +327,7 @@ } class profile::gpu::services { - if ! profile::is_grid_vgpu() { + if ! profile::gpu::has_vgpu() { $gpu_services = ['nvidia-persistenced', 'nvidia-dcgm'] } else { $gpu_services = ['nvidia-gridd'] diff --git a/site/profile/manifests/slurm.pp b/site/profile/manifests/slurm.pp index b034c6e60..bfce72063 100644 --- a/site/profile/manifests/slurm.pp +++ b/site/profile/manifests/slurm.pp @@ -202,8 +202,8 @@ 'suspend_rate' => $suspend_rate, 'memlimit' => $os_reserved_memory, 'partitions' => $partitions, - 'slurmctl' => profile::gethostnames_with_class('profile::slurm::controller'), - 'slurmdb' => profile::gethostnames_with_class('profile::slurm::accounting'), + 'slurmctl' => profile::utils::gethostnames_with_class('profile::slurm::controller'), + 'slurmdb' => profile::utils::gethostnames_with_class('profile::slurm::accounting'), }), group => 'slurm', owner => 'slurm', @@ -244,7 +244,7 @@ { 'nodes' => $nodes, 'memlimit' => $os_reserved_memory, - 'weights' => slurm_compute_weights($nodes), + 'weights' => profile::slurm::compute_weights($nodes), }), } diff --git a/site/profile/manifests/squid.pp b/site/profile/manifests/squid.pp index a8e1507ec..1184299a0 100644 --- a/site/profile/manifests/squid.pp +++ b/site/profile/manifests/squid.pp @@ -21,7 +21,7 @@ } squid::acl { 'CLUSTER_NETWORK': type => 'src', - entries => [profile::getcidr()], + entries => [profile::utils::getcidr()], } # How can we have multiple regex entries under the same ACL name? # From Squid documentation: diff --git a/site/profile/manifests/users.pp b/site/profile/manifests/users.pp index 41bf2b9d7..420ed0aad 100644 --- a/site/profile/manifests/users.pp +++ b/site/profile/manifests/users.pp @@ -170,7 +170,7 @@ $key_value = $split[$key_type_index+1] if $key_type_index != 0 { - $key_options = ssh_split_options($split[0, $key_type_index].join(' ')) + $key_options = profile::utils::split_options($split[0, $key_type_index].join(' ')) } else { $key_options = undef } diff --git a/site/profile/templates/slurm/nodes.conf.epp b/site/profile/templates/slurm/nodes.conf.epp index dce5eae3e..cd5a2cecc 100644 --- a/site/profile/templates/slurm/nodes.conf.epp +++ b/site/profile/templates/slurm/nodes.conf.epp @@ -4,11 +4,11 @@ NodeName=DEFAULT MemSpecLimit=<%= $memlimit %> State=CLOUD # Always online computes nodes <% $nodes.each |$name, $attr| { -%> <% if !('pool' in $attr['tags']) { -%> -<%= profile::generate_slurm_node_line($name, $attr, $weights[$name]) %> +<%= profile::slurm::generate_node_line($name, $attr, $weights[$name]) %> <% }} -%> # On-demand pool compute nodes <% $nodes.each |$name, $attr| { -%> <% if 'pool' in $attr['tags'] { -%> -<%= profile::generate_slurm_node_line($name, $attr, $weights[$name]) %> +<%= profile::slurm::generate_node_line($name, $attr, $weights[$name]) %> <% }} -%>