Class: Chake::ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/chake/config_manager.rb,
lib/chake/config_manager/chef.rb,
lib/chake/config_manager/shell.rb,
lib/chake/config_manager/itamae.rb

Direct Known Subclasses

Chef, Itamae, Shell

Defined Under Namespace

Classes: Chef, Itamae, Shell

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ ConfigManager

Returns a new instance of ConfigManager.



7
8
9
# File 'lib/chake/config_manager.rb', line 7

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/chake/config_manager.rb', line 5

def node
  @node
end

Class Method Details

.accept?(_node) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/chake/config_manager.rb', line 60

def self.accept?(_node)
  false
end

.allObject



64
65
66
# File 'lib/chake/config_manager.rb', line 64

def self.all
  @subclasses
end

.get(node) ⇒ Object

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
# File 'lib/chake/config_manager.rb', line 51

def self.get(node)
  available = @subclasses.sort_by(&:priority)
  manager = available.find { |c| c.short_name == node.data['config_manager'] }
  manager ||= available.find { |c| c.accept?(node) }
  raise ArgumentError, "Can't find configuration manager class for node #{node.hostname}. Available: #{available}.join(', ')}" unless manager

  manager.new(node)
end

.inherited(klass) ⇒ Object



45
46
47
48
49
# File 'lib/chake/config_manager.rb', line 45

def self.inherited(klass)
  super
  @subclasses ||= []
  @subclasses << klass
end

.initObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chake/config_manager.rb', line 68

def self.init
  skel = Pathname(__FILE__).parent / 'config_manager' / 'skel' / short_name
  skel.glob('**/*').each do |source|
    target = source.relative_path_from(skel)
    if target.exist?
      puts "exists: #{target}"
    else
      if source.directory?
        FileUtils.mkdir_p target
      else
        FileUtils.cp source, target
      end
      puts "create: #{target}"
    end
  end
end

.priority(new_prioriry = nil) ⇒ Object



41
42
43
# File 'lib/chake/config_manager.rb', line 41

def self.priority(new_prioriry = nil)
  @priority ||= new_prioriry || 50
end

.short_nameObject



37
38
39
# File 'lib/chake/config_manager.rb', line 37

def self.short_name
  name.split('::').last.downcase
end

Instance Method Details

#apply(config) ⇒ Object



13
# File 'lib/chake/config_manager.rb', line 13

def apply(config); end

#bootstrap_stepsObject



27
28
29
30
31
# File 'lib/chake/config_manager.rb', line 27

def bootstrap_steps
  base = File.join(File.absolute_path(File.dirname(__FILE__)), 'bootstrap')
  steps = Dir[File.join(base, '*.sh')] + Dir[File.join(base, name, '*.sh')]
  steps.sort_by { |f| File.basename(f) }
end

#convergeObject



11
# File 'lib/chake/config_manager.rb', line 11

def converge; end

#nameObject



19
20
21
# File 'lib/chake/config_manager.rb', line 19

def name
  self.class.short_name
end

#needs_upload?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/chake/config_manager.rb', line 33

def needs_upload?
  true
end

#pathObject



15
16
17
# File 'lib/chake/config_manager.rb', line 15

def path
  "/var/tmp/#{name}.#{node.username}"
end

#to_sObject



23
24
25
# File 'lib/chake/config_manager.rb', line 23

def to_s
  name
end