Class: R10K::Environment::Base
- Inherits:
-
Object
- Object
- R10K::Environment::Base
show all
- Includes:
- Logging
- Defined in:
- lib/r10k/environment/base.rb
Overview
This class defines a common interface for environment implementations.
Constant Summary
Constants included
from Logging
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(name, basedir, dirname, options = {}) ⇒ Base
Initialize the given environment.
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/r10k/environment/base.rb', line 51
def initialize(name, basedir, dirname, options = {})
@name = name
@basedir = basedir
@dirname = dirname
@options = options
@puppetfile_name = options.delete(:puppetfile_name)
@overrides = options.delete(:overrides) || {}
@full_path = File.join(@basedir, @dirname)
@path = Pathname.new(File.join(@basedir, @dirname))
@puppetfile = R10K::Puppetfile.new(@full_path,
{overrides: @overrides,
force: @overrides.dig(:modules, :force),
puppetfile_name: @puppetfile_name})
@puppetfile.environment = self
loader_options = { basedir: @full_path, overrides: @overrides, environment: self }
loader_options[:puppetfile] = @puppetfile_name if @puppetfile_name
@loader = R10K::ModuleLoader::Puppetfile.new(**loader_options)
if @overrides.dig(:environments, :incremental)
@loader.load_metadata
end
@base_modules = nil
@purge_exclusions = nil
@managed_directories = [ @full_path ]
@desired_contents = []
end
|
Instance Attribute Details
#basedir ⇒ Object
20
21
22
|
# File 'lib/r10k/environment/base.rb', line 20
def basedir
@basedir
end
|
#desired_contents ⇒ Object
40
41
42
|
# File 'lib/r10k/environment/base.rb', line 40
def desired_contents
@desired_contents
end
|
#dirname ⇒ Object
24
25
26
|
# File 'lib/r10k/environment/base.rb', line 24
def dirname
@dirname
end
|
#loader ⇒ Object
42
43
44
|
# File 'lib/r10k/environment/base.rb', line 42
def loader
@loader
end
|
#managed_directories ⇒ Object
40
41
42
|
# File 'lib/r10k/environment/base.rb', line 40
def managed_directories
@managed_directories
end
|
#name ⇒ Object
16
17
18
|
# File 'lib/r10k/environment/base.rb', line 16
def name
@name
end
|
#path ⇒ Object
28
29
30
|
# File 'lib/r10k/environment/base.rb', line 28
def path
@path
end
|
#puppetfile ⇒ Object
33
34
35
|
# File 'lib/r10k/environment/base.rb', line 33
def puppetfile
@puppetfile
end
|
#puppetfile_name ⇒ Object
38
39
40
|
# File 'lib/r10k/environment/base.rb', line 38
def puppetfile_name
@puppetfile_name
end
|
Instance Method Details
#accept(visitor) ⇒ Object
144
145
146
147
148
|
# File 'lib/r10k/environment/base.rb', line 144
def accept(visitor)
visitor.visit(:environment, self) do
puppetfile.accept(visitor)
end
end
|
#deploy ⇒ Object
Returns a Queue of the names of modules actually updated
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/r10k/environment/base.rb', line 152
def deploy
if @base_modules.nil?
load_puppetfile_modules
end
if ! @base_modules.empty?
pool_size = @overrides.dig(:modules, :pool_size)
updated_modules = R10K::ContentSynchronizer.concurrent_sync(@base_modules, pool_size, logger)
end
if (@overrides.dig(:purging, :purge_levels) || []).include?(:puppetfile)
logger.debug("Purging unmanaged Puppetfile content for environment '#{dirname}'...")
@puppetfile_cleaner.purge!
end
updated_modules
end
|
#determine_purge_exclusions(pf_managed_dirs = @puppetfile.managed_directories, pf_desired_contents = @puppetfile.desired_contents) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/r10k/environment/base.rb', line 186
def determine_purge_exclusions(pf_managed_dirs = @puppetfile.managed_directories,
pf_desired_contents = @puppetfile.desired_contents)
list = [File.join(@full_path, '.r10k-deploy.json')].to_set
list += pf_managed_dirs
list += pf_desired_contents.flat_map do |item|
desired_tree = []
if File.directory?(item)
desired_tree << File.join(item, '**', '*')
end
Pathname.new(item).ascend do |path|
break if path.to_s == @full_path
desired_tree << path.to_s
end
desired_tree
end
list.to_a
end
|
#generate_types! ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/r10k/environment/base.rb', line 219
def generate_types!
argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir, '--config', R10K::Settings.puppet_conf]
subproc = R10K::Util::Subprocess.new(argv)
subproc.raise_on_fail = true
subproc.logger = logger
result = subproc.execute
unless result.stderr.empty?
logger.warn "There were problems generating types for environment #{dirname}:"
result.stderr.split(%r{\n}).map { |msg| logger.warn msg }
end
end
|
#info ⇒ Hash
Returns a hash describing the current state of the environment.
120
121
122
123
124
125
|
# File 'lib/r10k/environment/base.rb', line 120
def info
{
:name => self.name,
:signature => self.signature,
}
end
|
#load_puppetfile_modules ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/r10k/environment/base.rb', line 170
def load_puppetfile_modules
loaded_content = @loader.load
@base_modules = loaded_content[:modules]
@purge_exclusions = determine_purge_exclusions(loaded_content[:managed_directories],
loaded_content[:desired_contents])
@puppetfile_cleaner = R10K::Util::Cleaner.new(loaded_content[:managed_directories],
loaded_content[:desired_contents],
loaded_content[:purge_exclusions])
end
|
Returns Whether or not the given module conflicts with any modules already defined in the r10k environment object.
140
141
142
|
# File 'lib/r10k/environment/base.rb', line 140
def module_conflicts?(mod)
false
end
|
Returns All modules defined in the Puppetfile associated with this environment.
129
130
131
132
133
134
135
|
# File 'lib/r10k/environment/base.rb', line 129
def modules
if @base_modules.nil?
load_puppetfile_modules
end
@base_modules
end
|
#purge_exclusions ⇒ Object
211
212
213
214
215
216
217
|
# File 'lib/r10k/environment/base.rb', line 211
def purge_exclusions
if @purge_exclusions.nil?
load_puppetfile_modules
end
@purge_exclusions
end
|
#signature ⇒ String
Returns a unique identifier for the environment’s current state.
113
114
115
|
# File 'lib/r10k/environment/base.rb', line 113
def signature
raise NotImplementedError, _("%{class} has not implemented method %{method}") %{class: self.class, method: __method__}
end
|
#status ⇒ Symbol
Determine the current status of the environment.
This can return the following values:
* :absent - there is no module installed
* :mismatched - there is a module installed but it must be removed and reinstalled
* :outdated - the correct module is installed but it needs to be updated
* :insync - the correct module is installed and up to date, or the module is actually a boy band.
104
105
106
|
# File 'lib/r10k/environment/base.rb', line 104
def status
raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
end
|
#sync ⇒ void
This method returns an undefined value.
Synchronize the given environment.
88
89
90
|
# File 'lib/r10k/environment/base.rb', line 88
def sync
raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
end
|
#whitelist(user_whitelist = []) ⇒ Object
182
183
184
|
# File 'lib/r10k/environment/base.rb', line 182
def whitelist(user_whitelist=[])
user_whitelist.collect { |pattern| File.join(@full_path, pattern) }
end
|