Class: Bosh::Director::Jobs::DeleteStemcell
Instance Attribute Summary
Attributes inherited from BaseJob
#task_id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from LockHelper
#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock
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(name, version, options = {}) ⇒ DeleteStemcell
Returns a new instance of DeleteStemcell.
16
17
18
19
20
21
22
23
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 16
def initialize(name, version, options = {})
@name = name
@version = version
@options = options
@cloud = Config.cloud
@blobstore = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
@stemcell_manager = Api::StemcellManager.new
end
|
Class Method Details
10
11
12
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 10
def self.job_type
:delete_stemcell
end
|
Instance Method Details
#cleanup_compiled_packages ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 63
def cleanup_compiled_packages
logger.info("Looking for any compiled packages on this stemcell")
compiled_packages =
Models::CompiledPackage.filter(:stemcell_id => @stemcell.id)
event_log.begin_stage("Deleting compiled packages",
compiled_packages.count, [@name, @version])
logger.info("Deleting compiled packages " +
"(#{compiled_packages.count}) for `#{desc}'")
compiled_packages.each do |compiled_package|
next unless compiled_package
package = compiled_package.package
track_and_log("#{package.name}/#{package.version}") do
logger.info("Deleting compiled package: " +
"#{package.name}/#{package.version}")
@blobstore.delete(compiled_package.blobstore_id)
compiled_package.destroy
end
end
end
|
#delete_from_cloud ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 51
def delete_from_cloud
event_log.begin_stage("Deleting stemcell from cloud", 1)
event_log.track("Delete stemcell") do
@cloud.delete_stemcell(@stemcell.cid)
end
rescue => e
raise unless force?
logger.warn(e.backtrace.join("\n"))
logger.info("Force deleting is set, ignoring exception: #{e.message}")
end
|
86
87
88
89
90
91
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 86
def delete_stemcell_metadata
event_log.begin_stage("Deleting stemcell metadata", 1)
event_log.track("Deleting stemcell metadata") do
@stemcell.destroy
end
end
|
93
94
95
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 93
def desc
"#@name/#@version"
end
|
#force? ⇒ Boolean
97
98
99
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 97
def force?
@options["force"]
end
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 25
def perform
logger.info("Processing delete stemcell")
with_stemcell_lock(@name, @version) do
logger.info("Looking up stemcell: #{desc}")
@stemcell = @stemcell_manager.find_by_name_and_version(@name, @version)
logger.info("Found: #{@stemcell.pretty_inspect}")
validate_deletion
delete_from_cloud
cleanup_compiled_packages
delete_stemcell_metadata
end
"/stemcells/#{@name}/#{@version}"
end
|
#validate_deletion ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/bosh/director/jobs/delete_stemcell.rb', line 41
def validate_deletion
logger.info("Checking for any deployments still using the stemcell")
deployments = @stemcell.deployments
unless deployments.empty?
names = deployments.map { |d| d.name }.join(", ")
raise StemcellInUse,
"Stemcell `#{desc}' is still in use by: #{names}"
end
end
|