Class: CORL::Plugin::Provisioner
- Inherits:
-
Object
- Object
- CORL::Plugin::Provisioner
- Extended by:
- Mixin::Builder::Global
- Includes:
- Mixin::Builder::Instance, Parallel
- Defined in:
- lib/core/plugin/provisioner.rb
Class Method Summary collapse
-
.build_info(namespace, plugin_type, data) ⇒ Object
—————————————————————————– Utilities.
-
.translate(data) ⇒ Object
—.
-
.translate_reference(reference) ⇒ Object
—.
Instance Method Summary collapse
-
#build(node, options = {}) ⇒ Object
—.
-
#build_dependencies(node, reset = false) ⇒ Object
—.
-
#build_directory ⇒ Object
—.
-
#build_info(node, reset = false) ⇒ Object
—.
-
#build_locations(node, reset = false) ⇒ Object
—.
- #build_profile(name, info, package, environment, profiles, options = {}) ⇒ Object
-
#build_profiles(node, reset = false) ⇒ Object
—.
-
#build_provider(package, info, environment, combined_info, options = {}) ⇒ Object
—.
- #directory ⇒ Object
-
#directory=(directory) ⇒ Object
—.
- #gateway(index = :first, reset = false) ⇒ Object
-
#gateway=(gateway) ⇒ Object
—.
-
#initialized?(options = {}) ⇒ Boolean
—————————————————————————– Checks.
-
#lookup(property, default = nil, options = {}) ⇒ Object
—.
-
#normalize(reload) ⇒ Object
—————————————————————————– Provisioner plugin interface.
- #package_gateways(node, reset = false) ⇒ Object
-
#profile_dependencies(node, profiles) ⇒ Object
—.
-
#profile_id(package, profile) ⇒ Object
—.
-
#provision(node, profiles, options = {}) ⇒ Object
—.
-
#register(options = {}) ⇒ Object
—————————————————————————– Provisioner operations.
-
#supported_profiles(node, profile_names = nil) ⇒ Object
—.
-
#translate_reference(reference) ⇒ Object
—.
Methods included from Mixin::Builder::Global
concatenate, id, id_joiner, process_environment, resource, resource_joiner
Methods included from Mixin::Builder::Instance
#build_config, #build_lock, #concatenate, #id, #id_joiner, #internal_path, #process_environment, #resource, #resource_joiner
Class Method Details
.build_info(namespace, plugin_type, data) ⇒ Object
Utilities
260 261 262 263 |
# File 'lib/core/plugin/provisioner.rb', line 260 def self.build_info(namespace, plugin_type, data) data = data.split(/\s*,\s*/) if data.is_a?(String) super(namespace, plugin_type, data) end |
.translate(data) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/core/plugin/provisioner.rb', line 267 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: #{.inspect}") end end end |
.translate_reference(reference) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/core/plugin/provisioner.rb', line 290 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(node, options = {}) ⇒ Object
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 207 208 |
# File 'lib/core/plugin/provisioner.rb', line 177 def build(node, = {}) config = Config.ensure() environment = Util::Data.ensure_value(config[:environment], node.lookup(:corl_environment)) provider_info = network.build.config.get_hash([ :provisioners, plugin_provider ]) combined_info = Config.new({}, {}, true, false) provider_info.each do |package, info| package_info = Config.new(info, {}, true, false) profiles = {} hash(package_info[:profiles]).each do |name, profile_info| profiles[profile_id(package, name)] = profile_info end package_info[:profiles] = profiles combined_info.import(package_info) end FileUtils.mkdir_p(build_directory) status = parallel(:build_provider, provider_info, environment, combined_info, config) success = status.values.include?(false) ? false : true if success # Save the updates in the local project cache set_cache_setting(:build_dependencies, network.build.dependencies.export) set_cache_setting(:build_locations, network.build.locations.export) set_cache_setting(:build_info, provider_info) set_cache_setting(:build_profiles, find_profiles(node)) end success end |
#build_dependencies(node, reset = false) ⇒ Object
138 139 140 141 142 |
# File 'lib/core/plugin/provisioner.rb', line 138 def build_dependencies(node, reset = false) dependencies = cache_setting(:build_dependencies, {}, :hash) build(node) if reset || dependencies.empty? symbol_map(cache_setting(:build_dependencies, {}, :hash)) end |
#build_directory ⇒ Object
43 44 45 |
# File 'lib/core/plugin/provisioner.rb', line 43 def build_directory File.join(network.build_directory, 'provisioners', plugin_provider.to_s) end |
#build_info(node, reset = false) ⇒ Object
154 155 156 157 158 |
# File 'lib/core/plugin/provisioner.rb', line 154 def build_info(node, reset = false) info = cache_setting(:build_info, {}, :hash) build(node) if reset || info.empty? symbol_map(cache_setting(:build_info, {}, :hash)) end |
#build_locations(node, reset = false) ⇒ Object
146 147 148 149 150 |
# File 'lib/core/plugin/provisioner.rb', line 146 def build_locations(node, reset = false) locations = cache_setting(:build_locations, {}, :hash) build(node) if reset || locations.empty? symbol_map(cache_setting(:build_locations, {}, :hash)) end |
#build_profile(name, info, package, environment, profiles, options = {}) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/core/plugin/provisioner.rb', line 218 def build_profile(name, info, package, environment, profiles, = {}) parents = [] config = Config.new(info, {}, true, false) success = true while config.has_key?(:extend) do array(config.delete(:extend)).each do |parent| parent = profile_id(package, parent) unless parent.match('::') parents << parent config.defaults(profiles[parent.to_sym]) end end build_config.set_dependency(:profile, profile_id(package, name), parents) success = yield(process_environment(info, environment), ) if block_given? success end |
#build_profiles(node, reset = false) ⇒ Object
162 163 164 165 166 |
# File 'lib/core/plugin/provisioner.rb', line 162 def build_profiles(node, reset = false) profiles = cache_setting(:build_profiles, [], :array) build(node) if reset || profiles.empty? cache_setting(:build_profiles, [], :array) end |
#build_provider(package, info, environment, combined_info, options = {}) ⇒ Object
212 213 214 215 216 |
# File 'lib/core/plugin/provisioner.rb', line 212 def build_provider(package, info, environment, combined_info, = {}) profiles = hash(info[:profiles]) status = parallel(:build_profile, profiles, id(package), environment, hash(combined_info[:profiles]), ) status.values.include?(false) ? false : true end |
#directory ⇒ Object
37 38 39 |
# File 'lib/core/plugin/provisioner.rb', line 37 def directory File.join(network.directory, myself[:directory]) end |
#directory=(directory) ⇒ Object
33 34 35 |
# File 'lib/core/plugin/provisioner.rb', line 33 def directory=directory myself[:directory] = directory end |
#gateway(index = :first, reset = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/core/plugin/provisioner.rb', line 53 def gateway(index = :first, reset = false) gateway = myself[:gateway] unless gateway gateways = package_gateways(reset) unless gateways.empty? if index == :first || index == 0 gateway = gateways[0] elsif index == :last gateway = gateways.pop elsif index.integer? gateway = gateways[index] end end end gateway end |
#gateway=(gateway) ⇒ Object
49 50 51 |
# File 'lib/core/plugin/provisioner.rb', line 49 def gateway=gateway myself[:gateway] = gateway end |
#initialized?(options = {}) ⇒ Boolean
Checks
23 24 |
# File 'lib/core/plugin/provisioner.rb', line 23 def initialized?( = {}) end |
#lookup(property, default = nil, options = {}) ⇒ Object
239 240 241 242 |
# File 'lib/core/plugin/provisioner.rb', line 239 def lookup(property, default = nil, = {}) # Implement in providers nil end |
#normalize(reload) ⇒ Object
Provisioner plugin interface
14 15 16 17 18 |
# File 'lib/core/plugin/provisioner.rb', line 14 def normalize(reload) super build_config.register(:dependency, :dependencies) if build_config yield if block_given? end |
#package_gateways(node, reset = false) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/core/plugin/provisioner.rb', line 72 def package_gateways(node, reset = false) gateways = [] build_info(node, reset).each do |package_name, package_info| gateways << File.join('packages', id(package_name).to_s, package_info[:gateway]) if package_info.has_key?(:gateway) end gateways end |
#profile_dependencies(node, profiles) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/core/plugin/provisioner.rb', line 114 def profile_dependencies(node, profiles) dependencies = build_dependencies(node)[:profile] profile_index = {} search_profiles = lambda do |profile| profile = profile.to_sym if dependencies.has_key?(profile) dependencies[profile].each do |parent_profile| search_profiles.call(parent_profile) end end profile_index[profile] = true end profiles.each do |profile| search_profiles.call(profile) end profile_index.keys end |
#profile_id(package, profile) ⇒ Object
317 318 319 |
# File 'lib/core/plugin/provisioner.rb', line 317 def profile_id(package, profile) concatenate([ package, 'profile', profile ], false) end |
#provision(node, profiles, options = {}) ⇒ Object
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/core/plugin/provisioner.rb', line 246 def provision(node, profiles, = {}) config = Config.ensure() profiles = profile_dependencies(node, profiles) success = true success = yield(profiles, config) if block_given? Config.save_properties(Config.(:corl_log)) success end |
#register(options = {}) ⇒ Object
Provisioner operations
171 172 173 |
# File 'lib/core/plugin/provisioner.rb', line 171 def register( = {}) # Implement in providers end |
#supported_profiles(node, profile_names = nil) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/core/plugin/provisioner.rb', line 95 def supported_profiles(node, profile_names = nil) found = [] profiles = build_profiles(node) 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
311 312 313 |
# File 'lib/core/plugin/provisioner.rb', line 311 def translate_reference(reference) self.class.translate_reference(reference) end |