summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-01-22 11:58:40 +1100
committerJames Turnbull <james@lovedthanlost.net>2008-01-22 11:58:40 +1100
commit1ccc9c3b47e7e96f70fa48b2a21c5e10dc103d6e (patch)
treec7cc7c39fa4c8f34519a9c6d8a7d8f0c35eb5033
parent1f5767439d31c8dd7bce2ee9fb6a91c4e417f8c1 (diff)
downloadpuppet-1ccc9c3b47e7e96f70fa48b2a21c5e10dc103d6e.tar.gz
puppet-1ccc9c3b47e7e96f70fa48b2a21c5e10dc103d6e.tar.xz
puppet-1ccc9c3b47e7e96f70fa48b2a21c5e10dc103d6e.zip
Fixes ticket #151 - host type now validates IP addresses and hostnames/FQDNs - the regex for the latter is quite complex but I have found it bullet-proof in the past
-rwxr-xr-xlib/puppet/type/host.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index be5c2ed72..7f633d989 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -1,9 +1,16 @@
+require 'ipaddr'
+
module Puppet
newtype(:host) do
ensurable
newproperty(:ip) do
desc "The host's IP address, IPv4 or IPv6."
+
+ validate do |value|
+ addr = IPAddr.new(value)
+ end
+
end
newproperty(:alias) do
@@ -78,6 +85,12 @@ module Puppet
desc "The host name."
isnamevar
+
+ validate do |value|
+ unless value =~ /^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/
+ raise Puppet::Error, "Invalid host name"
+ end
+ end
end
@doc = "Installs and manages host entries. For most systems, these