1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
require 'puppet/type/parsedtype'
module Puppet
newtype(:host) do
ensurable
newstate(:ip) do
desc "The host's IP address, IPv4 or IPv6."
end
newstate(:alias) do
desc "Any alias the host might have. Multiple values must be
specified as an array. Note that this state has the same name
as one of the metaparams; using this state to set aliases will
make those aliases available in your Puppet scripts and also on
disk."
def insync?
@is == @should
end
# Make sure our "is" value is always an array.
def is
current = super
unless current.is_a? Array
current = [current]
end
current
end
def is_to_s
self.is.join(" ")
end
# We have to override the feeding mechanism; it might be nil or
# white-space separated
def is=(value)
# If it's just whitespace, ignore it
case value
when /^\s+$/
@is = nil
when String
@is = value.split(/\s+/)
else
@is = value
end
end
def retrieve
super
@is = [@is] unless @is.is_a?(Array)
end
# We actually want to return the whole array here, not just the first
# value.
def should
if defined? @should
if @should == [:absent]
return :absent
else
return @should
end
else
return nil
end
end
def should_to_s
@should.join(" ")
end
validate do |value|
if value =~ /\s/
raise Puppet::Error, "Aliases cannot include whitespace"
end
end
munge do |value|
if value == :absent or value == "absent"
:absent
else
# Add the :alias metaparam in addition to the state
@parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
value
end
end
end
newstate(:target) do
desc "The file in which to store service information. Only used by
those providers that write to disk (i.e., not NetInfo)."
defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@parent.class.defaultprovider.default_target
else
nil
end
}
end
newparam(:name) do
desc "The host name."
isnamevar
end
@doc = "Installs and manages host entries. For most systems, these
entries will just be in /etc/hosts, but some systems (notably OS X)
will have different solutions."
end
end
# $Id: host.rb 1866 2006-11-13 05:13:38Z luke $
|