summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/filetype.rb6
-rw-r--r--lib/puppet/type.rb12
-rwxr-xr-xlib/puppet/type/cron.rb8
-rwxr-xr-xlib/puppet/type/parsedtype.rb34
-rwxr-xr-xlib/puppet/type/parsedtype/host.rb16
-rwxr-xr-xlib/puppet/type/parsedtype/port.rb66
-rw-r--r--lib/puppet/type/state.rb2
7 files changed, 83 insertions, 61 deletions
diff --git a/lib/puppet/filetype.rb b/lib/puppet/filetype.rb
index 77d356f2a..5f505e9bf 100755
--- a/lib/puppet/filetype.rb
+++ b/lib/puppet/filetype.rb
@@ -38,12 +38,12 @@ module Puppet # :nodoc:
begin
val = real_read()
@loaded = Time.now
- return val
+ return val.gsub(/# HEADER.*\n/,'')
rescue Puppet::Error => detail
raise
rescue => detail
- raise Puppet::Error, "%s could not read %s" %
- [self.class, @path]
+ raise Puppet::Error, "%s could not read %s: %s" %
+ [self.class, @path, detail]
end
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index eb0cc8282..9c5f17ac9 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -49,8 +49,6 @@ class Type < Puppet::Element
# again, silence the tests; the :notused has to be there because it's
# the namevar
- @states = []
- @parameters = [:notused]
# @paramdoc = Hash.new
@@ -128,7 +126,7 @@ class Type < Puppet::Element
def self.eachtype
@@typeary.each do |type|
# Only consider types that have names
- if type.name
+ if ! type.parameters.empty? or ! type.validstates.empty?
yield type
end
end
@@ -153,6 +151,10 @@ class Type < Puppet::Element
@objects = Hash.new
@aliases = Hash.new
+ unless defined? @parameters
+ @parameters = []
+ end
+
@validstates = {}
@paramdoc = Hash.new { |hash,key|
@@ -339,6 +341,7 @@ class Type < Puppet::Element
unless defined? @validstates
@validstates = Hash.new(false)
end
+ return unless defined? @states
@states.each { |stateklass|
name = stateklass.name
if @validstates.include?(name)
@@ -357,6 +360,7 @@ class Type < Puppet::Element
# Find the namevar
def self.namevar
unless defined? @namevar
+ return nil unless defined? @parameters and ! @parameters.empty?
@namevar = @parameters.find { |name, param|
param.isnamevar?
unless param
@@ -463,6 +467,7 @@ class Type < Puppet::Element
# Return the parameter names
def self.parameters
+ return [] unless defined? @parameters
@parameters.collect { |klass| klass.name }
end
@@ -510,6 +515,7 @@ class Type < Puppet::Element
# Return the list of validstates
def self.validstates
+ return {} unless defined? @states
unless @validstates.length == @states.length
self.buildstatehash
end
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index eca07c10e..bcb5d56ae 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -240,10 +240,10 @@ module Puppet
# Return the header placed at the top of each generated file, warning
# users that modifying this file manually is probably a bad idea.
def self.header
-%{#This file was autogenerated at #{Time.now} by puppet. While it
-# can still be managed manually, it is definitely not recommended.
-# Note particularly that the comments starting with 'Puppet Name' should
-# not be deleted, as doing so could cause duplicate cron jobs.\n}
+%{# HEADER This file was autogenerated at #{Time.now} by puppet. While it
+# HEADER can still be managed manually, it is definitely not recommended.
+# HEADER Note particularly that the comments starting with 'Puppet Name' should
+# HEADER not be deleted, as doing so could cause duplicate cron jobs.\n}
end
# Store a new instance of a cron job. Called from Cron#initialize.
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index c4c64c021..14563cf57 100755
--- a/lib/puppet/type/parsedtype.rb
+++ b/lib/puppet/type/parsedtype.rb
@@ -9,14 +9,20 @@ module Puppet
# the 'should' value to the 'is' value and to do support the right logging
# and such.
class ParsedParam < Puppet::State
- @name = :parsedparam
+ # Fix things so that the fields have to match exactly, instead
+ # of only kinda
+ def insync?
+ self.is == self.should
+ end
+
# Normally this would retrieve the current value, but our state is not
# actually capable of doing so.
def retrieve
# If we've synced, then just copy the values over and return.
# This allows this state to behave like any other state.
if defined? @synced and @synced
- @is = self.should
+ # by default, we only copy over the first value.
+ @is = @synced
@synced = false
return
end
@@ -32,30 +38,36 @@ module Puppet
def sync(nostore = false)
ebase = @parent.class.name.to_s
if @is == :notfound
- @is = self.should
+ #@is = self.should
tail = "created"
# If we're creating it, then sync all of the other states
# but tell them not to store (we'll store just once,
# at the end).
- @parent.eachstate { |state|
- next if state == self
- state.sync(true)
- }
+ unless nostore
+ @parent.eachstate { |state|
+ next if state == self
+ state.sync(true)
+ }
+ end
elsif self.should == :notfound
@parent.remove(true)
tail = "deleted"
+ #elsif @is == @should
elsif self.insync?
+ self.info "already in sync"
return nil
else
#@is = self.should
# Mark that we've synced it, but don't copy the value, because
# that will make the 'change' log inscrutable.
- @synced = true
tail = "changed"
end
+ @synced = self.should
- unless nostore
+ if nostore
+ self.retrieve
+ else
@parent.store
end
@@ -113,8 +125,8 @@ module Puppet
# Return the header placed at the top of each generated file, warning
# users that modifying this file manually is probably a bad idea.
def self.header
-%{# This file was autogenerated at #{Time.now} by puppet. While it
-# can still be managed manually, it is definitely not recommended.\n\n}
+%{# HEADER: This file was autogenerated at #{Time.now} by puppet. While it
+# HEADER: can still be managed manually, it is definitely not recommended.\n}
end
# Store a new instance of a host. Called from Host#initialize.
diff --git a/lib/puppet/type/parsedtype/host.rb b/lib/puppet/type/parsedtype/host.rb
index 4b60e7142..69c1dbe06 100755
--- a/lib/puppet/type/parsedtype/host.rb
+++ b/lib/puppet/type/parsedtype/host.rb
@@ -10,8 +10,8 @@ module Puppet
end
newstate(:aliases) do
- desc "Any aliases the host might have. Values can be either an array
- or a comma-separated list."
+ desc "Any aliases the host might have. Multiple values must be
+ specified as an array."
# We have to override the feeding mechanism; it might be nil or
# white-space separated
@@ -31,14 +31,10 @@ module Puppet
@should
end
- munge do |values|
- unless values.is_a?(Array)
- values = [values]
+ validate do |value|
+ if value =~ /\s/
+ raise Puppet::Error, "Aliases cannot include whitespace"
end
- # Split based on comma, then flatten the whole thing
- values.collect { |values|
- values.split(/,\s*/)
- }.flatten
end
end
@@ -100,7 +96,7 @@ module Puppet
end
# Convert the current object into a host-style string.
- def to_str
+ def to_s
str = "%s\t%s" % [self.state(:ip).should, self[:name]]
if state = self.state(:alias)
diff --git a/lib/puppet/type/parsedtype/port.rb b/lib/puppet/type/parsedtype/port.rb
index 2080e1086..65549d7da 100755
--- a/lib/puppet/type/parsedtype/port.rb
+++ b/lib/puppet/type/parsedtype/port.rb
@@ -7,18 +7,19 @@ module Puppet
newtype(:port, Puppet::Type::ParsedType) do
newstate(:protocols) do
desc "The protocols the port uses. Valid values are *udp* and *tcp*.
- Most services have both protocols, but not all."
+ Most services have both protocols, but not all. If you want
+ both protocols, you must specify that; Puppet replaces the
+ current values, it does not merge with them. If you specify
+ multiple protocols they must be as an array."
def is=(proto)
unless proto.is_a?(Array)
- proto = [proto]
+ proto = [proto.split(/\s+/)].flatten
end
- #self.info "setting to %s" % proto.inspect
@is = proto
end
def is
- #self.notice "returning is %s" % @is.inspect
@is
end
@@ -27,6 +28,12 @@ module Puppet
def should
@should
end
+
+ validate do |value|
+ unless value == "udp" or value == "tcp"
+ raise Puppet::Error, "Protocols can be either 'udp' or 'tcp'"
+ end
+ end
end
newstate(:number) do
@@ -38,8 +45,8 @@ module Puppet
end
newstate(:aliases) do
- desc "Any aliases the port might have. Values can be either an array
- or a comma-separated list."
+ desc "Any aliases the port might have. Multiple values must be specified
+ as an array."
# We have to override the feeding mechanism; it might be nil or
# white-space separated
@@ -59,14 +66,10 @@ module Puppet
@should
end
- munge do |values|
- unless values.is_a?(Array)
- values = [values]
+ validate do |value|
+ if value =~ /\s/
+ raise Puppet::Error, "Aliases cannot have whitespace in them"
end
- # Split based on comma, then flatten the whole thing
- values.collect { |values|
- values.split(/,\s*/)
- }.flatten
end
end
@@ -167,12 +170,12 @@ module Puppet
end
if hash[:protocols]
+ # The protocol can be a symbol, so...
+ if proto.is_a?(Symbol)
+ proto = []
+ end
# Check to see if it already includes our proto
- if proto.include?(hash[:protocols])
- Puppet.warning(
- "There is already a port with our name and protocols"
- )
- else
+ unless proto.include?(hash[:protocols])
# We are missing their proto
proto << hash[:protocols]
#Puppet.info "new proto is %s" % proto.inspect
@@ -190,19 +193,24 @@ module Puppet
end
# Convert the current object into a host-style string.
- def to_str
- str = "%s\t%s/%s" % [self[:name], self.state(:number).should,
- self.state(:protocols).should]
-
- if state = self.state(:alias)
- str += "\t%s" % state.should.join(" ")
- end
+ def to_s
+ self.state(:protocols).should.collect { |proto|
+ str = "%s\t%s/%s" % [self[:name], self.state(:number).should,
+ proto]
- if state = self.state(:description)
- str += "\t# %s" % state.should
- end
+ if state = self.state(:alias)
+ str += "\t%s" % state.should.join(" ")
+ else
+ str += "\t"
+ end
- str
+ if state = self.state(:description)
+ str += "\t# %s" % state.should
+ else
+ str += "\t"
+ end
+ str
+ }.join("\n")
end
end
end
diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb
index 6bd1d3b07..5ce9718b0 100644
--- a/lib/puppet/type/state.rb
+++ b/lib/puppet/type/state.rb
@@ -198,7 +198,7 @@ class State < Puppet::Parameter
end
def should_to_s
- @should
+ @should.join(" ")
end
def to_s