Class: Chef::EventDispatch::Etcd

Inherits:
Base
  • Object
show all
Defined in:
lib/chef/handler/etcd_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Etcd

Returns a new instance of Etcd.



10
11
12
13
14
15
16
# File 'lib/chef/handler/etcd_event.rb', line 10

def initialize(options={})
  etcd_host = options[:host] || '127.0.0.1'
  etcd_port = options[:port] || 4001
  @etcd = ::Etcd.client(host: etcd_host, port: etcd_port)
  @global_ttl = options[:global_ttl] || 600
  @ttls = options[:ttls] || {}
end

Instance Attribute Details

#etcdObject (readonly)

Returns the value of attribute etcd.



8
9
10
# File 'lib/chef/handler/etcd_event.rb', line 8

def etcd
  @etcd
end

Instance Method Details

#attribute_file_load_failed(path, exception) ⇒ Object



155
156
157
# File 'lib/chef/handler/etcd_event.rb', line 155

def attribute_file_load_failed(path, exception)
  set_sub_status(__method__)
end

#attribute_load_completeObject



159
160
161
# File 'lib/chef/handler/etcd_event.rb', line 159

def attribute_load_complete
  set_sub_status(__method__)
end

#attribute_load_start(attribute_file_count) ⇒ Object



151
152
153
# File 'lib/chef/handler/etcd_event.rb', line 151

def attribute_load_start(attribute_file_count)
  set_sub_status(__method__)
end

#converge_completeObject



195
196
197
# File 'lib/chef/handler/etcd_event.rb', line 195

def converge_complete
  set_sub_status(__method__)
end

#converge_start(run_context) ⇒ Object



191
192
193
# File 'lib/chef/handler/etcd_event.rb', line 191

def converge_start(run_context)
  set_sub_status(__method__)
end

#cookbook_clean_completeObject



111
112
113
# File 'lib/chef/handler/etcd_event.rb', line 111

def cookbook_clean_complete
  set_sub_status(__method__)
end

#cookbook_clean_startObject



107
108
109
# File 'lib/chef/handler/etcd_event.rb', line 107

def cookbook_clean_start
  set_sub_status(__method__)
end

#cookbook_resolution_complete(cookbook_collection) ⇒ Object



103
104
105
# File 'lib/chef/handler/etcd_event.rb', line 103

def cookbook_resolution_complete(cookbook_collection)
  set_sub_status(__method__)
end

#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object



99
100
101
# File 'lib/chef/handler/etcd_event.rb', line 99

def cookbook_resolution_failed(expanded_run_list, exception)
  set_sub_status(__method__)
end

#cookbook_resolution_start(expanded_run_list) ⇒ Object



95
96
97
# File 'lib/chef/handler/etcd_event.rb', line 95

def cookbook_resolution_start(expanded_run_list)
  set_sub_status(__method__)
end

#cookbook_sync_completeObject



123
124
125
# File 'lib/chef/handler/etcd_event.rb', line 123

def cookbook_sync_complete
  set_sub_status(__method__)
end

#cookbook_sync_failed(cookbooks, exception) ⇒ Object



119
120
121
# File 'lib/chef/handler/etcd_event.rb', line 119

def cookbook_sync_failed(cookbooks, exception)
  set_sub_status(__method__)
end

#cookbook_sync_start(cookbook_count) ⇒ Object



115
116
117
# File 'lib/chef/handler/etcd_event.rb', line 115

def cookbook_sync_start(cookbook_count)
  set_sub_status(__method__)
end

#definition_file_load_failed(path, exception) ⇒ Object



167
168
169
# File 'lib/chef/handler/etcd_event.rb', line 167

def definition_file_load_failed(path, exception)
  set_sub_status(__method__)
end

#definition_load_completeObject



171
172
173
# File 'lib/chef/handler/etcd_event.rb', line 171

def definition_load_complete
  set_sub_status(__method__)
end

#definition_load_start(definition_file_count) ⇒ Object



163
164
165
# File 'lib/chef/handler/etcd_event.rb', line 163

def definition_load_start(definition_file_count)
  set_sub_status(__method__)
