diff options
| author | James Turnbull <james@lovedthanlost.net> | 2008-01-25 22:49:48 +1100 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-01-25 22:49:48 +1100 |
| commit | 9a290bb646e23191184230243ef58cc0c9501400 (patch) | |
| tree | ee98091c5c26b03d9e9231ed29d97a28f6c56384 /lib/puppet | |
| parent | 4a7fcfc761aa086488b255f457373f6626498e72 (diff) | |
Second attempt to fix ticket #151 - host type now validates IP addresses and hostnames/FQDNs
Diffstat (limited to 'lib/puppet')
| -rwxr-xr-x | lib/puppet/type/host.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index be5c2ed72..2a04474e8 100755 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -1,9 +1,18 @@ +require 'ipaddr' + module Puppet newtype(:host) do ensurable newproperty(:ip) do desc "The host's IP address, IPv4 or IPv6." + + validate do |value| + unless value =~ /((([0-9a-fA-F]+:){7}[0-9a-fA-F]+)|(([0-9a-fA-F]+:)*[0-9a-fA-F]+)?::(([0-9a-fA-F]+:)*[0-9a-fA-F]+)?)|((25[0-5]|2[0-4][\d]|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})/ + raise Puppet::Error, "Invalid IP address" + end + end + end newproperty(:alias) do @@ -78,6 +87,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 |
