Class: KnifeSous::Node

Inherits:
Object
  • Object
show all
Includes:
HashMixins
Defined in:
lib/knife_sous/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashMixins

normalize_hash, sanitize_key

Constructor Details

#initialize(name, config_args = {}) ⇒ Node

Returns a new instance of Node.



10
11
12
13
14
# File 'lib/knife_sous/node.rb', line 10

def initialize(name, config_args={})
  @name = name.to_s
  @config = {}
  update_config(config_args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



32
33
34
# File 'lib/knife_sous/node.rb', line 32

def method_missing(method_name, *args, &block)
  @config[method_name.to_sym]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/knife_sous/node.rb', line 8

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/knife_sous/node.rb', line 8

def name
  @name
end

Instance Method Details

#config_aliasesObject



36
37
38
39
40
41
# File 'lib/knife_sous/node.rb', line 36

def config_aliases
  {
    ssh_config_file: :ssh_config,
    ip: :hostname
  }
end

#convert_aliases(config_hash = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/knife_sous/node.rb', line 22

def convert_aliases(config_hash = {})
  config_aliases.each do |key, value|
    if config_hash.has_key?(key)
      config_hash[value] = config_hash[key]
      config_hash.delete(key)
    end
  end
  config_hash
end

#update_config(other_config = {}) ⇒ Object



16
17
18
19
20
# File 'lib/knife_sous/node.rb', line 16

def update_config(other_config={})
  config = convert_aliases(normalize_hash(other_config))
  @config[:chef_node_name] = @name
  @config.merge!(config)
end