File: host.rb

package info (click to toggle)
puppet 2.6.2-5%2Bsqueeze9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,728 kB
  • ctags: 8,726
  • sloc: ruby: 110,196; sh: 934; lisp: 263; xml: 122; sql: 103; makefile: 90; python: 84
file content (98 lines) | stat: -rwxr-xr-x 2,515 bytes parent folder | download | duplicates (2)
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
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(:host_aliases) do
      desc "Any aliases the host might have.  Multiple values must be
        specified as an array."

      def insync?(is)
        is == @should
      end

      def is_to_s(currentvalue = @is)
        currentvalue = [currentvalue] unless currentvalue.is_a? Array
        currentvalue.join(" ")
      end

      def retrieve
        is = super
        case is
        when String
          is = is.split(/\s*,\s*/)
        when Symbol
          is = [is]
        when Array
          # nothing
        else
          raise Puppet::DevError, "Invalid @is type #{is.class}"
        end
        is
      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(newvalue = @should)
        newvalue.join(" ")
      end

      validate do |value|
        raise Puppet::Error, "Host aliases cannot include whitespace" if value =~ /\s/
      end
    end

    newproperty(:target) do
      desc "The file in which to store service information.  Only used by
        those providers that write to disk."

      defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
        @resource.class.defaultprovider.default_target
        else
          nil
        end
      }
    end

    newparam(:name) do
      desc "The host name."

      isnamevar

      validate do |value|
        # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com]
        x = value.split('.').each do |hostpart|
          unless hostpart =~ /^([\d\w]+|[\d\w][\d\w\-]+[\d\w])$/
            raise Puppet::Error, "Invalid host name"
          end
        end
      end
    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