end

#etcd_set(m, k, v = nil) ⇒ Object

m = method



30
31
32
33
34
35
# File 'lib/chef/handler/etcd_event.rb', line 30

def etcd_set(m, k, v=nil) # m = method
  key= name_space + k 
  value = v || m
  ttl = get_ttl(m)
  etcd.set(key, value, ttl)
end

#get_ttl(m) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/chef/handler/etcd_event.rb', line 18

def get_ttl(m)
  if @ttls.has_key?(m)
    @ttls[m]
  else
    @global_ttl
  end
end

#handlers_completedObject



245
246
247
# File 'lib/chef/handler/etcd_event.rb', line 245

def handlers_completed
  set_sub_status(__method__)
end

#handlers_start(handler_count) ⇒ Object



241
242
243
# File 'lib/chef/handler/etcd_event.rb', line 241

def handlers_start(handler_count)
  set_sub_status(__method__)
end

#library_file_load_failed(path, exception) ⇒ Object



131
132
133
# File 'lib/chef/handler/etcd_event.rb', line 131

def library_file_load_failed(path, exception)
  set_sub_status(__method__)
end

#library_load_completeObject



135
136
137
# File 'lib/chef/handler/etcd_event.rb', line 135

def library_load_complete
  set_sub_status(__method__)
end

#library_load_start(file_count) ⇒ Object



127
128
129
# File 'lib/chef/handler/etcd_event.rb', line 127

def library_load_start(file_count)
  set_sub_status(__method__)
end

#lwrp_file_load_failed(path, exception) ⇒ Object



143
144
145
# File 'lib/chef/handler/etcd_event.rb', line 143

def lwrp_file_load_failed(path, exception)
  set_sub_status(__method__)
end

#lwrp_load_completeObject



147
148
149
# File 'lib/chef/handler/etcd_event.rb', line 147

def lwrp_load_complete
  set_sub_status(__method__)
end

#lwrp_load_start(lwrp_file_count) ⇒ Object



139
140
141
# File 'lib/chef/handler/etcd_event.rb', line 139

def lwrp_load_start(lwrp_file_count)
  set_sub_status(__method__)
end

#msg(message) ⇒ Object



249
250
# File 'lib/chef/handler/etcd_event.rb', line 249

def msg(message)
end

#name_spaceObject



26
27
28
# File 'lib/chef/handler/etcd_event.rb', line 26

def name_space 
  '/nodes/' + Chef::Config[:node_name] + '/chef'
end

#node_load_completed(node, expanded_run_list, config) ⇒ Object



91
92
93
# File 'lib/chef/handler/etcd_event.rb', line 91

def node_load_completed(node, expanded_run_list, config)
  set_sub_status(__method__)
end

#node_load_failed(node_name, exception, config) ⇒ Object



83
84
85
# File 'lib/chef/handler/etcd_event.rb', line 83

def node_load_failed(node_name, exception, config)
  set_sub_status(__method__)
end

#node_load_start(node_name, config) ⇒ Object



79
80
81
# File 'lib/chef/handler/etcd_event.rb', line 79

def node_load_start(node_name, config)
  set_sub_status(__method__)
end

#ohai_completed(node) ⇒ Object



59
60
61
# File 'lib/chef/handler/etcd_event.rb', line 59

def ohai_completed(node)
  set_sub_status(__method__)
end

#recipe_file_load_failed(path, exception) ⇒ Object



179
180
181
# File 'lib/chef/handler/etcd_event.rb', line 179

def recipe_file_load_failed(path, exception)
  set_sub_status(__method__)
end

#recipe_load_completeObject



187
188
189
# File 'lib/chef/handler/etcd_event.rb', line 187

def recipe_load_complete
  set_sub_status(__method__)
end

#recipe_load_start(recipe_count) ⇒ Object



175
176
177
# File 'lib/chef/handler/etcd_event.rb', line 175

def recipe_load_start(recipe_count)
  set_sub_status(__method__)
end

#recipe_not_found(exception) ⇒ Object



183
184
185
# File 'lib/chef/handler/etcd_event.rb', line 183

