Class: Puppet::Module
- Includes:
- Util::Logging
- Defined in:
- lib/puppet/module.rb
Overview
Support for modules
Defined Under Namespace
Classes: Error, IncompatibleModule, IncompatiblePlatform, InvalidName, MissingMetadata, MissingModule, UnsupportedPlatform
Constant Summary collapse
- TEMPLATES =
"templates"- FILES =
"files"- MANIFESTS =
"manifests"- PLUGINS =
"plugins"- FILETYPES =
[MANIFESTS, FILES, TEMPLATES, PLUGINS]
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#description ⇒ Object
Returns the value of attribute description.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#license ⇒ Object
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project_page ⇒ Object
Returns the value of attribute project_page.
-
#puppetversion ⇒ Object
Returns the value of attribute puppetversion.
-
#source ⇒ Object
Returns the value of attribute source.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.find(modname, environment = nil) ⇒ Object
Find and return the
modulethatpathbelongs to. -
.modulepath(environment = nil) ⇒ Object
Return an array of paths by splitting the
modulepathconfig parameter.
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#file_directory ⇒ Object
Find the first ‘files’ directory.
- #has_metadata? ⇒ Boolean
-
#initialize(name, environment = nil) ⇒ Module
constructor
A new instance of Module.
- #license_file ⇒ Object
- #load_metadata ⇒ Object
-
#match_manifests(rest) ⇒ Object
Return the list of manifests matching the given glob pattern, defaulting to ‘init.pp,rb’ for empty modules.
- #metadata_file ⇒ Object
-
#path ⇒ Object
Find this module in the modulepath.
-
#plugin_directory ⇒ Object
Find all plugin directories.
- #requires(name, version = nil) ⇒ Object
- #supports(name, version = nil) ⇒ Object
- #to_s ⇒ Object
- #validate_dependencies ⇒ Object
- #validate_puppet_version ⇒ Object
Methods included from Util::Logging
Constructor Details
#initialize(name, environment = nil) ⇒ Module
Returns a new instance of Module.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/module.rb', line 48 def initialize(name, environment = nil) @name = name assert_validity if environment.is_a?(Puppet::Node::Environment) @environment = environment else @environment = Puppet::Node::Environment.new(environment) end if validate_puppet_version validate_dependencies end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def end |
#description ⇒ Object
Returns the value of attribute description.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def description @description end |
#environment ⇒ Object
Returns the value of attribute environment.
37 38 39 |
# File 'lib/puppet/module.rb', line 37 def environment @environment end |
#license ⇒ Object
Returns the value of attribute license.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/puppet/module.rb', line 37 def name @name end |
#project_page ⇒ Object
Returns the value of attribute project_page.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def project_page @project_page end |
#puppetversion ⇒ Object
Returns the value of attribute puppetversion.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def puppetversion @puppetversion end |
#source ⇒ Object
Returns the value of attribute source.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def source @source end |
#summary ⇒ Object
Returns the value of attribute summary.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def summary @summary end |
#version ⇒ Object
Returns the value of attribute version.
40 41 42 |
# File 'lib/puppet/module.rb', line 40 def version @version end |
Class Method Details
.find(modname, environment = nil) ⇒ Object
Find and return the module that path belongs to. If path is absolute, or if there is no module whose name is the first component of path, return nil
32 33 34 35 |
# File 'lib/puppet/module.rb', line 32 def self.find(modname, environment = nil) return nil unless modname Puppet::Node::Environment.new(environment).module(modname) end |
.modulepath(environment = nil) ⇒ Object
Return an array of paths by splitting the modulepath config parameter. Only consider paths that are absolute and existing directories
25 26 27 |
# File 'lib/puppet/module.rb', line 25 def self.modulepath(environment = nil) Puppet::Node::Environment.new(environment).modulepath end |
Instance Method Details
#exist? ⇒ Boolean
95 96 97 |
# File 'lib/puppet/module.rb', line 95 def exist? ! path.nil? end |
#file_directory ⇒ Object
Find the first ‘files’ directory. This is used by the XMLRPC fileserver.
100 101 102 |
# File 'lib/puppet/module.rb', line 100 def file_directory subpath("files") end |
#has_metadata? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/puppet/module.rb', line 42 def return false unless FileTest.exist?() end |
#license_file ⇒ Object
104 105 106 107 108 109 |
# File 'lib/puppet/module.rb', line 104 def license_file return @license_file if defined?(@license_file) return @license_file = nil unless path @license_file = File.join(path, "License") end |
#load_metadata ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/puppet/module.rb', line 111 def data = PSON.parse File.read() [:source, :author, :version, :license, :puppetversion].each do |attr| unless value = data[attr.to_s] unless attr == :puppetversion raise MissingMetadata, "No #{attr} module metadata provided for #{self.name}" end end send(attr.to_s + "=", value) end end |
#match_manifests(rest) ⇒ Object
Return the list of manifests matching the given glob pattern, defaulting to ‘init.pp,rb’ for empty modules.
125 126 127 128 129 130 |
# File 'lib/puppet/module.rb', line 125 def match_manifests(rest) pat = File.join(path, MANIFESTS, rest || 'init') [manifest("init.pp"),manifest("init.rb")].compact + Dir. glob(pat + (File.extname(pat).empty? ? '.{pp,rb}' : '')). reject { |f| FileTest.directory?(f) } end |
#metadata_file ⇒ Object
132 133 134 135 136 137 |
# File 'lib/puppet/module.rb', line 132 def return if defined?() return = nil unless path = File.join(path, "metadata.json") end |
#path ⇒ Object
Find this module in the modulepath.
140 141 142 |
# File 'lib/puppet/module.rb', line 140 def path environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.exist?(d) } end |
#plugin_directory ⇒ Object
Find all plugin directories. This is used by the Plugins fileserving mount.
145 146 147 |
# File 'lib/puppet/module.rb', line 145 def plugin_directory subpath("plugins") end |
#requires(name, version = nil) ⇒ Object
149 150 151 152 |
# File 'lib/puppet/module.rb', line 149 def requires(name, version = nil) @requires ||= [] @requires << [name, version] end |
#supports(name, version = nil) ⇒ Object
154 155 156 157 |
# File 'lib/puppet/module.rb', line 154 def supports(name, version = nil) @supports ||= [] @supports << [name, version] end |
#to_s ⇒ Object
159 160 161 162 163 |
# File 'lib/puppet/module.rb', line 159 def to_s result = "Module #{name}" result += "(#{path})" if path result end |
#validate_dependencies ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/puppet/module.rb', line 165 def validate_dependencies return unless defined?(@requires) @requires.each do |name, version| unless mod = environment.module(name) raise MissingModule, "Missing module #{name} required by #{self.name}" end if version and mod.version != version raise IncompatibleModule, "Required module #{name} is version #{mod.version} but #{self.name} requires #{version}" end end end |
#validate_puppet_version ⇒ Object
179 180 181 182 |
# File 'lib/puppet/module.rb', line 179 def validate_puppet_version return unless puppetversion and puppetversion != Puppet.version raise IncompatibleModule, "Module #{self.name} is only compatible with Puppet version #{puppetversion}, not #{Puppet.version}" end |