Class: Formatron::ChefClients

Inherits:
Object
  • Object
show all
Defined in:
lib/formatron/chef_clients.rb

Overview

creates chef clients

Instance Method Summary collapse

Constructor Details

#initialize(aws:, bucket:, name:, target:, ec2_key:, hosted_zone_name:, vpc:, external:, configuration:, databag_secret:) ⇒ ChefClients

rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/formatron/chef_clients.rb', line 7

def initialize(
  aws:,
  bucket:,
  name:,
  target:,
  ec2_key:,
  hosted_zone_name:,
  vpc:,
  external:,
  configuration:,
  databag_secret:
)
  @chef_clients = {}
  if external.nil?
    bastions = Util::VPC.instances :bastion, vpc
    chef_servers = Util::VPC.instances :chef_server, vpc
  else
    bastions = Util::VPC.instances :bastion, external, vpc
    chef_servers = Util::VPC.instances :chef_server, external, vpc
  end
  bastions = Hash[bastions.map { |k, v| [k, v.sub_domain] }]
  chef_servers.each do |key, chef_server|
    @chef_clients[key] = Chef.new(
      aws: aws,
      bucket: bucket,
      name: name,
      target: target,
      username: chef_server.username,
      organization: chef_server.organization.short_name,
      ssl_verify: chef_server.ssl_verify,
      chef_sub_domain: chef_server.sub_domain,
      ec2_key: ec2_key,
      bastions: bastions,
      hosted_zone_name: hosted_zone_name,
      server_stack: chef_server.stack || name,
      guid: chef_server.guid,
      configuration: configuration,
      databag_secret: databag_secret
    )
  end
end

Instance Method Details

#get(key = nil) ⇒ Object

rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize rubocop:enable Metrics/ParameterLists



52
53
54
55
# File 'lib/formatron/chef_clients.rb', line 52

def get(key = nil)
  key ||= @chef_clients.keys[0]
  @chef_clients[key]
end

#initObject



57
58
59
# File 'lib/formatron/chef_clients.rb', line 57

def init
  @chef_clients.values.each(&:init)
end


61
62
63
# File 'lib/formatron/chef_clients.rb', line 61

def unlink
  @chef_clients.values.each(&:unlink)
end