summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/metatype/closure.rb4
-rw-r--r--lib/puppet/node/catalog.rb2
-rw-r--r--lib/puppet/parser/ast/definition.rb3
-rw-r--r--lib/puppet/parser/ast/hostclass.rb9
-rw-r--r--lib/puppet/parser/interpreter.rb4
-rw-r--r--lib/puppet/parser/resource.rb9
-rw-r--r--lib/puppet/provider/interface/redhat.rb130
-rwxr-xr-xlib/puppet/type/exec.rb5
-rwxr-xr-xlib/puppet/type/mailalias.rb2
-rw-r--r--lib/puppet/type/package.rb8
-rw-r--r--lib/puppet/type/service.rb9
11 files changed, 99 insertions, 86 deletions
diff --git a/lib/puppet/metatype/closure.rb b/lib/puppet/metatype/closure.rb
index 259854411..673a2359d 100644
--- a/lib/puppet/metatype/closure.rb
+++ b/lib/puppet/metatype/closure.rb
@@ -20,6 +20,10 @@ class Puppet::Type
end
end
+ def isomorphic?
+ self.class.isomorphic?
+ end
+
# is the instance a managed instance? A 'yes' here means that
# the instance was created from the language, vs. being created
# in order resolve other questions, such as finding a package
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index d680de9a0..f885a41ee 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -73,7 +73,7 @@ class Puppet::Node::Catalog < Puppet::PGraph
# If the name and title differ, set up an alias
#self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title
if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title
- self.alias(resource, resource.name) if resource.class.isomorphic?
+ self.alias(resource, resource.name) if resource.isomorphic?
end
resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb
index 2b7506446..0c65c702c 100644
--- a/lib/puppet/parser/ast/definition.rb
+++ b/lib/puppet/parser/ast/definition.rb
@@ -24,9 +24,6 @@ class Puppet::Parser::AST::Definition < Puppet::Parser::AST::Branch
# Create a resource that knows how to evaluate our actual code.
def evaluate(scope)
- # Do nothing if the resource already exists; this provides the singleton nature classes need.
- return if scope.catalog.resource(self.class.name, self.classname)
-
resource = Puppet::Parser::Resource.new(:type => self.class.name, :title => self.classname, :scope => scope, :source => scope.source)
scope.catalog.tag(*resource.tags)
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb
index 8d4d01660..7f89f8151 100644
--- a/lib/puppet/parser/ast/hostclass.rb
+++ b/lib/puppet/parser/ast/hostclass.rb
@@ -21,7 +21,14 @@ class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition
# Make sure our parent class has been evaluated, if we have one.
def evaluate(scope)
if parentclass and ! scope.catalog.resource(self.class.name, parentclass)
- resource = parentobj.evaluate(scope)
+ parent_resource = parentobj.evaluate(scope)
+ end
+
+ # Do nothing if the resource already exists; this makes sure we don't
+ # get multiple copies of the class resource, which helps provide the
+ # singleton nature of classes.
+ if resource = scope.catalog.resource(self.class.name, self.classname)
+ return resource
end
super
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 33f66e8c2..d4655c403 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -28,10 +28,8 @@ class Puppet::Parser::Interpreter
begin
return Puppet::Parser::Compiler.new(node, env_parser).compile
rescue => detail
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, detail.to_s + " on node %s" % node.name
- if Puppet[:trace]
- puts detail.backtrace
- end
end
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index fb0799011..46be89ca2 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -133,6 +133,15 @@ class Puppet::Parser::Resource
tag(@ref.title) if valid_tag?(@ref.title.to_s)
end
+ # Is this resource modeling an isomorphic resource type?
+ def isomorphic?
+ if builtin?
+ return @ref.builtintype.isomorphic?
+ else
+ return true
+ end
+ end
+
# Merge an override resource in. This will throw exceptions if
# any overrides aren't allowed.
def merge(resource)
diff --git a/lib/puppet/provider/interface/redhat.rb b/lib/puppet/provider/interface/redhat.rb
index aa217620e..4a9fcb491 100644
--- a/lib/puppet/provider/interface/redhat.rb
+++ b/lib/puppet/provider/interface/redhat.rb
@@ -5,7 +5,7 @@ Puppet::Type.type(:interface).provide(:redhat) do
desc "Manage network interfaces on Red Hat operating systems. This provider
parses and generates configuration files in ``/etc/sysconfig/network-scripts``."
- INTERFACE_DIR = "/etc/sysconfig/network-scripts"
+ INTERFACE_DIR = "/etc/sysconfig/network-scripts"
confine :exists => INTERFACE_DIR
defaultfor :operatingsystem => [:fedora, :centos, :redhat]
@@ -43,52 +43,52 @@ NETMASK=<%= self.netmask %>
BROADCAST=
LOOPBACKDUMMY
- # maximum number of dummy interfaces
- @max_dummies = 10
+ # maximum number of dummy interfaces
+ @max_dummies = 10
- # maximum number of aliases per interface
- @max_aliases_per_iface = 10
+ # maximum number of aliases per interface
+ @max_aliases_per_iface = 10
- @@dummies = []
- @@aliases = Hash.new { |hash, key| hash[key] = [] }
+ @@dummies = []
+ @@aliases = Hash.new { |hash, key| hash[key] = [] }
- # calculate which dummy interfaces are currently already in
- # use prior to needing to call self.next_dummy later on.
- def self.instances
- # parse all of the config files at once
- Dir.glob("%s/ifcfg-*" % INTERFACE_DIR).collect do |file|
- record = parse(file)
+ # calculate which dummy interfaces are currently already in
+ # use prior to needing to call self.next_dummy later on.
+ def self.instances
+ # parse all of the config files at once
+ Dir.glob("%s/ifcfg-*" % INTERFACE_DIR).collect do |file|
+ record = parse(file)
- # store the existing dummy interfaces
+ # store the existing dummy interfaces
@@dummies << record[:ifnum] if (record[:interface_type] == :dummy and ! @@dummies.include?(record[:ifnum]))
@@aliases[record[:interface]] << record[:ifnum] if record[:interface_type] == :alias
new(record)
- end
- end
-
- # return the next avaliable dummy interface number, in the case where
- # ifnum is not manually specified
- def self.next_dummy
- @max_dummies.times do |i|
- unless @@dummies.include?(i.to_s)
- @@dummies << i.to_s
- return i.to_s
- end
- end
- end
-
- # return the next available alias on a given interface, in the case
- # where ifnum if not manually specified
- def self.next_alias(interface)
- @max_aliases_per_iface.times do |i|
- unless @@aliases[interface].include?(i.to_s)
- @@aliases[interface] << i.to_s
- return i.to_s
- end
- end
- end
+ end
+ end
+
+ # return the next avaliable dummy interface number, in the case where
+ # ifnum is not manually specified
+ def self.next_dummy
+ @max_dummies.times do |i|
+ unless @@dummies.include?(i.to_s)
+ @@dummies << i.to_s
+ return i.to_s
+ end
+ end
+ end
+
+ # return the next available alias on a given interface, in the case
+ # where ifnum if not manually specified
+ def self.next_alias(interface)
+ @max_aliases_per_iface.times do |i|
+ unless @@aliases[interface].include?(i.to_s)
+ @@aliases[interface] << i.to_s
+ return i.to_s
+ end
+ end
+ end
# base the ifnum, for dummy / loopback interface in linux
# on the last octect of the IP address
@@ -139,14 +139,14 @@ LOOPBACKDUMMY
# on whether we are adding an alias to a real interface, or a loopback
# address (also dummy) on linux. For linux it's quite involved, and we
# will use an ERB template
- def generate
+ def generate
itype = self.interface_type == :alias ? :alias : :normal
self.class.template(itype).result(binding)
- end
+ end
# Where should the file be written out?
- # This defaults to INTERFACE_DIR/ifcfg-<namevar>, but can have a
- # more symbolic name by setting interface_desc in the type.
+ # This defaults to INTERFACE_DIR/ifcfg-<namevar>, but can have a
+ # more symbolic name by setting interface_desc in the type.
def file_path
if resource and val = resource[:interface_desc]
desc = val
@@ -185,16 +185,16 @@ LOOPBACKDUMMY
end
end
- # create the device name, so this based on the IP, and interface + type
- def device
- case @resource.should(:interface_type)
- when :loopback
- @property_hash[:ifnum] ||= self.class.next_dummy
- return "dummy" + @property_hash[:ifnum]
- when :alias
- @property_hash[:ifnum] ||= self.class.next_alias(@resource[:interface])
- return @resource[:interface] + ":" + @property_hash[:ifnum]
- end
+ # create the device name, so this based on the IP, and interface + type
+ def device
+ case @resource.should(:interface_type)
+ when :loopback
+ @property_hash[:ifnum] ||= self.class.next_dummy
+ return "dummy" + @property_hash[:ifnum]
+ when :alias
+ @property_hash[:ifnum] ||= self.class.next_alias(@resource[:interface])
+ return @resource[:interface] + ":" + @property_hash[:ifnum]
+ end
end
# Set the name to our ip address.
@@ -202,19 +202,19 @@ LOOPBACKDUMMY
@property_hash[:name] = value
end
- # whether the device is to be brought up on boot or not. converts
- # the true / false of the type, into yes / no values respectively
- # writing out the ifcfg-* files
- def on_boot
- case @property_hash[:onboot].to_s
- when "true"
- return "yes"
- when "false"
- return "no"
- else
- return "neither"
- end
- end
+ # whether the device is to be brought up on boot or not. converts
+ # the true / false of the type, into yes / no values respectively
+ # writing out the ifcfg-* files
+ def on_boot
+ case @property_hash[:onboot].to_s
+ when "true"
+ return "yes"
+ when "false"
+ return "no"
+ else
+ return "neither"
+ end
+ end
# Mark whether the interface should be started on boot.
def on_boot=(value)
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index f8049236f..2772b54a8 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -211,10 +211,7 @@ module Puppet
log the output when the command reports an error. Values are
**true**, *false*, *on_failure*, and any legal log level."
- values = [:true, :false, :on_failure]
- # And all of the log levels
- Puppet::Util::Log.eachlevel { |level| values << level }
- newvalues(*values)
+ newvalues(:true, :false, :on_failure)
end
newparam(:refresh) do
diff --git a/lib/puppet/type/mailalias.rb b/lib/puppet/type/mailalias.rb
index 92f609267..50ca26ef6 100755
--- a/lib/puppet/type/mailalias.rb
+++ b/lib/puppet/type/mailalias.rb
@@ -9,7 +9,7 @@ module Puppet
end
newproperty(:recipient, :array_matching => :all) do
- desc "Where email should should be sent. Multiple values
+ desc "Where email should be sent. Multiple values
should be specified as an array."
def is_to_s(value)
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index ee2871ce2..f004f7c42 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -211,14 +211,6 @@ module Puppet
desc "Where to find the actual package. This must be a local file
(or on a network file system) or a URL that your specific
packaging type understands; Puppet will not retrieve files for you."
-
- validate do |value|
- unless value =~ /^#{File::SEPARATOR}/ or value =~ /\w+:\/\//
- self.fail(
- "Package sources must be fully qualified files or URLs, depending on the platform."
- )
- end
- end
end
newparam(:instance) do
desc "A read-only parameter set by the package."
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index c41a7883b..1b625cc41 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -28,6 +28,8 @@ module Puppet
feature :enableable, "The provider can enable and disable the service",
:methods => [:disable, :enable, :enabled?]
+ feature :controllable, "The provider uses a control variable."
+
newproperty(:enable, :required_features => :enableable) do
desc "Whether a service should be enabled to start at boot.
This property behaves quite differently depending on the platform;
@@ -163,6 +165,13 @@ module Puppet
desc "Specify a *stop* command manually."
end
+ newparam(:control) do
+ desc "The control variable used to manage services (originally for HP-UX).
+ Defaults to the upcased service name plus ``START`` replacing dots with
+ underscores, for those providers that support the ``controllable`` feature."
+ defaultto { resource.name.gsub(".","_").upcase + "_START" if resource.provider.controllable? }
+ end
+
newparam :hasrestart do
desc "Specify that an init script has a ``restart`` option. Otherwise,
the init script's ``stop`` and ``start`` methods are used."