blob: 99ddcd2f4fc50bae04b78d9f54d8925b85dd8cda (
plain)
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
114
115
|
require 'puppet/provider/parsedfile'
require 'erb'
Puppet::Type.type(:interface).provide(:sunos,
:default_target => "/etc/hostname.lo0",
:parent => Puppet::Provider::ParsedFile,
:filetype => :flat
) do
confine :kernel => "SunOS"
# Two types of lines:
# the first line does not start with 'addif'
# the rest do
record_line :sunos, :fields => %w{interface_type name ifopts onboot}, :rts => true, :absent => "", :block_eval => :instance do
# Parse our interface line
def process(line)
details = {:ensure => :present}
values = line.split(/\s+/)
# Are we the primary interface?
if values[0] == "addif"
details[:interface_type] = :alias
values.shift
else
details[:interface_type] = :normal
end
# Should the interface be up by default?
if values[-1] == "up"
details[:onboot] = :true
values.pop
else
details[:onboot] = :false
end
# Set the interface name.
details[:name] = values.shift
# Handle any interface options
unless values.empty?
details[:ifopts] = values.join(" ")
end
return details
end
# Turn our record into a line.
def to_line(details)
ret = []
if details[:interface_type] != :normal
ret << "addif"
end
ret << details[:name]
if details[:ifopts] and details[:ifopts] != :absent
if details[:ifopts].is_a?(Array)
ret << details[:ifopts].join(" ")
else
ret << details[:ifopts]
end
end
if details[:onboot] and details[:onboot] != :false
ret << "up"
end
return ret.join(" ")
end
end
def self.header
# over-write the default puppet behaviour of adding a header
# because on further investigation this breaks the solaris
# init scripts
%{}
end
# Get a list of interface instances.
def self.instances
Dir.glob("/etc/hostname.*").collect do |file|
# We really only expect one record from each file
parse(file).shift
end.collect { |record| new(record) }
end
def self.match(hash)
# see if we can match the has against an existing object
if model.find { |obj| obj.value(:name) == hash[:name] }
return obj
else
return false
end
end
# Prefetch our interface list, yo.
def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
resource.provider = prov
end
end
end
# Where should the file be written out? Can be overridden by setting
# :target in the model.
def file_path
unless resource[:interface]
raise ArgumentError, "You must provide the interface name on Solaris"
end
return File.join("/etc", "hostname." + resource[:interface])
end
end
|