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, #event_log, #logger, perform, #result_file, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log
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
#deployment_manager ⇒ Object
18
19
20
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 18
def deployment_manager
@deployment_manager ||= Bosh::Director::Api::DeploymentManager.new
end
|
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 44
def send_alert(instance, message)
nats = Bosh::Director::Config.nats
payload = Yajl::Encoder.encode(
{
"id" => 'director',
"severity" => ERROR,
"title" => "director - snapshot failure",
"summary" => "failed to snapshot #{instance.job}/#{instance.index}: #{message}",
"created_at" => Time.now.to_i
}
)
nats.publish('hm.director.alert', payload)
end
|
#snapshot(instance) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/bosh/director/jobs/snapshot_deployment.rb', line 33
def snapshot(instance)
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
|