bosh-director 1.5.0.pre.1113
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/bin/bosh-director +36 -0
- data/bin/bosh-director-console +84 -0
- data/bin/bosh-director-drain-workers +42 -0
- data/bin/bosh-director-migrate +58 -0
- data/bin/bosh-director-scheduler +27 -0
- data/bin/bosh-director-worker +76 -0
- data/db/migrations/README +1 -0
- data/db/migrations/director/20110209010747_initial.rb +118 -0
- data/db/migrations/director/20110406055800_add_task_user.rb +9 -0
- data/db/migrations/director/20110518225809_remove_cid_constrain.rb +13 -0
- data/db/migrations/director/20110617211923_add_deployments_release_versions.rb +32 -0
- data/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb +9 -0
- data/db/migrations/director/20110628023039_add_state_to_instances.rb +21 -0
- data/db/migrations/director/20110709012332_add_disk_size_to_instances.rb +9 -0
- data/db/migrations/director/20110906183441_add_log_bundles.rb +11 -0
- data/db/migrations/director/20110907194830_add_logs_json_to_templates.rb +9 -0
- data/db/migrations/director/20110915205610_add_persistent_disks.rb +51 -0
- data/db/migrations/director/20111005180929_add_properties.rb +14 -0
- data/db/migrations/director/20111110024617_add_deployment_problems.rb +24 -0
- data/db/migrations/director/20111216214145_recreate_support_for_vms.rb +9 -0
- data/db/migrations/director/20120102084027_add_credentials_to_vms.rb +7 -0
- data/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb +36 -0
- data/db/migrations/director/20120524175805_add_task_type.rb +44 -0
- data/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb +34 -0
- data/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb +17 -0
- data/db/migrations/director/20120830191244_add_properties_to_templates.rb +9 -0
- data/db/migrations/director/20121106190739_persist_vm_env.rb +9 -0
- data/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb +9 -0
- data/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb +19 -0
- data/db/migrations/director/20130409235338_snapshot.rb +15 -0
- data/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb +14 -0
- data/db/migrations/director/20130531172604_add_director_attributes.rb +13 -0
- data/db/migrations/dns/20120123234908_initial.rb +27 -0
- data/lib/bosh/director.rb +133 -0
- data/lib/bosh/director/agent_client.rb +78 -0
- data/lib/bosh/director/api.rb +29 -0
- data/lib/bosh/director/api/api_helper.rb +81 -0
- data/lib/bosh/director/api/backup_manager.rb +15 -0
- data/lib/bosh/director/api/controller.rb +639 -0
- data/lib/bosh/director/api/controller_helpers.rb +34 -0
- data/lib/bosh/director/api/deployment_lookup.rb +13 -0
- data/lib/bosh/director/api/deployment_manager.rb +60 -0
- data/lib/bosh/director/api/http_constants.rb +16 -0
- data/lib/bosh/director/api/instance_lookup.rb +44 -0
- data/lib/bosh/director/api/instance_manager.rb +63 -0
- data/lib/bosh/director/api/problem_manager.rb +40 -0
- data/lib/bosh/director/api/property_manager.rb +69 -0
- data/lib/bosh/director/api/release_manager.rb +59 -0
- data/lib/bosh/director/api/resource_manager.rb +69 -0
- data/lib/bosh/director/api/resurrector_manager.rb +15 -0
- data/lib/bosh/director/api/snapshot_manager.rb +94 -0
- data/lib/bosh/director/api/stemcell_manager.rb +50 -0
- data/lib/bosh/director/api/task_helper.rb +46 -0
- data/lib/bosh/director/api/task_manager.rb +64 -0
- data/lib/bosh/director/api/user_manager.rb +72 -0
- data/lib/bosh/director/api/vm_state_manager.rb +11 -0
- data/lib/bosh/director/app.rb +35 -0
- data/lib/bosh/director/blob_util.rb +87 -0
- data/lib/bosh/director/blobstores.rb +29 -0
- data/lib/bosh/director/client.rb +156 -0
- data/lib/bosh/director/cloudcheck_helper.rb +204 -0
- data/lib/bosh/director/compile_task.rb +157 -0
- data/lib/bosh/director/config.rb +370 -0
- data/lib/bosh/director/configuration_hasher.rb +114 -0
- data/lib/bosh/director/cycle_helper.rb +36 -0
- data/lib/bosh/director/db_backup.rb +22 -0
- data/lib/bosh/director/db_backup/adapter.rb +3 -0
- data/lib/bosh/director/db_backup/adapter/mysql2.rb +27 -0
- data/lib/bosh/director/db_backup/adapter/postgres.rb +36 -0
- data/lib/bosh/director/db_backup/adapter/sqlite.rb +17 -0
- data/lib/bosh/director/db_backup/error.rb +10 -0
- data/lib/bosh/director/deployment_plan.rb +26 -0
- data/lib/bosh/director/deployment_plan/assembler.rb +430 -0
- data/lib/bosh/director/deployment_plan/compilation_config.rb +54 -0
- data/lib/bosh/director/deployment_plan/compiled_package.rb +35 -0
- data/lib/bosh/director/deployment_plan/dynamic_network.rb +91 -0
- data/lib/bosh/director/deployment_plan/idle_vm.rb +109 -0
- data/lib/bosh/director/deployment_plan/instance.rb +413 -0
- data/lib/bosh/director/deployment_plan/job.rb +470 -0
- data/lib/bosh/director/deployment_plan/manual_network.rb +137 -0
- data/lib/bosh/director/deployment_plan/network.rb +74 -0
- data/lib/bosh/director/deployment_plan/network_subnet.rb +167 -0
- data/lib/bosh/director/deployment_plan/planner.rb +288 -0
- data/lib/bosh/director/deployment_plan/preparer.rb +52 -0
- data/lib/bosh/director/deployment_plan/release.rb +126 -0
- data/lib/bosh/director/deployment_plan/resource_pool.rb +143 -0
- data/lib/bosh/director/deployment_plan/resource_pools.rb +68 -0
- data/lib/bosh/director/deployment_plan/stemcell.rb +56 -0
- data/lib/bosh/director/deployment_plan/template.rb +94 -0
- data/lib/bosh/director/deployment_plan/update_config.rb +80 -0
- data/lib/bosh/director/deployment_plan/updater.rb +55 -0
- data/lib/bosh/director/deployment_plan/vip_network.rb +79 -0
- data/lib/bosh/director/dns_helper.rb +204 -0
- data/lib/bosh/director/download_helper.rb +44 -0
- data/lib/bosh/director/duration.rb +36 -0
- data/lib/bosh/director/encryption_helper.rb +10 -0
- data/lib/bosh/director/errors.rb +198 -0
- data/lib/bosh/director/event_log.rb +136 -0
- data/lib/bosh/director/ext.rb +64 -0
- data/lib/bosh/director/hash_string_vals.rb +13 -0
- data/lib/bosh/director/instance_deleter.rb +109 -0
- data/lib/bosh/director/instance_updater.rb +506 -0
- data/lib/bosh/director/ip_util.rb +67 -0
- data/lib/bosh/director/job_queue.rb +16 -0
- data/lib/bosh/director/job_runner.rb +162 -0
- data/lib/bosh/director/job_updater.rb +121 -0
- data/lib/bosh/director/jobs/backup.rb +86 -0
- data/lib/bosh/director/jobs/base_job.rb +66 -0
- data/lib/bosh/director/jobs/cloud_check/apply_resolutions.rb +46 -0
- data/lib/bosh/director/jobs/cloud_check/scan.rb +38 -0
- data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +73 -0
- data/lib/bosh/director/jobs/create_snapshot.rb +23 -0
- data/lib/bosh/director/jobs/delete_deployment.rb +183 -0
- data/lib/bosh/director/jobs/delete_deployment_snapshots.rb +34 -0
- data/lib/bosh/director/jobs/delete_release.rb +219 -0
- data/lib/bosh/director/jobs/delete_snapshots.rb +23 -0
- data/lib/bosh/director/jobs/delete_stemcell.rb +102 -0
- data/lib/bosh/director/jobs/fetch_logs.rb +99 -0
- data/lib/bosh/director/jobs/scheduled_backup.rb +38 -0
- data/lib/bosh/director/jobs/snapshot_deployment.rb +61 -0
- data/lib/bosh/director/jobs/snapshot_deployments.rb +23 -0
- data/lib/bosh/director/jobs/snapshot_self.rb +43 -0
- data/lib/bosh/director/jobs/ssh.rb +59 -0
- data/lib/bosh/director/jobs/update_deployment.rb +110 -0
- data/lib/bosh/director/jobs/update_release.rb +672 -0
- data/lib/bosh/director/jobs/update_stemcell.rb +109 -0
- data/lib/bosh/director/jobs/vm_state.rb +89 -0
- data/lib/bosh/director/lock.rb +133 -0
- data/lib/bosh/director/lock_helper.rb +92 -0
- data/lib/bosh/director/models.rb +29 -0
- data/lib/bosh/director/models/compiled_package.rb +33 -0
- data/lib/bosh/director/models/deployment.rb +22 -0
- data/lib/bosh/director/models/deployment_problem.rb +49 -0
- data/lib/bosh/director/models/deployment_property.rb +21 -0
- data/lib/bosh/director/models/director_attribute.rb +9 -0
- data/lib/bosh/director/models/dns.rb +9 -0
- data/lib/bosh/director/models/dns/domain.rb +9 -0
- data/lib/bosh/director/models/dns/record.rb +7 -0
- data/lib/bosh/director/models/helpers/model_helper.rb +7 -0
- data/lib/bosh/director/models/instance.rb +28 -0
- data/lib/bosh/director/models/log_bundle.rb +10 -0
- data/lib/bosh/director/models/package.rb +30 -0
- data/lib/bosh/director/models/persistent_disk.rb +13 -0
- data/lib/bosh/director/models/release.rb +17 -0
- data/lib/bosh/director/models/release_version.rb +16 -0
- data/lib/bosh/director/models/snapshot.rb +13 -0
- data/lib/bosh/director/models/stemcell.rb +18 -0
- data/lib/bosh/director/models/task.rb +10 -0
- data/lib/bosh/director/models/template.rb +44 -0
- data/lib/bosh/director/models/user.rb +11 -0
- data/lib/bosh/director/models/vm.rb +42 -0
- data/lib/bosh/director/nats_rpc.rb +54 -0
- data/lib/bosh/director/network_reservation.rb +121 -0
- data/lib/bosh/director/next_rebase_version.rb +20 -0
- data/lib/bosh/director/package_compiler.rb +423 -0
- data/lib/bosh/director/problem_handlers/base.rb +153 -0
- data/lib/bosh/director/problem_handlers/inactive_disk.rb +112 -0
- data/lib/bosh/director/problem_handlers/invalid_problem.rb +28 -0
- data/lib/bosh/director/problem_handlers/missing_vm.rb +34 -0
- data/lib/bosh/director/problem_handlers/mount_info_mismatch.rb +62 -0
- data/lib/bosh/director/problem_handlers/out_of_sync_vm.rb +64 -0
- data/lib/bosh/director/problem_handlers/unbound_instance_vm.rb +85 -0
- data/lib/bosh/director/problem_handlers/unresponsive_agent.rb +78 -0
- data/lib/bosh/director/problem_resolver.rb +103 -0
- data/lib/bosh/director/problem_scanner.rb +268 -0
- data/lib/bosh/director/resource_pool_updater.rb +216 -0
- data/lib/bosh/director/scheduler.rb +57 -0
- data/lib/bosh/director/sequel.rb +13 -0
- data/lib/bosh/director/tar_gzipper.rb +47 -0
- data/lib/bosh/director/task_result_file.rb +19 -0
- data/lib/bosh/director/thread_pool.rb +8 -0
- data/lib/bosh/director/validation_helper.rb +55 -0
- data/lib/bosh/director/version.rb +7 -0
- data/lib/bosh/director/vm_creator.rb +80 -0
- data/lib/bosh/director/vm_data.rb +63 -0
- data/lib/bosh/director/vm_metadata_updater.rb +29 -0
- data/lib/bosh/director/vm_reuser.rb +63 -0
- data/lib/cloud/dummy.rb +149 -0
- metadata +664 -0
@@ -0,0 +1,219 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
class DeleteRelease < BaseJob
|
6
|
+
include LockHelper
|
7
|
+
|
8
|
+
@queue = :normal
|
9
|
+
|
10
|
+
def self.job_type
|
11
|
+
:delete_release
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(name, options = {})
|
15
|
+
@name = name
|
16
|
+
@blobstore = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
|
17
|
+
@errors = []
|
18
|
+
@force = !!options["force"]
|
19
|
+
@version = options["version"]
|
20
|
+
@release_manager = Api::ReleaseManager.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_release_version(release_version)
|
24
|
+
release = release_version.release
|
25
|
+
|
26
|
+
packages_to_keep = []
|
27
|
+
packages_to_delete = []
|
28
|
+
templates_to_keep = []
|
29
|
+
templates_to_delete = []
|
30
|
+
|
31
|
+
# We don't delete packages inside this loop b/c Sequel will also delete
|
32
|
+
# them from packages collection we're iterating on which will lead to
|
33
|
+
# skipping some packages
|
34
|
+
release_version.packages.each do |package|
|
35
|
+
if package.release_versions == [ release_version ]
|
36
|
+
packages_to_delete << package
|
37
|
+
else
|
38
|
+
packages_to_keep << package
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
release_version.templates.each do |template|
|
43
|
+
if template.release_versions == [ release_version ]
|
44
|
+
templates_to_delete << template
|
45
|
+
else
|
46
|
+
templates_to_keep << template
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
event_log.begin_stage("Deleting packages", packages_to_delete.count)
|
51
|
+
packages_to_delete.each do |package|
|
52
|
+
track_and_log("#{package.name}/#{package.version}") do
|
53
|
+
logger.info("Package #{package.name}/#{package.version} " +
|
54
|
+
"is only used by this release version " +
|
55
|
+
"and will be deleted")
|
56
|
+
delete_package(package)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
packages_to_keep.each do |package|
|
61
|
+
logger.info("Keeping package #{package.name}/#{package.version} " +
|
62
|
+
"as it is used by other release versions")
|
63
|
+
package.remove_release_version(release_version)
|
64
|
+
end
|
65
|
+
|
66
|
+
event_log.begin_stage("Deleting templates", templates_to_delete.count)
|
67
|
+
templates_to_delete.each do |template|
|
68
|
+
track_and_log("#{template.name}/#{template.version}") do
|
69
|
+
logger.info("Template #{template.name}/#{template.version} " +
|
70
|
+
"is only used by this release version " +
|
71
|
+
"and will be deleted")
|
72
|
+
delete_template(template)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
templates_to_keep.each do |template|
|
77
|
+
logger.info("Keeping template " +
|
78
|
+
"#{template.name}/#{template.version} as it is used " +
|
79
|
+
"by other release versions")
|
80
|
+
template.remove_release_version(release_version)
|
81
|
+
end
|
82
|
+
|
83
|
+
logger.info("Remove all deployments in release version")
|
84
|
+
release_version.remove_all_deployments
|
85
|
+
|
86
|
+
if @errors.empty? || @force
|
87
|
+
release_version.destroy
|
88
|
+
end
|
89
|
+
|
90
|
+
if release.versions.empty?
|
91
|
+
delete_release(release)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_release(release)
|
96
|
+
event_log.begin_stage("Deleting packages", release.packages.count)
|
97
|
+
release.packages.each do |package|
|
98
|
+
track_and_log("#{package.name}/#{package.version}") do
|
99
|
+
delete_package(package)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
event_log.begin_stage("Deleting templates", release.templates.count)
|
104
|
+
release.templates.each do |template|
|
105
|
+
track_and_log("#{template.name}/#{template.version}") do
|
106
|
+
delete_template(template)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
if @errors.empty? || @force
|
111
|
+
event_log.begin_stage("Deleting release versions",
|
112
|
+
release.versions.count)
|
113
|
+
|
114
|
+
release.versions.each do |release_version|
|
115
|
+
track_and_log("#{release.name}/#{release_version.version}") do
|
116
|
+
release_version.destroy
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
release.destroy
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def delete_package(package)
|
125
|
+
compiled_packages = package.compiled_packages
|
126
|
+
|
127
|
+
logger.info("Deleting package #{package.name}/#{package.version}")
|
128
|
+
|
129
|
+
compiled_packages.each do |compiled_package|
|
130
|
+
stemcell = compiled_package.stemcell
|
131
|
+
logger.info("Deleting compiled package " +
|
132
|
+
"(#{compiled_package.blobstore_id}) " +
|
133
|
+
"#{package.name}/#{package.version} " +
|
134
|
+
"for #{stemcell.name}/#{stemcell.version}")
|
135
|
+
delete_blobstore_id(compiled_package.blobstore_id) do
|
136
|
+
compiled_package.destroy
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
delete_blobstore_id(package.blobstore_id) do
|
141
|
+
package.remove_all_release_versions
|
142
|
+
package.destroy
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def delete_template(template)
|
147
|
+
logger.info("Deleting template: #{template.name}/#{template.version}")
|
148
|
+
|
149
|
+
delete_blobstore_id(template.blobstore_id) do
|
150
|
+
template.remove_all_release_versions
|
151
|
+
template.destroy
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def perform
|
156
|
+
logger.info("Processing delete release")
|
157
|
+
|
158
|
+
with_release_lock(@name, :timeout => 10) do
|
159
|
+
logger.info("Looking up release: #{@name}")
|
160
|
+
release = @release_manager.find_by_name(@name)
|
161
|
+
desc = "#{@name}/#{@version}"
|
162
|
+
logger.info("Found: #{release.name}")
|
163
|
+
|
164
|
+
if @version
|
165
|
+
logger.info("Looking up release version `#{desc}'")
|
166
|
+
release_version = @release_manager.find_version(release, @version)
|
167
|
+
logger.info("Found release version `#{desc}'")
|
168
|
+
logger.info("Checking for any deployments still using " +
|
169
|
+
"this particular release version")
|
170
|
+
|
171
|
+
deployments = release_version.deployments
|
172
|
+
|
173
|
+
unless deployments.empty?
|
174
|
+
names = deployments.map{ |d| d.name }.join(", ")
|
175
|
+
raise ReleaseVersionInUse,
|
176
|
+
"Release version `#{desc}' is still in use by: #{names}"
|
177
|
+
end
|
178
|
+
|
179
|
+
delete_release_version(release_version)
|
180
|
+
else
|
181
|
+
logger.info("Checking for any deployments still using the release")
|
182
|
+
deployments = release.versions.map { |version|
|
183
|
+
version.deployments
|
184
|
+
}.flatten.uniq
|
185
|
+
|
186
|
+
unless deployments.empty?
|
187
|
+
names = deployments.map { |d| d.name }.join(", ")
|
188
|
+
raise ReleaseInUse,
|
189
|
+
"Release `#{@name}' is still in use by: #{names}"
|
190
|
+
end
|
191
|
+
|
192
|
+
delete_release(release)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
unless @errors.empty?
|
197
|
+
errors = @errors.map { |e| e.to_s }.join(", ")
|
198
|
+
raise ReleaseDeleteFailed, "Can't delete release: #{errors}"
|
199
|
+
end
|
200
|
+
|
201
|
+
"/release/#{@name}"
|
202
|
+
end
|
203
|
+
|
204
|
+
def delete_blobstore_id(blobstore_id)
|
205
|
+
deleted = false
|
206
|
+
begin
|
207
|
+
@blobstore.delete(blobstore_id)
|
208
|
+
deleted = true
|
209
|
+
rescue Exception => e
|
210
|
+
logger.warn("Could not delete from blobstore: #{e}\n " +
|
211
|
+
e.backtrace.join("\n"))
|
212
|
+
@errors << e
|
213
|
+
end
|
214
|
+
yield if deleted || @force
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Jobs
|
3
|
+
class DeleteSnapshots < BaseJob
|
4
|
+
|
5
|
+
@queue = :normal
|
6
|
+
|
7
|
+
def self.job_type
|
8
|
+
:delete_snapshot
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(snapshots_cids)
|
12
|
+
@snapshot_cids = snapshots_cids
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform
|
16
|
+
logger.info("deleting snapshots: #{@snapshot_cids.join(', ')}")
|
17
|
+
snapshots = Bosh::Director::Models::Snapshot.where(snapshot_cid: @snapshot_cids).to_a
|
18
|
+
Bosh::Director::Api::SnapshotManager.delete_snapshots(snapshots)
|
19
|
+
"snapshot(s) #{@snapshot_cids.join(', ')} deleted"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
class DeleteStemcell < BaseJob
|
6
|
+
include LockHelper
|
7
|
+
|
8
|
+
@queue = :normal
|
9
|
+
|
10
|
+
def self.job_type
|
11
|
+
:delete_stemcell
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [String] name Stemcell name
|
15
|
+
# @param [String] version Stemcell version
|
16
|
+
def initialize(name, version, options = {})
|
17
|
+
@name = name
|
18
|
+
@version = version
|
19
|
+
@options = options
|
20
|
+
@cloud = Config.cloud
|
21
|
+
@blobstore = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
|
22
|
+
@stemcell_manager = Api::StemcellManager.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def perform
|
26
|
+
logger.info("Processing delete stemcell")
|
27
|
+
with_stemcell_lock(@name, @version) do
|
28
|
+
logger.info("Looking up stemcell: #{desc}")
|
29
|
+
@stemcell = @stemcell_manager.find_by_name_and_version(@name, @version)
|
30
|
+
logger.info("Found: #{@stemcell.pretty_inspect}")
|
31
|
+
|
32
|
+
validate_deletion
|
33
|
+
delete_from_cloud
|
34
|
+
cleanup_compiled_packages
|
35
|
+
delete_stemcell_metadata
|
36
|
+
end
|
37
|
+
|
38
|
+
"/stemcells/#{@name}/#{@version}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_deletion
|
42
|
+
logger.info("Checking for any deployments still using the stemcell")
|
43
|
+
deployments = @stemcell.deployments
|
44
|
+
unless deployments.empty?
|
45
|
+
names = deployments.map { |d| d.name }.join(", ")
|
46
|
+
raise StemcellInUse,
|
47
|
+
"Stemcell `#{desc}' is still in use by: #{names}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete_from_cloud
|
52
|
+
event_log.begin_stage("Deleting stemcell from cloud", 1)
|
53
|
+
|
54
|
+
event_log.track("Delete stemcell") do
|
55
|
+
@cloud.delete_stemcell(@stemcell.cid)
|
56
|
+
end
|
57
|
+
rescue => e
|
58
|
+
raise unless force?
|
59
|
+
logger.warn(e.backtrace.join("\n"))
|
60
|
+
logger.info("Force deleting is set, ignoring exception: #{e.message}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def cleanup_compiled_packages
|
64
|
+
logger.info("Looking for any compiled packages on this stemcell")
|
65
|
+
compiled_packages =
|
66
|
+
Models::CompiledPackage.filter(:stemcell_id => @stemcell.id)
|
67
|
+
|
68
|
+
event_log.begin_stage("Deleting compiled packages",
|
69
|
+
compiled_packages.count, [@name, @version])
|
70
|
+
logger.info("Deleting compiled packages " +
|
71
|
+
"(#{compiled_packages.count}) for `#{desc}'")
|
72
|
+
|
73
|
+
compiled_packages.each do |compiled_package|
|
74
|
+
next unless compiled_package
|
75
|
+
|
76
|
+
package = compiled_package.package
|
77
|
+
track_and_log("#{package.name}/#{package.version}") do
|
78
|
+
logger.info("Deleting compiled package: " +
|
79
|
+
"#{package.name}/#{package.version}")
|
80
|
+
@blobstore.delete(compiled_package.blobstore_id)
|
81
|
+
compiled_package.destroy
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_stemcell_metadata
|
87
|
+
event_log.begin_stage("Deleting stemcell metadata", 1)
|
88
|
+
event_log.track("Deleting stemcell metadata") do
|
89
|
+
@stemcell.destroy
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def desc
|
94
|
+
"#@name/#@version"
|
95
|
+
end
|
96
|
+
|
97
|
+
def force?
|
98
|
+
@options["force"]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
class FetchLogs < BaseJob
|
6
|
+
include LockHelper
|
7
|
+
|
8
|
+
DEFAULT_BUNDLE_LIFETIME = 86400 * 10 # 10 days
|
9
|
+
|
10
|
+
@queue = :normal
|
11
|
+
|
12
|
+
attr_accessor :bundle_lifetime
|
13
|
+
|
14
|
+
def self.job_type
|
15
|
+
:fetch_logs
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(instance_id, options = {})
|
19
|
+
@blobstore = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
|
20
|
+
@instance_id = instance_id
|
21
|
+
@log_type = options["type"] || "job"
|
22
|
+
@filters = options["filters"]
|
23
|
+
@instance_manager = Api::InstanceManager.new
|
24
|
+
@bundle_lifetime = DEFAULT_BUNDLE_LIFETIME
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform
|
28
|
+
instance = @instance_manager.find_instance(@instance_id)
|
29
|
+
desc = "#{instance.job}/#{instance.index}"
|
30
|
+
|
31
|
+
deployment = instance.deployment
|
32
|
+
|
33
|
+
if deployment.nil?
|
34
|
+
raise InstanceDeploymentMissing,
|
35
|
+
"`#{desc}' doesn't belong to any deployment"
|
36
|
+
end
|
37
|
+
|
38
|
+
with_deployment_lock(deployment) do
|
39
|
+
cleanup_old_bundles
|
40
|
+
|
41
|
+
event_log.begin_stage("Fetching logs for #{desc}", 1)
|
42
|
+
|
43
|
+
agent = @instance_manager.agent_client_for(instance)
|
44
|
+
blobstore_id = nil
|
45
|
+
|
46
|
+
track_and_log("Finding and packing log files") do
|
47
|
+
logger.info("Fetching logs from agent: " +
|
48
|
+
"log_type='#{@log_type}', filters='#{@filters}'")
|
49
|
+
|
50
|
+
task = agent.fetch_logs(@log_type, @filters)
|
51
|
+
blobstore_id = task["blobstore_id"]
|
52
|
+
end
|
53
|
+
|
54
|
+
if blobstore_id.nil?
|
55
|
+
raise AgentTaskNoBlobstoreId,
|
56
|
+
"Agent didn't return a blobstore object id for packaged logs"
|
57
|
+
end
|
58
|
+
|
59
|
+
Models::LogBundle.create(:blobstore_id => blobstore_id,
|
60
|
+
:timestamp => Time.now)
|
61
|
+
|
62
|
+
# The returned value of this method is used as task result
|
63
|
+
# and gets extracted by CLI as a tarball blobstore id
|
64
|
+
blobstore_id
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def cleanup_old_bundles
|
69
|
+
old_bundles = Models::LogBundle.filter("timestamp <= ?",
|
70
|
+
Time.now - bundle_lifetime)
|
71
|
+
count = old_bundles.count
|
72
|
+
|
73
|
+
if count == 0
|
74
|
+
logger.info("No old bundles to delete")
|
75
|
+
return
|
76
|
+
end
|
77
|
+
|
78
|
+
logger.info("Deleting #{count} old log bundle#{count > 1 ? "s" : ""}")
|
79
|
+
|
80
|
+
old_bundles.each do |bundle|
|
81
|
+
begin
|
82
|
+
logger.info("Deleting log bundle #{bundle.id}: " +
|
83
|
+
"#{bundle.blobstore_id}")
|
84
|
+
@blobstore.delete(bundle.blobstore_id)
|
85
|
+
bundle.delete
|
86
|
+
rescue Bosh::Blobstore::BlobstoreError => e
|
87
|
+
logger.warn("Could not delete #{bundle.blobstore_id}: #{e}")
|
88
|
+
# Assuming object has been deleted from blobstore by someone else,
|
89
|
+
# cleaning up DB record accordingly
|
90
|
+
if e.kind_of?(Bosh::Blobstore::NotFound)
|
91
|
+
bundle.delete
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Jobs
|
3
|
+
class ScheduledBackup < BaseJob
|
4
|
+
@queue = :normal
|
5
|
+
|
6
|
+
attr_reader :backup_job
|
7
|
+
|
8
|
+
def self.job_type
|
9
|
+
:scheduled_backup
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@backup_job = options.fetch(:backup_job) { Backup.new(backup_file) }
|
14
|
+
@backup_destination = options.fetch(:backup_destination) { App.instance.blobstores.backup_destination }
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
@backup_job.perform
|
19
|
+
|
20
|
+
blobstore_path = "backup-#{Time.now.utc.iso8601}.tgz"
|
21
|
+
|
22
|
+
File.open(@backup_job.backup_file) do |f|
|
23
|
+
@backup_destination.create(f, blobstore_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
"Stored `#{blobstore_path}' in backup blobstore"
|
27
|
+
ensure
|
28
|
+
FileUtils.rm_f(@backup_job.backup_file)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def backup_file
|
34
|
+
File.join(Dir.tmpdir, "backup-#{task_id}.tgz")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|