Class: CORL::Provisioner::Puppetnode
- Inherits:
-
Object
- Object
- CORL::Provisioner::Puppetnode
- Defined in:
- lib/CORL/provisioner/puppetnode.rb
Constant Summary collapse
- @@puppet_lock =
Mutex.new
- @@status =
{}
Class Method Summary collapse
Instance Method Summary collapse
-
#add_search_path(type, resource_name) ⇒ Object
—.
-
#build(options = {}) ⇒ Object
—————————————————————————– Provisioner interface operations.
-
#compiler ⇒ Object
—————————————————————————– Property accessor / modifiers.
-
#concatenate(components, capitalize = false) ⇒ Object
—.
-
#import(files, options = {}) ⇒ Object
–.
-
#lookup(property, default = nil, options = {}) ⇒ Object
—.
-
#normalize(reload) ⇒ Object
—————————————————————————– Provisioner plugin interface.
-
#profile_id(package_name, profile_name) ⇒ Object
—————————————————————————– Utilities.
-
#provision(profiles, options = {}) ⇒ Object
—.
-
#register(options = {}) ⇒ Object
—.
-
#scope ⇒ Object
—.
Class Method Details
.status ⇒ Object
11 12 13 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 11 def self.status @@status end |
Instance Method Details
#add_search_path(type, resource_name) ⇒ Object
207 208 209 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 207 def add_search_path(type, resource_name) Config.([ :all, type ], { :search => [ resource_name.to_s ] }) end |
#build(options = {}) ⇒ Object
Provisioner interface operations
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 128 def build( = {}) super do |locations, package_info| success = true # Build modules locations[:module] = {} init_profile = lambda do |package_name, profile_name, profile_info| package_id = id(package_name) base_directory = File.join(locations[:build], 'modules', package_id.to_s, profile_name.to_s) profile_success = true ui.info("Building CORL profile #{blue(profile_name)} modules into #{green(base_directory)}") if profile_info.has_key?(:modules) profile_info[:modules].each do |module_name, module_reference| module_directory = File.join(base_directory, module_name.to_s) ui.info("Building Puppet module #{blue(module_name)} at #{purple(module_reference)} into #{green(module_directory)}") full_module_directory = File.join(build_directory, module_directory) module_project = CORL.project(extended_config(:puppet_module, { :directory => full_module_directory, :url => module_reference, :create => File.directory?(full_module_directory) ? false : true, :pull => true })) unless module_project ui.warn("Puppet module #{cyan(module_name)} failed to initialize") profile_success = false break end end locations[:module][profile_id(package_name, profile_name)] = base_directory if profile_success profile_success end end hash(package_info.get([ :provisioners, plugin_provider ])).each do |package_name, info| if info.has_key?(:profiles) info[:profiles].each do |profile_name, profile_info| unless init_profile.call(package_name, profile_name, profile_info) success = false break end end end end profiles.each do |profile_name, profile_info| unless init_profile.call(plugin_name, profile_name, profile_info) success = false break end end success end end |
#compiler ⇒ Object
Property accessor / modifiers
62 63 64 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 62 def compiler @compiler end |
#concatenate(components, capitalize = false) ⇒ Object
319 320 321 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 319 def concatenate(components, capitalize = false) super(components, capitalize, '::') end |
#import(files, options = {}) ⇒ Object
–
198 199 200 201 202 203 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 198 def import(files, = {}) Util::Puppet.import(files, Config.ensure().defaults({ :puppet_scope => scope, :puppet_import_base => network.directory })) end |
#lookup(property, default = nil, options = {}) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 189 def lookup(property, default = nil, = {}) Util::Puppet.lookup(property, default, Config.ensure().defaults({ :provisioner => :puppetnode, :puppet_scope => scope })) end |
#normalize(reload) ⇒ Object
Provisioner plugin interface
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 18 def normalize(reload) super do if CORL.log_level == :debug Puppet.debug = true end unless reload Puppet::Util::Log.newdesttype id do def handle(msg) levels = { :emerg => { :name => 'emergency', :send => :error }, :alert => { :name => 'alert', :send => :error }, :crit => { :name => 'critical', :send => :error }, :err => { :name => 'error', :send => :error }, :warning => { :name => 'warning', :send => :warn }, :notice => { :name => 'notice', :send => :success }, :info => { :name => 'info', :send => :info }, :debug => { :name => 'debug', :send => :info } } str = msg.respond_to?(:multiline) ? msg.multiline : msg.to_s str = msg.source == "Puppet" ? str : "#{CORL.blue(msg.source)}: #{str}" level = levels[msg.level] if [ :warn, :error ].include?(level[:send]) ::CORL::Provisioner::Puppetnode.status[name] = 111 end CORL.ui_group("puppetnode::#{name}(#{CORL.yellow(level[:name])})", :cyan) do |ui| ui.send(level[:send], str) end end end end end end |
#profile_id(package_name, profile_name) ⇒ Object
Utilities
313 314 315 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 313 def profile_id(package_name, profile_name) concatenate([ package_name, 'profile', profile_name ], false) end |
#provision(profiles, options = {}) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 213 def provision(profiles, = {}) super do |config| locations = build_locations success = true include_location = lambda do |type, parameters = {}, add_search_path = false| classes = {} locations[:package].each do |name, package_directory| type_gateway = File.join(build_directory, package_directory, "#{type}.pp") resource_name = concatenate([ name, type ]) add_search_path(type, resource_name) if add_search_path if File.exists?(type_gateway) import(type_gateway) classes[resource_name] = parameters end type_directory = File.join(build_directory, package_directory, type.to_s) Dir.glob(File.join(type_directory, '*.pp')).each do |file| resource_name = concatenate([ name, type, File.basename(file).gsub('.pp', '') ]) import(file) classes[resource_name] = parameters end end type_gateway = File.join(directory, "#{type}.pp") resource_name = concatenate([ plugin_name, type ]) add_search_path(type, resource_name) if add_search_path if File.exists?(type_gateway) import(type_gateway) classes[resource_name] = parameters end type_directory = File.join(directory, type.to_s) if File.directory?(type_directory) Dir.glob(File.join(type_directory, '*.pp')).each do |file| resource_name = concatenate([ plugin_name, type, File.basename(file).gsub('.pp', '') ]) import(file) classes[resource_name] = parameters end end classes end @@puppet_lock.synchronize do begin ui.info("Starting catalog generation") @@status[id] = code.success start_time = Time.now node = init_puppet(profiles) # Include defaults classes = include_location.call(:default, {}, true) # Import needed profiles include_location.call(:profiles, {}, false) profiles.each do |profile| classes[profile.to_s] = { :require => 'Anchor[profile_start]' } end # Compile catalog node.classes = classes compiler.compile # Start system configuration catalog = compiler.catalog.to_ral catalog.finalize catalog.retrieval_duration = Time.now - start_time unless config.get(:dry_run, false) ui.info("\n", { :prefix => false }) ui.info("Starting configuration run") configurer = Puppet::Configurer.new if ! configurer.run(:catalog => catalog, :pluginsync => false) success = false end end rescue Exception => error raise error Puppet.log_exception(error) end end success = false if @@status[id] != code.success success end end |
#register(options = {}) ⇒ Object
55 56 57 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 55 def register( = {}) Util::Puppet.register_plugins(Config.ensure().defaults({ :puppet_scope => scope })) end |
#scope ⇒ Object
68 69 70 71 |
# File 'lib/CORL/provisioner/puppetnode.rb', line 68 def scope return compiler.topscope if compiler nil end |