Class: Bosh::Director::Jobs::SnapshotDeployment
- Inherits:
-
BaseJob
show all
- Defined in:
- lib/bosh/director/jobs/snapshot_deployment.rb
Constant Summary
collapse
- ERROR =
3
Instance Attribute Summary collapse
Attributes inherited from BaseJob
#task_id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseJob
#begin_stage, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username
Constructor Details
#initialize(deployment_name, options = {}) ⇒ SnapshotDeployment
Returns a new instance of SnapshotDeployment.
12
13
14
15
16
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 12
def initialize(deployment_name, options = {})
@deployment = deployment_manager.find_by_name(deployment_name)
@options = options
@errors = 0
end
|
Instance Attribute Details
#deployment ⇒ Object
Returns the value of attribute deployment.
6
7
8
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 6
def deployment
@deployment
end
|
Class Method Details
8
9
10
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 8
def self.job_type
:snapshot_deployment
end
|
Instance Method Details
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 22
def perform
logger.info("taking snapshot of: #{deployment.name}")
deployment.job_instances.each do |instance|
snapshot(instance)
end
msg = "snapshots of deployment '#{deployment.name}' created"
msg += ", with #{@errors} failure(s)" unless @errors == 0
msg
end
|
#send_alert(instance, message) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 48
def send_alert(instance, message)
payload = {
'id' => 'director',
'severity' => ERROR,
'title' => 'director - snapshot failure',
'summary' => "failed to snapshot #{instance.job}/#{instance.index}: #{message}",
'created_at' => Time.now.to_i
}
Bosh::Director::Config.nats_rpc.send_message('hm.director.alert', payload)
end
|
#snapshot(instance) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 33
def snapshot(instance)
if instance.vm_cid.nil?
logger.info('No vm attached to this instance, no snapshot; skipping')
return
end
logger.info("taking snapshot of: #{instance.job}/#{instance.index} (#{instance.vm_cid})")
Bosh::Director::Api::SnapshotManager.take_snapshot(instance, @options)
rescue Bosh::Clouds::CloudError => e
@errors += 1
logger.error("failed to take snapshot of: #{instance.job}/#{instance.index} (#{instance.vm_cid}) - #{e.inspect}")
send_alert(instance, e.inspect)
end
|