rename dsa-puppet-stuff to puppet-crontab
[mirror/dsa-puppet.git] / modules / roles / templates / static-mirroring / static-components.conf.erb
index 117828e..c04a3a5 100644 (file)
@@ -10,39 +10,57 @@ lines = []
 lines << "# This file has been autogenerated and pushed by puppet.  Edit static-components.yaml in puppet."
 lines << "# <master> <service> <source host> <directory> <extra push hosts, comma separated> <hosts to not mirror this component to>"
 
+# this is the list of static mirrors, or, technically, the list of
+# nodes with the roles::static_mirror class applied to it. this should
+# be populated from outside the template from PuppetDB, see:
+# modules/roles/manifests/static_base.pp
+mirrors = @static_mirrors
 
 config = YAML.load(File.open('/etc/puppet/modules/roles/misc/static-components.yaml').read)
-mirrors = scope.lookupvar('site::roles')['static_mirror']
 
-config['components'].each_pair do |component, conf|
+
+config['mirrors'].each do |mirror, mc|
+       if not mirrors.include?(mirror)
+               fail("static-components.yaml defines mirror #{mirror} but we do not know of it")
+       end
+end
+
+config['components'].each_pair do |component_name, component_conf|
        %w{exclude-mirrors extra-push limit-mirrors}.each do |key|
-               conf[key] = [] unless conf.has_key?(key)
+               component_conf[key] = [] unless component_conf.has_key?(key)
        end
 
-       srchost, srcpath = conf['source'].split(':', 2)
+       srchost, srcpath = component_conf['source'].split(':', 2)
 
-       config['mirrors'].each do |mirror, mc|
-               next unless mirrors.include?(mirror)
+       if not component_conf['exclude-mirrors'].empty? and \
+          not component_conf['limit-mirrors'].empty? then
+               fail("Component #{component_name} specifies both exclude-mirrors and limit-mirrors.")
+       end
 
-               if mc.has_key?('components-include') and not mc['components-include'].include?(component)
-                       conf['exclude-mirrors'] << mirror
+       # In the end, we care about an exclude list, so let's invert limit-mirror and turn it into an exclude list
+       if not component_conf['limit-mirrors'].empty? then
+               component_conf['exclude-mirrors'] = mirrors.select do |m|
+                       not component_conf['limit-mirrors'].include?(m)
                end
        end
-       if conf['limit-mirrors'].size > 0
-               mirrors.each do |mirror|
-                       if not conf['limit-mirrors'].include?(mirror)
-                               next if conf['exclude-mirrors'].include?(mirror) # if it's already excluded, do not add it again
-                               conf['exclude-mirrors'] << mirror
-                       end
+
+       # mirrors may also specify limits as components-include (thus excluding all others).  Apply this
+       config['mirrors'].each do |mirror, mc|
+               mirror_components_include = mc.fetch('components-include', [])
+               next if mirror_components_include.empty?
+
+               if not mirror_components_include.include?(component_name)
+                       next if component_conf['exclude-mirrors'].include?(mirror) # do not exclude twice
+                       component_conf['exclude-mirrors'] << mirror
                end
        end
 
-       exclude = conf['exclude-mirrors'].join(',')
-       exclude = '-' unless exclude != ""
-       extrapush = conf['extra-push'].join(',')
-       extrapush = '-' unless extrapush != ""
+       exclude = component_conf['exclude-mirrors'].sort().join(',')
+       exclude = '-' if exclude == ""
+       extrapush = component_conf['extra-push'].sort().join(',')
+       extrapush = '-' if extrapush == ""
 
-       lines << "#{conf['master']} #{component} #{srchost} #{srcpath} #{extrapush} #{exclude}"
+       lines << "#{component_conf['master']} #{component_name} #{srchost} #{srcpath} #{extrapush} #{exclude}"
 end
 lines.join("\n")
 %>