def recipe_not_found(exception)
  set_sub_status(__method__)
end

#registration_completedObject



71
72
73
# File 'lib/chef/handler/etcd_event.rb', line 71

def registration_completed
  set_sub_status(__method__)
end

#registration_failed(node_name, exception, config) ⇒ Object



75
76
77
# File 'lib/chef/handler/etcd_event.rb', line 75

def registration_failed(node_name, exception, config)
  set_sub_status(__method__)
end

#registration_start(node_name, config) ⇒ Object



67
68
69
# File 'lib/chef/handler/etcd_event.rb', line 67

def registration_start(node_name, config)
  set_sub_status(__method__)
end

#resource_action_start(resource, action, notification_type = nil, notifier = nil) ⇒ Object



199
200
201
202
203
# File 'lib/chef/handler/etcd_event.rb', line 199

def resource_action_start(resource, action, notification_type=nil, notifier=nil)
  etcd_set(__method__, '/resource_state', 'action_start')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#resource_bypassed(resource, action, current_resource) ⇒ Object



222
223
224
225
226
# File 'lib/chef/handler/etcd_event.rb', line 222

def resource_bypassed(resource, action, current_resource)
  etcd_set(__method__, '/resource_state', 'bypassed')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#resource_completed(resource) ⇒ Object



211
212
213
214
# File 'lib/chef/handler/etcd_event.rb', line 211

def resource_completed(resource)
  etcd_set(__method__, '/resource_state', 'completed')
  etcd_set(__method__, '/resource_name', resource.to_s)
end

#resource_failed(resource, action, exception) ⇒ Object



205
206
207
208
209
# File 'lib/chef/handler/etcd_event.rb', line 205

def resource_failed(resource, action, exception)
  etcd_set(__method__, '/resource_state', 'failed')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#resource_skipped(resource, action, conditional) ⇒ Object



216
217
218
219
220
# File 'lib/chef/handler/etcd_event.rb', line 216

def resource_skipped(resource, action, conditional)
  etcd_set(__method__, '/resource_state', 'skipped')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#resource_up_to_date(resource, action) ⇒ Object



228
229
230
231
232
# File 'lib/chef/handler/etcd_event.rb', line 228

def resource_up_to_date(resource, action)
  etcd_set(__method__, '/resource_state', 'converged')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#resource_updated(resource, action) ⇒ Object



235
236
237
238
239
# File 'lib/chef/handler/etcd_event.rb', line 235

def resource_updated(resource, action)
  etcd_set(__method__, '/resource_state', 'updated')
  etcd_set(__method__, '/resource_name', resource.to_s)
  etcd_set(__method__, '/resource_action', action.to_s)
end

#run_completed(node) ⇒ Object



46
47
48
# File 'lib/chef/handler/etcd_event.rb', line 46

def run_completed(node)
  etcd_set(__method__, '/status', 'completed')
end

#run_failed(exception) ⇒ Object



50
51
52
# File 'lib/chef/handler/etcd_event.rb', line 50

def run_failed(exception)
  etcd_set(__method__, '/status', 'failed')
end

#run_list_expand_failed(node, exception) ⇒ Object



87
88
89
# File 'lib/chef/handler/etcd_event.rb', line 87

def run_list_expand_failed(node, exception)
  set_sub_status(__method__)
end

#run_start(version) ⇒ Object



41
42
43
44
# File 'lib/chef/handler/etcd_event.rb', line 41

def run_start(version)
  etcd_set(__method__, '/status', 'running')
  etcd_set(__method__, '/version', version)
end

#run_started(run_status) ⇒ Object



54
55
56
# File 'lib/chef/handler/etcd_event.rb', line 54

def run_started(run_status)
  set_sub_status(__method__)
end

#set_sub_status(m) ⇒ Object



37
38
39
# File 'lib/chef/handler/etcd_event.rb', line 37

def set_sub_status(m)
 etcd_set(m, '/sub_status')
end

#skipping_registration(node_name, config) ⇒ Object



63
64
65
# File 'lib/chef/handler/etcd_event.rb', line 63

def skipping_registration(node_name, config)
  set_sub_status(__method__)
end