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
#clear_deprecation_warnings, #deprecation_warning, #send_log
Constructor Details
#initialize(name, environment = nil) ⇒ Module
Returns a new instance of Module.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/module.rb', line 51 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
98 99 100 |
# File 'lib/puppet/module.rb', line 98 def exist? ! path.nil? end |
#file_directory ⇒ Object
Find the first ‘files’ directory. This is used by the XMLRPC fileserver.
103 104 105 |
# File 'lib/puppet/module.rb', line 103 def file_directory subpath("files") end |
#has_metadata? ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/puppet/module.rb', line 42 def return false unless return false unless FileTest.exist?() = PSON.parse File.read() return .is_a?(Hash) && !.keys.empty? end |
#license_file ⇒ Object
107 108 109 110 111 112 |
# File 'lib/puppet/module.rb', line 107 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
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/puppet/module.rb', line 114 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.
128 129 130 131 132 133 |
# File 'lib/puppet/module.rb', line 128 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
135 136 137 138 139 140 |
# File 'lib/puppet/module.rb', line 135 def return if defined?() return = nil unless path = File.join(path, "metadata.json") end |
#path ⇒ Object
Find this module in the modulepath.
143 144 145 |
# File 'lib/puppet/module.rb', line 143 def path environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.directory?(d) } end |
#plugin_directory ⇒ Object
Find all plugin directories. This is used by the Plugins fileserving mount.
148 149 150 |
# File 'lib/puppet/module.rb', line 148 def plugin_directory subpath("plugins") end |
#requires(name, version = nil) ⇒ Object
152 153 154 155 |
# File 'lib/puppet/module.rb', line 152 def requires(name, version = nil) @requires ||= [] @requires << [name, version] end |
#supports(name, version = nil) ⇒ Object
157 158 159 160 |
# File 'lib/puppet/module.rb', line 157 def supports(name, version = nil) @supports ||= [] @supports << [name, version] end |
#to_s ⇒ Object
162 163 164 165 166 |
# File 'lib/puppet/module.rb', line 162 def to_s result = "Module #{name}" result += "(#{path})" if path result end |
#validate_dependencies ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/puppet/module.rb', line 168 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
182 183 184 185 |
# File 'lib/puppet/module.rb', line 182 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 |