Class: Ridley::BootstrapContext::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ridley/bootstrap_context.rb

Direct Known Subclasses

Unix, Windows

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ridley/bootstrap_context.rb', line 31

def initialize(options = {})
  options = options.reverse_merge(
    validator_client: "chef-validator",
    attributes: Hash.new,
    run_list: Array.new,
    environment: "_default",
    sudo: true,
    hints: Hash.new,
    chef_version: "latest"
  )
  options[:template] ||= default_template
  self.class.validate_options(options)

  @template_file             = options[:template]
  @bootstrap_proxy           = options[:bootstrap_proxy]
  @chef_version              = options[:chef_version]
  @sudo                      = options[:sudo]
  @validator_path            = options[:validator_path]
  @encrypted_data_bag_secret = options[:encrypted_data_bag_secret]
  @hints                     = options[:hints]
  @server_url                = options[:server_url]
  @validator_client          = options[:validator_client]
  @node_name                 = options[:node_name]
  @attributes                = options[:attributes]
  @run_list                  = options[:run_list]
  @environment               = options[:environment]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



26
27
28
# File 'lib/ridley/bootstrap_context.rb', line 26

def attributes
  @attributes
end

#bootstrap_proxyObject (readonly)

Returns the value of attribute bootstrap_proxy.



19
20
21
# File 'lib/ridley/bootstrap_context.rb', line 19

def bootstrap_proxy
  @bootstrap_proxy
end

#chef_versionObject (readonly)

Returns the value of attribute chef_version.



20
21
22
# File 'lib/ridley/bootstrap_context.rb', line 20

def chef_version
  @chef_version
end

#encrypted_data_bag_secretObject (readonly)

Returns the value of attribute encrypted_data_bag_secret.



22
23
24
# File 'lib/ridley/bootstrap_context.rb', line 22

def encrypted_data_bag_secret
  @encrypted_data_bag_secret
end

#environmentObject (readonly)

Returns the value of attribute environment.



28
29
30
# File 'lib/ridley/bootstrap_context.rb', line 28

def environment
  @environment
end

#hintsObject (readonly)

Returns the value of attribute hints.



29
30
31
# File 'lib/ridley/bootstrap_context.rb', line 29

def hints
  @hints
end

#node_nameObject (readonly)

Returns the value of attribute node_name.



25
26
27
# File 'lib/ridley/bootstrap_context.rb', line 25

def node_name
  @node_name
end

#run_listObject (readonly)

Returns the value of attribute run_list.



27
28
29
# File 'lib/ridley/bootstrap_context.rb', line 27

def run_list
  @run_list
end

#server_urlObject (readonly)

Returns the value of attribute server_url.



23
24
25
# File 'lib/ridley/bootstrap_context.rb', line 23

def server_url
  @server_url
end

#template_fileObject (readonly)

Returns the value of attribute template_file.



18
19
20
# File 'lib/ridley/bootstrap_context.rb', line 18

def template_file
  @template_file
end

#validator_clientObject (readonly)

Returns the value of attribute validator_client.



24
25
26
# File 'lib/ridley/bootstrap_context.rb', line 24

def validator_client
  @validator_client
end

#validator_pathObject (readonly)

Returns the value of attribute validator_path.



21
22
23
# File 'lib/ridley/bootstrap_context.rb', line 21

def validator_path
  @validator_path
end

Class Method Details

.validate_options(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/ridley/bootstrap_context.rb', line 7

def validate_options(options = {})
  if options[:server_url].nil?
    raise Errors::ArgumentError, "A server_url is required for bootstrapping"
  end

  if options[:validator_path].nil?
    raise Errors::ArgumentError, "A path to a validator is required for bootstrapping"
  end
end

Instance Method Details

#bootstrap_commandString

Returns:

  • (String)

Raises:

  • (RuntimeError)


60
61
62
# File 'lib/ridley/bootstrap_context.rb', line 60

def bootstrap_command
  raise RuntimeError, "abstract function: must be implemented on includer"
end

#default_templateString

Returns:

  • (String)

Raises:

  • (RuntimeError)


65
66
67
# File 'lib/ridley/bootstrap_context.rb', line 65

def default_template
  raise RuntimeError, "abstract function: must be implemented on includer"
end

#first_bootString

Returns:

  • (String)


75
76
77
# File 'lib/ridley/bootstrap_context.rb', line 75

def first_boot
  JSON.fast_generate(attributes.merge(run_list: run_list))
end

#templateErubis::Eruby

Returns:

  • (Erubis::Eruby)


91
92
93
# File 'lib/ridley/bootstrap_context.rb', line 91

def template
  Erubis::Eruby.new(IO.read(template_file).chomp)
end

#templates_pathPathname

Returns:

  • (Pathname)


70
71
72
# File 'lib/ridley/bootstrap_context.rb', line 70

def templates_path
  Ridley.root.join('bootstrappers')
end

#validation_keyString

The validation key to create a new client for the node

Returns:

  • (String)

Raises:



84
85
86
87
88
# File 'lib/ridley/bootstrap_context.rb', line 84

def validation_key
  IO.read(File.expand_path(validator_path)).chomp
rescue Errno::ENOENT
  raise Errors::ValidatorNotFound, "Error bootstrapping: Validator not found at '#{validator_path}'"
end