class Bosh::Director::Jobs::SnapshotDeployment
Constants
- ERROR
Attributes
deployment[R]
Public Class Methods
job_type()
click to toggle source
# File lib/bosh/director/jobs/snapshot_deployment.rb, line 8 def self.job_type :snapshot_deployment end
new(deployment_name, options = {})
click to toggle source
# 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
Public Instance Methods
deployment_manager()
click to toggle source
# File lib/bosh/director/jobs/snapshot_deployment.rb, line 18 def deployment_manager @deployment_manager ||= Bosh::Director::Api::DeploymentManager.new end
perform()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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