summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
committerMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
commit3dde838ac992571e13262ea29ba3a0eb8152e753 (patch)
tree90520cf62bfa2f1bb9c992bbfe1bc47ae10471f2 /lib/puppet/provider
parentfe45c2417af580597cd39adec96a30a05a7cd66a (diff)
parent3ab44c7ce01ab86a995deb66228f5be95239c92a (diff)
Merge branch 'next'
* next: (204 commits) Revert "(#6928) Removed --ignoreimport" Updated CHANGELOG for 2.6.8rc1 (#6928) Removed --ignoreimport (#6928) Remove --parseonly (#6928) Add a Parser face with Validate action (#6830) Fix sha1 to digest/sha1 require issue for Ruby 1.9 (#6830) Fix UTF-8 encoding issue for Ruby 1.9 (#6830) Fix string method sub call on a symbol for Ruby 1.9 (#2331) Remove darwinports pkg provider, replace with rewritten macports provider (#7059) handle inherited action binding scope maint: ensure we handle '-foo=' options correctly in faces. (#2150) Fix File const lookup when configuring routes Fixed #7082 - Added system support for groups maint: install erb templates under lib/ maint: clean up the spec test headers in bulk. (#7056) Use 'face' rather than 'faces' in the production code. maint: eliminate deprecated since 2008 code from Puppet. (#6117) Add POST support to indirector requests (#6962) Move option handling into #parse_options, not #preinit. maint: whitespace cleanup for puppet/util/command_line. ...
Diffstat (limited to 'lib/puppet/provider')
-rw-r--r--lib/puppet/provider/augeas/augeas.rb24
-rwxr-xr-xlib/puppet/provider/cron/crontab.rb8
-rw-r--r--lib/puppet/provider/group/directoryservice.rb14
-rw-r--r--lib/puppet/provider/group/groupadd.rb3
-rw-r--r--lib/puppet/provider/interface/base.rb0
-rw-r--r--lib/puppet/provider/interface/cisco.rb33
-rw-r--r--lib/puppet/provider/mcx/mcxcontent.rb19
-rw-r--r--lib/puppet/provider/nameservice/directoryservice.rb14
-rw-r--r--lib/puppet/provider/network_device.rb59
-rwxr-xr-xlib/puppet/provider/package/darwinport.rb86
-rwxr-xr-xlib/puppet/provider/package/macports.rb106
-rw-r--r--lib/puppet/provider/package/pkgdmg.rb17
-rw-r--r--lib/puppet/provider/user/directoryservice.rb14
-rw-r--r--lib/puppet/provider/vlan/cisco.rb34
14 files changed, 246 insertions, 185 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 5488c6674..a16f54bd7 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -1,21 +1,17 @@
-#--
-# Copyright (C) 2008 Red Hat Inc.
#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
+# Copyright 2011 Bryan Kearney <bkearney@redhat.com>
#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# Author: Bryan Kearney <bkearney@redhat.com>
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
require 'augeas' if Puppet.features.augeas?
require 'strscan'
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb
index 8a347b331..a554363c8 100755
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -11,13 +11,7 @@ tab = case Facter.value(:operatingsystem)
- Puppet::Type.type(:cron).provide(
- :crontab,
- :parent => Puppet::Provider::ParsedFile,
- :default_target => ENV["USER"] || "root",
-
- :filetype => tab
-) do
+Puppet::Type.type(:cron).provide(:crontab, :parent => Puppet::Provider::ParsedFile, :default_target => ENV["USER"] || "root", :filetype => tab) do
commands :crontab => "crontab"
text_line :comment, :match => %r{^#}, :post_parse => proc { |record|
diff --git a/lib/puppet/provider/group/directoryservice.rb b/lib/puppet/provider/group/directoryservice.rb
index 97fee883d..e11284898 100644
--- a/lib/puppet/provider/group/directoryservice.rb
+++ b/lib/puppet/provider/group/directoryservice.rb
@@ -1,17 +1,3 @@
-# Created by Jeff McCune on 2007-07-22
-# Copyright (c) 2007. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation (version 2 of the License)
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
-
require 'puppet/provider/nameservice/directoryservice'
Puppet::Type.type(:group).provide :directoryservice, :parent => Puppet::Provider::NameService::DirectoryService do
diff --git a/lib/puppet/provider/group/groupadd.rb b/lib/puppet/provider/group/groupadd.rb
index 82ed4c0c7..bcc08d9f7 100644
--- a/lib/puppet/provider/group/groupadd.rb
+++ b/lib/puppet/provider/group/groupadd.rb
@@ -9,6 +9,8 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
commands :add => "groupadd", :delete => "groupdel", :modify => "groupmod"
+ has_feature :system_groups
+
verify :gid, "GID must be an integer" do |value|
value.is_a? Integer
end
@@ -21,6 +23,7 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
end
end
cmd << "-o" if @resource.allowdupe?
+ cmd << "-r" if @resource.system?
cmd << @resource[:name]
cmd
diff --git a/lib/puppet/provider/interface/base.rb b/lib/puppet/provider/interface/base.rb
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/lib/puppet/provider/interface/base.rb
diff --git a/lib/puppet/provider/interface/cisco.rb b/lib/puppet/provider/interface/cisco.rb
new file mode 100644
index 000000000..f3bd202e9
--- /dev/null
+++ b/lib/puppet/provider/interface/cisco.rb
@@ -0,0 +1,33 @@
+require 'puppet/util/network_device/cisco/device'
+require 'puppet/provider/network_device'
+
+Puppet::Type.type(:interface).provide :cisco, :parent => Puppet::Provider::NetworkDevice do
+
+ desc "Cisco switch/router provider for interface."
+
+ mk_resource_methods
+
+ def self.lookup(url, name)
+ interface = nil
+ network_gear = Puppet::Util::NetworkDevice::Cisco::Device.new(url)
+ network_gear.command do |ng|
+ interface = network_gear.interface(name)
+ end
+ interface
+ end
+
+ def initialize(*args)
+ super
+ end
+
+ def flush
+ device.command do |device|
+ device.new_interface(name).update(former_properties, properties)
+ end
+ super
+ end
+
+ def device
+ @device ||= Puppet::Util::NetworkDevice::Cisco::Device.new(resource[:device_url])
+ end
+end
diff --git a/lib/puppet/provider/mcx/mcxcontent.rb b/lib/puppet/provider/mcx/mcxcontent.rb
index 3ad437b53..0c0061278 100644
--- a/lib/puppet/provider/mcx/mcxcontent.rb
+++ b/lib/puppet/provider/mcx/mcxcontent.rb
@@ -1,22 +1,3 @@
-#--
-# Copyright (C) 2008 Jeffrey J McCune.
-
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-# Author: Jeff McCune <mccune.jeff@gmail.com>
-
require 'tempfile'
Puppet::Type.type(:mcx).provide :mcxcontent, :parent => Puppet::Provider do
diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb
index 2e3480985..c1139a679 100644
--- a/lib/puppet/provider/nameservice/directoryservice.rb
+++ b/lib/puppet/provider/nameservice/directoryservice.rb
@@ -1,17 +1,3 @@
-# Created by Jeff McCune on 2007-07-22
-# Copyright (c) 2007. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation (version 2 of the License)
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
-
require 'puppet'
require 'puppet/provider/nameservice'
require 'facter/util/plist'
diff --git a/lib/puppet/provider/network_device.rb b/lib/puppet/provider/network_device.rb
new file mode 100644
index 000000000..58865fddc
--- /dev/null
+++ b/lib/puppet/provider/network_device.rb
@@ -0,0 +1,59 @@
+
+# This is the base class of all prefetched network device provider
+class Puppet::Provider::NetworkDevice < Puppet::Provider
+
+ def self.lookup(url, name)
+ raise "This provider doesn't implement the necessary lookup method"
+ end
+
+ def self.prefetch(resources)
+ resources.each do |name, resource|
+ if result = lookup(resource[:device_url], name)
+ result[:ensure] = :present
+ resource.provider = new(result)
+ else
+ resource.provider = new(:ensure => :absent)
+ end
+ end
+ end
+
+ def exists?
+ @property_hash[:ensure] != :absent
+ end
+
+ def initialize(*args)
+ super
+
+ # Make a duplicate, so that we have a copy for comparison
+ # at the end.
+ @properties = @property_hash.dup
+ end
+
+ def create
+ @property_hash[:ensure] = :present
+ self.class.resource_type.validproperties.each do |property|
+ if val = resource.should(property)
+ @property_hash[property] = val
+ end
+ end
+ end
+
+ def destroy
+ @property_hash[:ensure] = :absent
+ end
+
+ def flush
+ @property_hash.clear
+ end
+
+ def self.instances
+ end
+
+ def former_properties
+ @properties.dup
+ end
+
+ def properties
+ @property_hash.dup
+ end
+end \ No newline at end of file
diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb
deleted file mode 100755
index c5f9ba28f..000000000
--- a/lib/puppet/provider/package/darwinport.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require 'puppet/provider/package'
-
-Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Package do
- desc "Package management using DarwinPorts on OS X."
-
- confine :operatingsystem => :darwin
- commands :port => "/opt/local/bin/port"
-
- def self.eachpkgashash
- # list out all of the packages
- open("| #{command(:port)} list installed") { |process|
- regex = %r{(\S+)\s+@(\S+)\s+(\S+)}
- fields = [:name, :ensure, :location]
- hash = {}
-
- # now turn each returned line into a package object
- process.each { |line|
- hash.clear
-
- if match = regex.match(line)
- fields.zip(match.captures) { |field,value|
- hash[field] = value
- }
-
- hash.delete :location
- hash[:provider] = self.name
- yield hash.dup
- else
- raise Puppet::DevError,
- "Failed to match dpkg line #{line}"
- end
- }
- }
- end
-
- def self.instances
- packages = []
-
- eachpkgashash do |hash|
- packages << new(hash)
- end
-
- packages
- end
-
- def install
- should = @resource.should(:ensure)
-
- # Seems like you can always say 'upgrade'
- output = port "upgrade", @resource[:name]
- if output =~ /^Error: No port/
- raise Puppet::ExecutionFailure, "Could not find package #{@resource[:name]}"
- end
- end
-
- def query
- version = nil
- self.class.eachpkgashash do |hash|
- return hash if hash[:name] == @resource[:name]
- end
-
- nil
- end
-
- def latest
- info = port :search, "^#{@resource[:name]}$"
-
- if $CHILD_STATUS != 0 or info =~ /^Error/
- return nil
- end
-
- ary = info.split(/\s+/)
- version = ary[2].sub(/^@/, '')
-
- version
- end
-
- def uninstall
- port :uninstall, @resource[:name]
- end
-
- def update
- install
- end
-end
-
diff --git a/lib/puppet/provider/package/macports.rb b/lib/puppet/provider/package/macports.rb
new file mode 100755
index 000000000..c43eb72f3
--- /dev/null
+++ b/lib/puppet/provider/package/macports.rb
@@ -0,0 +1,106 @@
+require 'puppet/provider/package'
+
+Puppet::Type.type(:package).provide :macports, :parent => Puppet::Provider::Package do
+ desc "Package management using MacPorts on OS X.
+
+ Supports MacPorts versions and revisions, but not variants.
+ Variant preferences may be specified using the MacPorts variants.conf file
+ http://guide.macports.org/chunked/internals.configuration-files.html#internals.configuration-files.variants-conf
+
+ When specifying a version in the Puppet DSL, only specify the version, not the revision
+ Revisions are only used internally for ensuring the latest version/revision of a port.
+ "
+
+ confine :operatingsystem => :darwin
+ commands :port => "/opt/local/bin/port"
+
+ has_feature :installable
+ has_feature :uninstallable
+ has_feature :upgradeable
+ has_feature :versionable
+
+
+ def self.parse_installed_query_line(line)
+ regex = /(\S+)\s+@(\S+)_(\S+)\s+\(active\)/
+ fields = [:name, :ensure, :revision]
+ hash_from_line(line, regex, fields)
+ end
+
+ def self.parse_info_query_line(line)
+ regex = /(\S+)\s+(\S+)/
+ fields = [:version, :revision]
+ hash_from_line(line, regex, fields)
+ end
+
+ def self.hash_from_line(line, regex, fields)
+ hash = {}
+ if match = regex.match(line)
+ fields.zip(match.captures) { |field, value|
+ hash[field] = value
+ }
+ hash[:provider] = self.name
+ return hash
+ end
+ nil
+ end
+
+ def self.instances
+ packages = []
+ port("-q", :installed).each do |line|
+ if hash = parse_installed_query_line(line)
+ packages << new(hash)
+ end
+ end
+ packages
+ end
+
+ def install
+ should = @resource.should(:ensure)
+ if [:latest, :installed, :present].include?(should)
+ output = port("-q", :install, @resource[:name])
+ else
+ output = port("-q", :install, @resource[:name], "@#{should}")
+ end
+ # MacPorts now correctly exits non-zero with appropriate errors in
+ # situations where a port cannot be found or installed.
+ end
+
+ def query
+ return self.class.parse_installed_query_line(port("-q", :installed, @resource[:name]))
+ end
+
+ def latest
+ # We need both the version and the revision to be confident
+ # we've got the latest revision of a specific version
+ # Note we're still not doing anything with variants here.
+ info_line = port("-q", :info, "--line", "--version", "--revision", @resource[:name])
+ return nil if info_line == ""
+
+ if newest = self.class.parse_info_query_line(info_line)
+ current = query
+ # We're doing some fiddling behind the scenes here to cope with updated revisions.
+ # If we're already at the latest version/revision, then just return the version
+ # so the current and desired values match. Otherwise return version and revision
+ # to trigger an upgrade to the latest revision.
+ if newest[:version] == current[:ensure] and newest[:revision] == current[:revision]
+ return current[:ensure]
+ else
+ return "#{newest[:version]}_#{newest[:revision]}"
+ end
+ end
+ nil
+ end
+
+ def uninstall
+ port("-q", :uninstall, @resource[:name])
+ end
+
+ def update
+ if query[:name] == @resource[:name] # 'port upgrade' cannot install new ports
+ port("-q", :upgrade, @resource[:name])
+ else
+ install
+ end
+ end
+end
+
diff --git a/lib/puppet/provider/package/pkgdmg.rb b/lib/puppet/provider/package/pkgdmg.rb
index 39e377d66..662d05c8f 100644
--- a/lib/puppet/provider/package/pkgdmg.rb
+++ b/lib/puppet/provider/package/pkgdmg.rb
@@ -1,21 +1,4 @@
#
-# pkgdmg.rb
-#
-# Install Installer.app packages wrapped up inside a DMG image file.
-#
-# Copyright (C) 2007 Jeff McCune Jeff McCune <jeff@northstarlabs.net>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation (version 2 of the License)
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
-#
# Motivation: DMG files provide a true HFS file system
# and are easier to manage and .pkg bundles.
#
diff --git a/lib/puppet/provider/user/directoryservice.rb b/lib/puppet/provider/user/directoryservice.rb
index 4b62a6ae7..a2c561039 100644
--- a/lib/puppet/provider/user/directoryservice.rb
+++ b/lib/puppet/provider/user/directoryservice.rb
@@ -1,17 +1,3 @@
-# Created by Jeff McCune on 2007-07-22
-# Copyright (c) 2007. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation (version 2 of the License)
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
-
require 'puppet/provider/nameservice/directoryservice'
Puppet::Type.type(:user).provide :directoryservice, :parent => Puppet::Provider::NameService::DirectoryService do
diff --git a/lib/puppet/provider/vlan/cisco.rb b/lib/puppet/provider/vlan/cisco.rb
new file mode 100644
index 000000000..46e172c73
--- /dev/null
+++ b/lib/puppet/provider/vlan/cisco.rb
@@ -0,0 +1,34 @@
+require 'puppet/util/network_device/cisco/device'
+require 'puppet/provider/network_device'
+
+Puppet::Type.type(:vlan).provide :cisco, :parent => Puppet::Provider::NetworkDevice do
+
+ desc "Cisco switch/router provider for vlans."
+
+ mk_resource_methods
+
+ def self.lookup(url, id)
+ vlans = {}
+ device = Puppet::Util::NetworkDevice::Cisco::Device.new(url)
+ device.command do |d|
+ vlans = d.parse_vlans || {}
+ end
+ vlans[id]
+ end
+
+ def initialize(*args)
+ super
+ end
+
+ # Clear out the cached values.
+ def flush
+ device.command do |device|
+ device.update_vlan(resource[:name], former_properties, properties)
+ end
+ super
+ end
+
+ def device
+ @device ||= Puppet::Util::NetworkDevice::Cisco::Device.new(resource[:device_url])
+ end
+end