Class: Bosh::Director::Jobs::DeleteDeploymentSnapshots

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/delete_deployment_snapshots.rb

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) ⇒ DeleteDeploymentSnapshots

Returns a new instance of DeleteDeploymentSnapshots.



12
13
14
# File 'lib/bosh/director/jobs/delete_deployment_snapshots.rb', line 12

def initialize(deployment_name)
  @deployment = deployment_manager.find_by_name(deployment_name)
end

Instance Attribute Details

#deploymentObject (readonly)

Returns the value of attribute deployment.



6
7
8
# File 'lib/bosh/director/jobs/delete_deployment_snapshots.rb', line 6

def deployment
  @deployment
end

Class Method Details

.job_typeObject



8
9
10
# File 'lib/bosh/director/jobs/delete_deployment_snapshots.rb', line 8

def self.job_type
  :delete_deployment_snapshots
end

Instance Method Details

#deployment_managerObject



16
17
18
# File 'lib/bosh/director/jobs/delete_deployment_snapshots.rb', line 16

def deployment_manager
  @deployment_manager ||= Bosh::Director::Api::DeploymentManager.new
end

#performObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bosh/director/jobs/delete_deployment_snapshots.rb', line 20

def perform
  logger.info("deleting snapshots of deployment: #{deployment.name}")
  deployment.job_instances.each do |instance|
    snapshots = instance.persistent_disks.map { |disk| disk.snapshots }.flatten
    if snapshots.any?
      logger.info("deleting snapshots of: #{instance.job}/#{instance.index} (#{instance.vm_cid})")
      Bosh::Director::Api::SnapshotManager.delete_snapshots(snapshots)
    end
  end

  "snapshots of deployment '#{deployment.name}' deleted"
end