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,66 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
class BaseJob
|
6
|
+
|
7
|
+
def self.job_type
|
8
|
+
raise NotImplementedError.new('Subclasses must return a symbol representing type')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.perform(task_id, *args)
|
12
|
+
Bosh::Director::JobRunner.new(self, task_id).run(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :task_id
|
16
|
+
|
17
|
+
def logger
|
18
|
+
@logger ||= Config.logger
|
19
|
+
end
|
20
|
+
|
21
|
+
def event_log
|
22
|
+
@event_log ||= Config.event_log
|
23
|
+
end
|
24
|
+
|
25
|
+
def result_file
|
26
|
+
@result_file ||= Config.result
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] Has task been cancelled?
|
30
|
+
def task_cancelled?
|
31
|
+
return false if task_id.nil?
|
32
|
+
task = task_manager.find_task(task_id)
|
33
|
+
task && (task.state == "cancelling" || task.state == "timeout")
|
34
|
+
end
|
35
|
+
|
36
|
+
def task_checkpoint
|
37
|
+
if task_cancelled?
|
38
|
+
raise TaskCancelled, "Task #{task_id} cancelled"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def begin_stage(stage_name, n_steps)
|
43
|
+
event_log.begin_stage(stage_name, n_steps)
|
44
|
+
logger.info(stage_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def track_and_log(task, log = true)
|
48
|
+
event_log.track(task) do |ticker|
|
49
|
+
logger.info(task) if log
|
50
|
+
yield ticker if block_given?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def single_step_stage(stage_name)
|
55
|
+
begin_stage(stage_name, 1)
|
56
|
+
track_and_log(stage_name, false) { yield }
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def task_manager
|
62
|
+
@task_manager ||= Api::TaskManager.new
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
module CloudCheck
|
6
|
+
class ApplyResolutions < BaseJob
|
7
|
+
include LockHelper
|
8
|
+
|
9
|
+
@queue = :normal
|
10
|
+
|
11
|
+
def self.job_type
|
12
|
+
:cck_apply
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String] deployment_name Deployment name
|
16
|
+
# @param [Hash] resolutions Problem resolutions
|
17
|
+
def initialize(deployment_name, resolutions)
|
18
|
+
@deployment_manager = Api::DeploymentManager.new
|
19
|
+
@deployment = @deployment_manager.find_by_name(deployment_name)
|
20
|
+
|
21
|
+
unless resolutions.kind_of?(Hash)
|
22
|
+
raise CloudcheckInvalidResolutionFormat,
|
23
|
+
"Invalid format for resolutions, Hash expected, #{resolutions.class} is given"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Normalizing problem ids
|
27
|
+
@resolutions =
|
28
|
+
resolutions.inject({}) { |hash, (problem_id, solution_name)|
|
29
|
+
hash[problem_id.to_s] = solution_name
|
30
|
+
hash
|
31
|
+
}
|
32
|
+
|
33
|
+
@problem_resolver = ProblemResolver.new(@deployment)
|
34
|
+
end
|
35
|
+
|
36
|
+
def perform
|
37
|
+
with_deployment_lock(@deployment) do
|
38
|
+
count = @problem_resolver.apply_resolutions(@resolutions)
|
39
|
+
"#{count} resolved"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
module CloudCheck
|
6
|
+
class Scan < BaseJob
|
7
|
+
include LockHelper
|
8
|
+
|
9
|
+
@queue = :normal
|
10
|
+
|
11
|
+
def self.job_type
|
12
|
+
:cck_scan
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String] deployment_name Deployment name
|
16
|
+
def initialize(deployment_name)
|
17
|
+
@deployment_manager = Api::DeploymentManager.new
|
18
|
+
@deployment = @deployment_manager.find_by_name(deployment_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def perform
|
22
|
+
begin
|
23
|
+
with_deployment_lock(@deployment, :timeout => 0) do
|
24
|
+
scanner = ProblemScanner.new(@deployment)
|
25
|
+
scanner.reset
|
26
|
+
scanner.scan_vms
|
27
|
+
scanner.scan_disks
|
28
|
+
|
29
|
+
"scan complete"
|
30
|
+
end
|
31
|
+
rescue Lock::TimeoutError
|
32
|
+
raise "Unable to get deployment lock, maybe a deployment is in progress. Try again later."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# This job is used by the resurrector health monitor plugin, to notify the director that
|
2
|
+
# it needs to scan the job(s) for problems (only unresponsive agents) and then try to
|
3
|
+
# automatically try to fix it by recreating the job.
|
4
|
+
module Bosh::Director
|
5
|
+
module Jobs
|
6
|
+
module CloudCheck
|
7
|
+
class ScanAndFix < BaseJob
|
8
|
+
include LockHelper
|
9
|
+
|
10
|
+
attr_reader :filtered_jobs
|
11
|
+
|
12
|
+
@queue = :normal
|
13
|
+
|
14
|
+
def self.job_type
|
15
|
+
:cck_scan_and_fix
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(deployment_name, jobs, fix_stateful_jobs=false)
|
19
|
+
@deployment_manager = Api::DeploymentManager.new
|
20
|
+
@instance_manager = Bosh::Director::Api::InstanceManager.new
|
21
|
+
@deployment = @deployment_manager.find_by_name(deployment_name)
|
22
|
+
@jobs = jobs # {j1 => [i1, i2, ...], j2 => [i1, i2, ...]}
|
23
|
+
@fix_stateful_jobs = fix_stateful_jobs
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform
|
27
|
+
jobs = filtered_jobs
|
28
|
+
|
29
|
+
begin
|
30
|
+
with_deployment_lock(@deployment, :timeout => 0) do
|
31
|
+
|
32
|
+
scanner = ProblemScanner.new(@deployment)
|
33
|
+
scanner.reset(jobs)
|
34
|
+
scanner.scan_vms(jobs)
|
35
|
+
|
36
|
+
resolver = ProblemResolver.new(@deployment)
|
37
|
+
resolver.apply_resolutions(resolutions(jobs))
|
38
|
+
|
39
|
+
"scan and fix complete"
|
40
|
+
end
|
41
|
+
rescue Lock::TimeoutError
|
42
|
+
raise "Unable to get deployment lock, maybe a deployment is in progress. Try again later."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def resolutions(jobs)
|
47
|
+
all_resolutions = {}
|
48
|
+
jobs.each do |job, index|
|
49
|
+
instance = @instance_manager.find_by_name(@deployment.name, job, index)
|
50
|
+
next if instance.resurrection_paused
|
51
|
+
problems = Models::DeploymentProblem.filter(deployment: @deployment, resource_id: instance.vm.id, state: 'open')
|
52
|
+
problems.each do |problem|
|
53
|
+
if problem.type == 'unresponsive_agent' || problem.type == 'missing_vm'
|
54
|
+
all_resolutions[problem.id.to_s] = :recreate_vm
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
all_resolutions
|
60
|
+
end
|
61
|
+
|
62
|
+
def filtered_jobs
|
63
|
+
return @jobs if @fix_stateful_jobs
|
64
|
+
|
65
|
+
@jobs.reject do |job, index|
|
66
|
+
instance = @instance_manager.find_by_name(@deployment.name, job, index)
|
67
|
+
instance.persistent_disk
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Jobs
|
3
|
+
class CreateSnapshot < BaseJob
|
4
|
+
|
5
|
+
@queue = :normal
|
6
|
+
|
7
|
+
def self.job_type
|
8
|
+
:create_snapshot
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(instance_id, options)
|
12
|
+
@instance = Bosh::Director::Api::InstanceManager.new.find_instance(instance_id)
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
logger.info("taking snapshot of: #{@instance.job}/#{@instance.index} (#{@instance.vm.cid})")
|
18
|
+
snapshot_cids = Bosh::Director::Api::SnapshotManager.take_snapshot(@instance, @options)
|
19
|
+
"snapshot(s) #{snapshot_cids.join(', ')} created"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Jobs
|
5
|
+
class DeleteDeployment < BaseJob
|
6
|
+
include DnsHelper
|
7
|
+
include LockHelper
|
8
|
+
|
9
|
+
@queue = :normal
|
10
|
+
|
11
|
+
def self.job_type
|
12
|
+
:delete_deployment
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(deployment_name, options = {})
|
16
|
+
@deployment_name = deployment_name
|
17
|
+
@force = options["force"]
|
18
|
+
@keep_snapshots = options["keep_snapshots"]
|
19
|
+
@cloud = Config.cloud
|
20
|
+
@deployment_manager = Api::DeploymentManager.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform
|
24
|
+
logger.info("Deleting: #{@deployment_name}")
|
25
|
+
|
26
|
+
deployment = find_deployment(@deployment_name)
|
27
|
+
|
28
|
+
logger.info("Acquiring deployment lock: #{deployment.name}")
|
29
|
+
|
30
|
+
with_deployment_lock(@deployment_name) do
|
31
|
+
# Make sure it wasn't deleted
|
32
|
+
deployment = find_deployment(@deployment_name)
|
33
|
+
|
34
|
+
ThreadPool.new(:max_threads => Config.max_threads).wrap do |pool|
|
35
|
+
delete_instances(deployment, pool)
|
36
|
+
pool.wait
|
37
|
+
delete_vms(deployment, pool)
|
38
|
+
end
|
39
|
+
|
40
|
+
event_log.begin_stage("Removing deployment artifacts", 3)
|
41
|
+
track_and_log("Detach stemcells") do
|
42
|
+
deployment.remove_all_stemcells
|
43
|
+
end
|
44
|
+
|
45
|
+
track_and_log("Detaching releases") do
|
46
|
+
deployment.remove_all_release_versions
|
47
|
+
end
|
48
|
+
|
49
|
+
event_log.begin_stage("Deleting properties",
|
50
|
+
deployment.properties.count)
|
51
|
+
logger.info("Deleting deployment properties")
|
52
|
+
deployment.properties.each do |property|
|
53
|
+
event_log.track(property.name) do
|
54
|
+
property.destroy
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
track_and_log("Delete DNS records") do
|
59
|
+
delete_dns(@deployment_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
track_and_log("Destroy deployment") do
|
63
|
+
deployment.destroy
|
64
|
+
end
|
65
|
+
"/deployments/#{@deployment_name}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def find_deployment(name)
|
70
|
+
@deployment_manager.find_by_name(name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_instances(deployment, pool)
|
74
|
+
instances = deployment.job_instances
|
75
|
+
event_log.begin_stage("Deleting instances", instances.count)
|
76
|
+
|
77
|
+
instances.each do |instance|
|
78
|
+
pool.process do
|
79
|
+
desc = "#{instance.job}/#{instance.index}"
|
80
|
+
event_log.track(desc) do
|
81
|
+
logger.info("Deleting #{desc}")
|
82
|
+
delete_instance(instance)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete_vms(deployment, pool)
|
89
|
+
vms = deployment.vms
|
90
|
+
event_log.begin_stage("Deleting idle VMs", vms.count)
|
91
|
+
|
92
|
+
vms.each do |vm|
|
93
|
+
pool.process do
|
94
|
+
event_log.track("#{vm.cid}") do
|
95
|
+
logger.info("Deleting idle vm #{vm.cid}")
|
96
|
+
delete_vm(vm)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def delete_instance(instance)
|
103
|
+
desc = "#{instance.job}/#{instance.index}"
|
104
|
+
with_thread_name("delete_instance(#{desc})") do
|
105
|
+
logger.info("Deleting instance: #{desc}")
|
106
|
+
|
107
|
+
vm = instance.vm
|
108
|
+
|
109
|
+
if vm && vm.agent_id
|
110
|
+
ignoring_errors_when_forced do
|
111
|
+
agent = AgentClient.new(vm.agent_id)
|
112
|
+
agent.stop
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
instance.persistent_disks.each do |disk|
|
117
|
+
if disk.active && vm && vm.cid && disk.disk_cid
|
118
|
+
if vm.agent_id
|
119
|
+
ignoring_errors_when_forced do
|
120
|
+
agent = AgentClient.new(vm.agent_id)
|
121
|
+
agent.unmount_disk(disk.disk_cid)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
ignoring_errors_when_forced do
|
126
|
+
# If persistent disk has been mounted but
|
127
|
+
# clean_shutdown above did not unmount it
|
128
|
+
# properly (i.e. for wedged deployment),
|
129
|
+
# detach_disk might hang indefinitely.
|
130
|
+
# Right now it's up to cloudcheck handle
|
131
|
+
# that but 'force' might be added to CPI
|
132
|
+
# in the future.
|
133
|
+
@cloud.detach_disk(vm.cid, disk.disk_cid)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
if disk.disk_cid
|
138
|
+
ignoring_errors_when_forced do
|
139
|
+
delete_snapshots(disk)
|
140
|
+
@cloud.delete_disk(disk.disk_cid)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
disk.destroy
|
145
|
+
end
|
146
|
+
|
147
|
+
instance.destroy
|
148
|
+
|
149
|
+
delete_vm(vm) if vm
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def delete_snapshots(disk)
|
154
|
+
@keep_snapshots ? disk.snapshots.each(&:delete) : Api::SnapshotManager.delete_snapshots(disk.snapshots)
|
155
|
+
end
|
156
|
+
|
157
|
+
def delete_vm(vm)
|
158
|
+
if vm.cid
|
159
|
+
ignoring_errors_when_forced do
|
160
|
+
@cloud.delete_vm(vm.cid)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
vm.destroy
|
165
|
+
end
|
166
|
+
|
167
|
+
def delete_dns(name)
|
168
|
+
if Config.dns_enabled?
|
169
|
+
record_pattern = ["%", canonical(name), dns_domain_name].join(".")
|
170
|
+
delete_dns_records(record_pattern)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def ignoring_errors_when_forced
|
175
|
+
yield
|
176
|
+
rescue => e
|
177
|
+
raise unless @force
|
178
|
+
logger.warn(e.backtrace.join("\n"))
|
179
|
+
logger.info("Force deleting is set, ignoring exception")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Jobs
|
3
|
+
class DeleteDeploymentSnapshots < BaseJob
|
4
|
+
@queue = :normal
|
5
|
+
|
6
|
+
attr_reader :deployment
|
7
|
+
|
8
|
+
def self.job_type
|
9
|
+
:delete_deployment_snapshots
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(deployment_name)
|
13
|
+
@deployment = deployment_manager.find_by_name(deployment_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def deployment_manager
|
17
|
+
@deployment_manager ||= Bosh::Director::Api::DeploymentManager.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform
|
21
|
+
logger.info("deleting snapshots of deployment: #{deployment.name}")
|
22
|
+
deployment.job_instances.each do |instance|
|
23
|
+
snapshots = instance.persistent_disks.map { |disk| disk.snapshots }.flatten
|
24
|
+
if snapshots.any?
|
25
|
+
logger.info("deleting snapshots of: #{instance.job}/#{instance.index} (#{instance.vm.cid})")
|
26
|
+
Bosh::Director::Api::SnapshotManager.delete_snapshots(snapshots)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
"snapshots of deployment `#{deployment.name}' deleted"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|