Class: RunlistMap
- Inherits:
-
Object
- Object
- RunlistMap
- Defined in:
- lib/mofa/runlist_map.rb
Instance Attribute Summary collapse
-
#cookbook ⇒ Object
Returns the value of attribute cookbook.
-
#default_runlist_recipes ⇒ Object
Returns the value of attribute default_runlist_recipes.
-
#hostlist ⇒ Object
Returns the value of attribute hostlist.
-
#mp ⇒ Object
Returns the value of attribute mp.
-
#option_runlist ⇒ Object
Returns the value of attribute option_runlist.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
- #guess_runlists_by_hostnames ⇒ Object
-
#initialize ⇒ RunlistMap
constructor
A new instance of RunlistMap.
- #set_default_runlist_for_every_host ⇒ Object
Constructor Details
#initialize ⇒ RunlistMap
18 19 20 |
# File 'lib/mofa/runlist_map.rb', line 18 def initialize @mp = {} end |
Instance Attribute Details
#cookbook ⇒ Object
Returns the value of attribute cookbook.
3 4 5 |
# File 'lib/mofa/runlist_map.rb', line 3 def cookbook @cookbook end |
#default_runlist_recipes ⇒ Object
Returns the value of attribute default_runlist_recipes.
7 8 9 |
# File 'lib/mofa/runlist_map.rb', line 7 def default_runlist_recipes @default_runlist_recipes end |
#hostlist ⇒ Object
Returns the value of attribute hostlist.
4 5 6 |
# File 'lib/mofa/runlist_map.rb', line 4 def hostlist @hostlist end |
#mp ⇒ Object
Returns the value of attribute mp.
2 3 4 |
# File 'lib/mofa/runlist_map.rb', line 2 def mp @mp end |
#option_runlist ⇒ Object
Returns the value of attribute option_runlist.
6 7 8 |
# File 'lib/mofa/runlist_map.rb', line 6 def option_runlist @option_runlist end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/mofa/runlist_map.rb', line 5 def token @token end |
Class Method Details
.create(cookbook, hostlist, token, option_runlist = nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/mofa/runlist_map.rb', line 9 def self.create(cookbook, hostlist, token, option_runlist = nil) rl = RunlistMap.new rl.cookbook = cookbook rl.hostlist = hostlist rl.token = token rl.default_runlist_recipes = (!option_runlist.nil?) ? option_runlist : nil rl end |
Instance Method Details
#generate ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mofa/runlist_map.rb', line 22 def generate @default_runlist_recipes ||= [ "#{cookbook.name}::default" ] case cookbook.type when 'env' guess_runlists_by_hostnames else set_default_runlist_for_every_host end end |
#guess_runlists_by_hostnames ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mofa/runlist_map.rb', line 33 def guess_runlists_by_hostnames # recipes/jkmaster.rb --> runlist[<env_cookbook_name>::jkmaster] for all hosts with shortname jkmaster # recipes/jkslave.rb --> runlist[<env_cookbook_name>::jkslave] for all hosts with shortname jkslave[0-9] # and so on hostlist.list.each do |hostname| cookbook.recipes.each do |recipe| recipe_regex = "^#{recipe}[0-9]*\." if hostname.match(recipe_regex) @mp.store(hostname, "recipe[#{cookbook.name}::#{recipe}]") end end end end |
#set_default_runlist_for_every_host ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/mofa/runlist_map.rb', line 48 def set_default_runlist_for_every_host hostlist.list.each do |hostname| puts "Default Runlist Recipes: #{@default_runlist_recipes}" @default_runlist_recipes.each do |rl_entry| next unless rl_entry.split(/::/)[0] == cookbook.name @mp.store(hostname, @default_runlist) if cookbook.recipes.include?(rl_entry.split(/::/)[1]) end end end |