From eda301b7ba8f8827d1c9973ffaba0c1c7a029d98 Mon Sep 17 00:00:00 2001 From: Raphaƫl Pinson Date: Fri, 12 Apr 2013 12:29:45 +0200 Subject: Add spec for dhcp::subnet and improve template and definition --- templates/subnet.conf.erb | 49 +++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'templates/subnet.conf.erb') diff --git a/templates/subnet.conf.erb b/templates/subnet.conf.erb index 89ca82f..11f9ed4 100644 --- a/templates/subnet.conf.erb +++ b/templates/subnet.conf.erb @@ -1,33 +1,28 @@ # File managed by puppet -<% if netmask -%> -subnet <%=name%> netmask <%=netmask%> { -<% else -%> -subnet <%=name%> netmask <%=netmask_eth0%> { -<% end -%> -<% if routers and not routers.empty? -%> - option routers <%= routers.collect! {|i| "#{i}" }.join(",") %>; -<% else -%> - option routers <%=network_eth0%>; -<% end -%> -<% if subnet_mask -%> - option subnet-mask <%=subnet_mask%>; -<% elsif netmask -%> - option subnet-mask <%=netmask%>; -<% else -%> - option subnet-mask <%=netmask_eth0%>; -<% end -%> - option broadcast-address <%=broadcast%>; -<% if domain_name -%> - option domain-name "<%=domain_name%>"; -<% else -%> - option domain-name "<%=domain%>"; -<% end -%> -<% if other_opts and not other_opts.empty? -%> - <% if other_opts.is_a?(Array) -%> -<%= other_opts.collect! {|i| " #{i};"}.join("\n") %> +<%- + _netmask = @netmask || scope.lookupvar('::netmask_eth0') + scope.function_validate_re([_netmask, @ip_re]) -%> +subnet <%= @name %> netmask <%= _netmask %> { +<%- + _routers = @routers unless @routers.empty? + _routers ||= [scope.lookupvar('::netmask_eth0')] + scope.function_validate_array([_routers]) -%> + option routers <%= _routers.collect! {|i| "#{i}" }.join(',') %>; +<%- + _subnet_mask = @subnet_mask || _netmask + scope.function_validate_re([_subnet_mask, @ip_re]) -%> + option subnet-mask <%= _subnet_mask %>; + option broadcast-address <%= @broadcast %>; +<%- + _domain_name = @domain_name || scope.lookupvar('::domain') + scope.function_validate_re([_domain_name, '^\S+$']) -%> + option domain-name "<%= _domain_name %>"; +<% unless @other_opts.empty? -%> + <% if @other_opts.is_a?(Array) -%> +<%= @other_opts.collect! {|i| " #{i};"}.join("\n") %> <% else -%> - <%=other_opts%>; + <%= @other_opts %>; <% end -%> <% end -%> } -- cgit v1.2.3