This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
easybib.rb
101 lines (78 loc) · 2.53 KB
/
easybib.rb
1
2
3
4
5
6
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module EasyBib
def has_role?(instance_roles, role)
return true if role.nil?
return true if instance_roles.include?(role)
false
end
def has_env?(app, node = self.node)
return false unless node.attribute?(app)
return true if node[app]['env']
false
end
def get_cluster_name(node = self.node)
if node['opsworks'] && node['opsworks']['stack']
return node['opsworks']['stack']['name']
end
if node['easybib'] && node['easybib']['cluster_name']
return node['easybib']['cluster_name']
end
return 'vagrant' unless is_aws(node)
::Chef::Log.error('Unknown environment. (get_cluster_name) - returning unknown')
''
end
def get_normalized_cluster_name(node = self.node)
cluster_name = get_cluster_name(node)
cluster_name.downcase.gsub(/[^a-z0-9-]/, '_')
end
def get_deploy_user(node = self.node)
return node['opsworks']['deploy_user'] if node['opsworks']
::Chef::Log.info('Unknown environment. (get_deploy_user)')
{
'home' => nil,
'group' => nil,
'user' => nil
}
end
def get_instance_roles(node = self.node)
return node['opsworks']['instance']['layers'] if node['opsworks']
::Chef::Log.debug('Unknown environment. (get_instance_roles)')
end
def get_instance(node = self.node)
if node.fetch('opsworks', {})['instance']
return node['opsworks']['instance']
end
::Chef::Log.debug('Unknown environment. (get_instance)')
false
end
def is_aws(node = self.node)
return true if node['opsworks']
false
end
# Determines the hostname of the current node
#
# @return [String]
def get_hostname(node = self.node)
return get_instance(node)['hostname'] if get_instance(node) && get_instance(node)['hostname']
return node['server_name'] if node['server_name']
node['hostname']
end
def get_awsregion(node = self.node)
node['opsworks']['instance']['region']
end
def get_opsworks_activity(node = self.node)
node['opsworks']['activity']
end
# constructs an almost FQDN (except for the actual zone name)
def get_record_name(node = self.node)
instance = get_instance(node)
host_name = get_hostname(node)
Chef::Application.fatal!('Can not determine the hostname of this node!') if host_name.nil?
stack_name = get_normalized_cluster_name(node)
region_id = instance['region']
"#{host_name}.#{stack_name}.#{region_id}"
end
extend self
end
Chef::Provider.send(:include, ::EasyBib)
Chef::Recipe.send(:include, ::EasyBib)
Chef::Resource.send(:include, ::EasyBib)