Class: Nucleon::Plugin::Provisioner
- Inherits:
-
Object
- Object
- Nucleon::Plugin::Provisioner
- Includes:
- Parallel
- Defined in:
- lib/core/plugin/provisioner.rb
Class Method Summary collapse
-
.build_info(type, data) ⇒ Object
—————————————————————————– Utilities.
-
.translate(data) ⇒ Object
—.
-
.translate_reference(reference) ⇒ Object
—.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
—.
-
#build_directory ⇒ Object
—.
-
#build_info(reset = false) ⇒ Object
—.
-
#build_locations(reset = false) ⇒ Object
—.
-
#build_profiles(reset = false) ⇒ Object
—.
-
#concatenate(components, capitalize = false, joiner = '::') ⇒ Object
—.
- #directory ⇒ Object
-
#directory=(directory) ⇒ Object
—.
- #gateway ⇒ Object
-
#gateway=(gateway) ⇒ Object
—.
-
#id(name = nil) ⇒ Object
—.
-
#initialized?(options = {}) ⇒ Boolean
—————————————————————————– Checks.
-
#lookup(property, default = nil, options = {}) ⇒ Object
—.
-
#normalize(reload) ⇒ Object
—————————————————————————– Provisioner plugin interface.
-
#packages ⇒ Object
—.
-
#profiles ⇒ Object
—.
-
#provision(profiles, options = {}) ⇒ Object
—.
-
#register(options = {}) ⇒ Object
—————————————————————————– Provisioner operations.
-
#supported_profiles(profile_names = nil) ⇒ Object
—.
-
#translate_reference(reference) ⇒ Object
—.
Class Method Details
.build_info(type, data) ⇒ Object
Utilities
228 229 230 231 |
# File 'lib/core/plugin/provisioner.rb', line 228 def self.build_info(type, data) data = data.split(/\s*,\s*/) if data.is_a?(String) super(type, data) end |
.translate(data) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/core/plugin/provisioner.rb', line 235 def self.translate(data) = super(data) case data when String = { :profiles => array(data) } when Hash = data end if .has_key?(:profiles) if matches = translate_reference([:profiles]) [:provider] = matches[:provider] [:profiles] = matches[:profiles] logger.debug("Translating provisioner options: #{options.inspect}") end end end |
.translate_reference(reference) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/core/plugin/provisioner.rb', line 258 def self.translate_reference(reference) # ex: puppetnode:::profile::something,profile::somethingelse if reference && reference.match(/^\s*([a-zA-Z0-9_-]+):::([^\s]+)\s*$/) provider = $1 profiles = $2 logger.debug("Translating provisioner reference: #{provider} #{profiles}") info = { :provider => provider, :profiles => profiles.split(/\s*,\s*/) } logger.debug("Project reference info: #{info.inspect}") return info end nil end |
Instance Method Details
#build(options = {}) ⇒ Object
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/core/plugin/provisioner.rb', line 138 def build( = {}) config = Config.ensure() success = true locations = Config.new({ :build => id.to_s, :package => {} }) package_info = Config.new init_package = lambda do |name, reference| package_directory = File.join(locations[:build], 'packages', id(name).to_s) package_success = true ui.info("Building package #{blue(name)} at #{purple(reference)} into #{green(package_directory)}") full_package_directory = File.join(build_directory, package_directory) project = CORL.configuration(extended_config(:package, { :directory => full_package_directory, :url => reference, :create => File.directory?(full_package_directory) ? false : true })) unless project ui.warn("Project #{cyan(name)} failed to initialize") package_success = false end if package_success package_info.import(project.export) locations[:package][name] = package_directory if project.get([ :provisioners, plugin_provider ], false) project.get_hash([ :provisioners, plugin_provider ]).each do |prov_name, info| if info.has_key?(:packages) info[:packages].each do |sub_name, sub_reference| unless init_package.call(sub_name, sub_reference) package_success = false break end end end end end end package_success end local_build_directory = File.join(build_directory, locations[:build]) FileUtils.mkdir_p(local_build_directory) # Build packages packages.each do |name, reference| unless init_package.call(name, reference) success = false break end end if success # Build provider specific components success = yield(locations, package_info) if block_given? if success # Save the updates in the local project cache set_cache_setting(:build_locations, locations.export) set_cache_setting(:build_info, package_info.get([ :provisioners, plugin_provider ])) set_cache_setting(:build_profiles, find_profiles) end end success end |
#build_directory ⇒ Object
46 47 48 |
# File 'lib/core/plugin/provisioner.rb', line 46 def build_directory File.join(network.build_directory, plugin_provider.to_s) end |
#build_info(reset = false) ⇒ Object
115 116 117 118 119 |
# File 'lib/core/plugin/provisioner.rb', line 115 def build_info(reset = false) info = cache_setting(:build_info, {}, :hash) build if reset || info.empty? symbol_map(cache_setting(:build_info, {}, :hash)) end |
#build_locations(reset = false) ⇒ Object
107 108 109 110 111 |
# File 'lib/core/plugin/provisioner.rb', line 107 def build_locations(reset = false) locations = cache_setting(:build_locations, {}, :hash) build if reset || locations.empty? symbol_map(cache_setting(:build_locations, {}, :hash)) end |
#build_profiles(reset = false) ⇒ Object
123 124 125 126 127 |
# File 'lib/core/plugin/provisioner.rb', line 123 def build_profiles(reset = false) profiles = cache_setting(:build_profiles, [], :array) build if reset || profiles.empty? cache_setting(:build_profiles, [], :array) end |
#concatenate(components, capitalize = false, joiner = '::') ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/core/plugin/provisioner.rb', line 285 def concatenate(components, capitalize = false, joiner = '::') if components.is_a?(Array) components = components.collect do |str| str.to_s.split('__') end.flatten else components = [ components.to_s.split('__') ].flatten end if capitalize name = components.collect {|str| str.capitalize }.join(joiner) else name = components.join(joiner) end name end |
#directory ⇒ Object
40 41 42 |
# File 'lib/core/plugin/provisioner.rb', line 40 def directory File.join(network.directory, myself[:directory]) end |
#directory=(directory) ⇒ Object
36 37 38 |
# File 'lib/core/plugin/provisioner.rb', line 36 def directory=directory myself[:directory] = directory end |
#gateway ⇒ Object
56 57 58 |
# File 'lib/core/plugin/provisioner.rb', line 56 def gateway myself[:gateway] end |
#gateway=(gateway) ⇒ Object
52 53 54 |
# File 'lib/core/plugin/provisioner.rb', line 52 def gateway=gateway myself[:gateway] = gateway end |
#id(name = nil) ⇒ Object
29 30 31 32 |
# File 'lib/core/plugin/provisioner.rb', line 29 def id(name = nil) name = plugin_name if name.nil? name.to_s.gsub('::', '_').to_sym end |
#initialized?(options = {}) ⇒ Boolean
Checks
19 20 |
# File 'lib/core/plugin/provisioner.rb', line 19 def initialized?( = {}) end |
#lookup(property, default = nil, options = {}) ⇒ Object
210 211 212 213 |
# File 'lib/core/plugin/provisioner.rb', line 210 def lookup(property, default = nil, = {}) # Implement in providers nil end |
#normalize(reload) ⇒ Object
Provisioner plugin interface
11 12 13 14 |
# File 'lib/core/plugin/provisioner.rb', line 11 def normalize(reload) super yield if block_given? end |
#packages ⇒ Object
62 63 64 |
# File 'lib/core/plugin/provisioner.rb', line 62 def packages hash(myself[:packages]) end |
#profiles ⇒ Object
68 69 70 |
# File 'lib/core/plugin/provisioner.rb', line 68 def profiles hash(myself[:profiles]) end |
#provision(profiles, options = {}) ⇒ Object
217 218 219 220 221 222 223 |
# File 'lib/core/plugin/provisioner.rb', line 217 def provision(profiles, = {}) config = Config.ensure() success = yield(config) if block_given? Config.save_properties(Config.(:corl_log)) if success success end |
#register(options = {}) ⇒ Object
Provisioner operations
132 133 134 |
# File 'lib/core/plugin/provisioner.rb', line 132 def register( = {}) # Implement in providers end |
#supported_profiles(profile_names = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/core/plugin/provisioner.rb', line 88 def supported_profiles(profile_names = nil) found = [] profiles = build_profiles if profile_names.nil? found = profiles else profile_names.each do |name| name = name.to_s if profiles.include?(name) found << name end end end found.empty? ? false : found end |
#translate_reference(reference) ⇒ Object
279 280 281 |
# File 'lib/core/plugin/provisioner.rb', line 279 def translate_reference(reference) myself.class.translate_reference(reference) end |