bosh-director 1.3173.0 → 1.3177.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrations/director/20151229184742_add_vm_attributes_to_instance.rb +25 -0
- data/db/migrations/director/20160108191637_drop_vm_env_json_from_instance.rb +7 -0
- data/lib/bosh/director/api/controllers/base_controller.rb +1 -1
- data/lib/bosh/director/api/controllers/deployments_controller.rb +1 -1
- data/lib/bosh/director/api/deployment_manager.rb +10 -12
- data/lib/bosh/director/api/instance_manager.rb +5 -6
- data/lib/bosh/director/api/snapshot_manager.rb +1 -2
- data/lib/bosh/director/cloudcheck_helper.rb +30 -52
- data/lib/bosh/director/config.rb +2 -1
- data/lib/bosh/director/deployment_deleter.rb +0 -21
- data/lib/bosh/director/deployment_plan.rb +1 -1
- data/lib/bosh/director/deployment_plan/agent_state_migrator.rb +7 -19
- data/lib/bosh/director/deployment_plan/assembler.rb +6 -30
- data/lib/bosh/director/deployment_plan/compilation_instance_pool.rb +2 -4
- data/lib/bosh/director/deployment_plan/dynamic_network.rb +1 -1
- data/lib/bosh/director/deployment_plan/instance.rb +6 -46
- data/lib/bosh/director/deployment_plan/instance_network_reservations.rb +13 -13
- data/lib/bosh/director/deployment_plan/instance_plan.rb +3 -3
- data/lib/bosh/director/deployment_plan/instance_plan_factory.rb +12 -4
- data/lib/bosh/director/deployment_plan/instance_planner.rb +5 -4
- data/lib/bosh/director/deployment_plan/instance_repository.rb +7 -14
- data/lib/bosh/director/deployment_plan/instance_spec.rb +2 -2
- data/lib/bosh/director/deployment_plan/ip_provider/database_ip_repo.rb +7 -7
- data/lib/bosh/director/deployment_plan/ip_provider/in_memory_ip_repo.rb +6 -3
- data/lib/bosh/director/deployment_plan/ip_provider/ip_provider.rb +4 -4
- data/lib/bosh/director/deployment_plan/job.rb +0 -7
- data/lib/bosh/director/deployment_plan/job_migrator.rb +3 -2
- data/lib/bosh/director/deployment_plan/manual_network_subnet.rb +1 -1
- data/lib/bosh/director/deployment_plan/network_planner/planner.rb +2 -2
- data/lib/bosh/director/deployment_plan/network_reservation_repository.rb +20 -0
- data/lib/bosh/director/deployment_plan/placement_planner/static_ips_availability_zone_picker.rb +2 -1
- data/lib/bosh/director/deployment_plan/planner.rb +2 -17
- data/lib/bosh/director/deployment_plan/steps/package_compile_step.rb +1 -1
- data/lib/bosh/director/deployment_plan/steps/update_step.rb +1 -21
- data/lib/bosh/director/disk_manager.rb +8 -8
- data/lib/bosh/director/dns/dns_manager.rb +76 -20
- data/lib/bosh/director/errand/job_manager.rb +1 -1
- data/lib/bosh/director/instance_deleter.rb +1 -3
- data/lib/bosh/director/instance_updater.rb +4 -3
- data/lib/bosh/director/job_updater.rb +10 -2
- data/lib/bosh/director/jobs/base_job.rb +1 -1
- data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +3 -3
- data/lib/bosh/director/jobs/create_snapshot.rb +1 -1
- data/lib/bosh/director/jobs/delete_deployment.rb +1 -1
- data/lib/bosh/director/jobs/delete_deployment_snapshots.rb +1 -1
- data/lib/bosh/director/jobs/snapshot_deployment.rb +2 -2
- data/lib/bosh/director/jobs/vm_state.rb +16 -17
- data/lib/bosh/director/models.rb +0 -1
- data/lib/bosh/director/models/deployment.rb +0 -3
- data/lib/bosh/director/models/instance.rb +17 -10
- data/lib/bosh/director/network_reservation.rb +15 -16
- data/lib/bosh/director/problem_handlers/inactive_disk.rb +4 -6
- data/lib/bosh/director/problem_handlers/missing_disk.rb +3 -5
- data/lib/bosh/director/problem_handlers/missing_vm.rb +8 -10
- data/lib/bosh/director/problem_handlers/mount_info_mismatch.rb +8 -3
- data/lib/bosh/director/problem_handlers/unresponsive_agent.rb +14 -29
- data/lib/bosh/director/problem_scanner/disk_scan_stage.rb +1 -4
- data/lib/bosh/director/problem_scanner/problem_register.rb +2 -4
- data/lib/bosh/director/problem_scanner/scanner.rb +1 -1
- data/lib/bosh/director/problem_scanner/vm_scan_stage.rb +17 -35
- data/lib/bosh/director/stopper.rb +2 -2
- data/lib/bosh/director/version.rb +1 -1
- data/lib/bosh/director/vm_creator.rb +15 -33
- data/lib/bosh/director/vm_deleter.rb +6 -8
- data/lib/bosh/director/vm_metadata_updater.rb +5 -7
- data/lib/bosh/director/vm_recreator.rb +3 -2
- metadata +19 -18
- data/lib/bosh/director/deployment_plan/vm.rb +0 -22
- data/lib/bosh/director/models/vm.rb +0 -38
@@ -17,7 +17,7 @@ module Bosh::Director
|
|
17
17
|
configure_instance_plan(instance_plan)
|
18
18
|
@instance_reuser.add_in_use_instance(instance_plan.instance, stemcell)
|
19
19
|
else
|
20
|
-
@logger.info("Reusing compilation VM `#{instance.
|
20
|
+
@logger.info("Reusing compilation VM `#{instance.model.vm_cid}' for stemcell `#{stemcell.model.desc}'")
|
21
21
|
end
|
22
22
|
|
23
23
|
yield instance
|
@@ -80,7 +80,7 @@ module Bosh::Director
|
|
80
80
|
instance.bind_new_instance_model
|
81
81
|
|
82
82
|
compilation_network = @deployment_plan.network(@deployment_plan.compilation.network_name)
|
83
|
-
reservation = DesiredNetworkReservation.new_dynamic(instance, compilation_network)
|
83
|
+
reservation = DesiredNetworkReservation.new_dynamic(instance.model, compilation_network)
|
84
84
|
desired_instance = DeploymentPlan::DesiredInstance.new(@compile_job, nil)
|
85
85
|
instance_plan = DeploymentPlan::InstancePlan.new(
|
86
86
|
existing_instance: instance.model,
|
@@ -95,8 +95,6 @@ module Bosh::Director
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def configure_instance_plan(instance_plan)
|
98
|
-
instance_plan.instance.bind_unallocated_vm
|
99
|
-
|
100
98
|
@deployment_plan.ip_provider.reserve(instance_plan.network_plans.first.reservation)
|
101
99
|
@vm_creator.create_for_instance_plan(instance_plan, [])
|
102
100
|
end
|
@@ -8,7 +8,7 @@ module Bosh::Director
|
|
8
8
|
name = safe_property(network_spec, 'name', :class => String)
|
9
9
|
Canonicalizer.canonicalize(name)
|
10
10
|
logger = TaggedLogger.new(logger, 'network-configuration')
|
11
|
-
dns_manager =
|
11
|
+
dns_manager = DnsManagerProvider.create
|
12
12
|
|
13
13
|
validate_network_has_no_key('az', name, network_spec)
|
14
14
|
validate_network_has_no_key('azs', name, network_spec)
|
@@ -29,9 +29,6 @@ module Bosh::Director
|
|
29
29
|
|
30
30
|
attr_reader :availability_zone
|
31
31
|
|
32
|
-
# @return [DeploymentPlan::Vm] Associated resource pool VM
|
33
|
-
attr_reader :vm
|
34
|
-
|
35
32
|
attr_reader :existing_network_reservations
|
36
33
|
|
37
34
|
def self.create_from_job(job, index, virtual_state, deployment_model, instance_state, availability_zone, logger)
|
@@ -80,7 +77,7 @@ module Bosh::Director
|
|
80
77
|
|
81
78
|
# reservation generated from current state/DB
|
82
79
|
@existing_network_reservations = InstanceNetworkReservations.new(logger)
|
83
|
-
@dns_manager =
|
80
|
+
@dns_manager = DnsManagerProvider.create
|
84
81
|
|
85
82
|
@virtual_state = virtual_state
|
86
83
|
end
|
@@ -105,16 +102,6 @@ module Bosh::Director
|
|
105
102
|
end
|
106
103
|
end
|
107
104
|
|
108
|
-
# Looks up instance model in DB and binds it to this instance spec.
|
109
|
-
# Instance model is created if it's not found in DB. New VM is
|
110
|
-
# allocated if instance DB record doesn't reference one.
|
111
|
-
# @return [void]
|
112
|
-
# TODO: This should just be responsible to allocating the VMs and not creating instance_models
|
113
|
-
def bind_unallocated_vm
|
114
|
-
ensure_model_bound
|
115
|
-
ensure_vm_allocated
|
116
|
-
end
|
117
|
-
|
118
105
|
def ensure_model_bound
|
119
106
|
@model ||= find_or_create_model
|
120
107
|
end
|
@@ -132,13 +119,6 @@ module Bosh::Director
|
|
132
119
|
@uuid = @model.uuid
|
133
120
|
end
|
134
121
|
|
135
|
-
def ensure_vm_allocated
|
136
|
-
@uuid = @model.uuid
|
137
|
-
if @model.vm.nil?
|
138
|
-
allocate_vm
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
122
|
def vm_type
|
143
123
|
@vm_type
|
144
124
|
end
|
@@ -160,8 +140,6 @@ module Bosh::Director
|
|
160
140
|
@uuid = existing_instance_model.uuid
|
161
141
|
check_model_not_bound
|
162
142
|
@model = existing_instance_model
|
163
|
-
allocate_vm
|
164
|
-
@vm.model = existing_instance_model.vm
|
165
143
|
end
|
166
144
|
|
167
145
|
def bind_existing_reservations(reservations)
|
@@ -196,7 +174,7 @@ module Bosh::Director
|
|
196
174
|
|
197
175
|
def update_trusted_certs
|
198
176
|
agent_client.update_settings(Config.trusted_certs)
|
199
|
-
@model.
|
177
|
+
@model.update(:trusted_certs_sha1 => Digest::SHA1.hexdigest(Config.trusted_certs))
|
200
178
|
end
|
201
179
|
|
202
180
|
def update_cloud_properties!
|
@@ -204,7 +182,7 @@ module Bosh::Director
|
|
204
182
|
end
|
205
183
|
|
206
184
|
def agent_client
|
207
|
-
@agent_client ||= AgentClient.with_vm_credentials_and_agent_id(@model.
|
185
|
+
@agent_client ||= AgentClient.with_vm_credentials_and_agent_id(@model.credentials, @model.agent_id)
|
208
186
|
end
|
209
187
|
|
210
188
|
##
|
@@ -279,32 +257,14 @@ module Bosh::Director
|
|
279
257
|
#
|
280
258
|
# @return [Boolean] true if the VM needs to be sent a new set of trusted certificates
|
281
259
|
def trusted_certs_changed?
|
282
|
-
model_trusted_certs = @model.vm ? @model.vm.trusted_certs_sha1 : nil
|
283
260
|
config_trusted_certs = Digest::SHA1.hexdigest(Bosh::Director::Config.trusted_certs)
|
284
|
-
changed = config_trusted_certs !=
|
285
|
-
log_changes(__method__,
|
261
|
+
changed = config_trusted_certs != @model.trusted_certs_sha1
|
262
|
+
log_changes(__method__, @model.trusted_certs_sha1, config_trusted_certs) if changed
|
286
263
|
changed
|
287
264
|
end
|
288
265
|
|
289
266
|
def vm_created?
|
290
|
-
!@
|
291
|
-
end
|
292
|
-
|
293
|
-
def bind_to_vm_model(vm_model)
|
294
|
-
@model.update(vm: vm_model)
|
295
|
-
@vm.model = vm_model
|
296
|
-
@vm.bound_instance = self
|
297
|
-
end
|
298
|
-
|
299
|
-
# Allocates an VM in this job resource pool and binds current instance to that VM.
|
300
|
-
# @return [void]
|
301
|
-
def allocate_vm
|
302
|
-
vm = Vm.new
|
303
|
-
|
304
|
-
# VM is not created yet: let's just make it reference this instance
|
305
|
-
# so later it knows what it needs to become
|
306
|
-
vm.bound_instance = self
|
307
|
-
@vm = vm
|
267
|
+
!@model.vm_cid.nil?
|
308
268
|
end
|
309
269
|
|
310
270
|
def cloud_properties
|
@@ -4,32 +4,32 @@ module Bosh::Director
|
|
4
4
|
include Enumerable
|
5
5
|
include IpUtil
|
6
6
|
|
7
|
-
def self.create_from_state(
|
7
|
+
def self.create_from_state(instance_model, state, deployment, logger)
|
8
8
|
reservations = new(logger)
|
9
|
-
reservations.logger.debug("Creating instance network reservations from agent state for instance '#{
|
9
|
+
reservations.logger.debug("Creating instance network reservations from agent state for instance '#{instance_model}'")
|
10
10
|
|
11
11
|
state.fetch('networks', []).each do |network_name, network_config|
|
12
|
-
reservations.add_existing(
|
12
|
+
reservations.add_existing(instance_model, deployment, network_name, network_config['ip'], '', network_config['type'])
|
13
13
|
end
|
14
14
|
|
15
15
|
reservations
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.create_from_db(
|
18
|
+
def self.create_from_db(instance_model, deployment, logger)
|
19
19
|
reservations = new(logger)
|
20
|
-
reservations.logger.debug("Creating instance network reservations from database for instance '#{
|
20
|
+
reservations.logger.debug("Creating instance network reservations from database for instance '#{instance_model}'")
|
21
21
|
|
22
|
-
ip_addresses =
|
22
|
+
ip_addresses = instance_model.ip_addresses.clone
|
23
23
|
|
24
24
|
ip_addresses.each do |ip_address|
|
25
|
-
reservations.add_existing(
|
25
|
+
reservations.add_existing(instance_model, deployment, ip_address.network_name, ip_address.address, ip_address.type, 'manual')
|
26
26
|
end
|
27
27
|
|
28
|
-
unless
|
28
|
+
unless instance_model.spec.nil?
|
29
29
|
# Dynamic network reservations are not saved in DB, recreating from instance spec
|
30
|
-
|
30
|
+
instance_model.spec.fetch('networks', []).each do |network_name, network_config|
|
31
31
|
next unless network_config['type'] == 'dynamic'
|
32
|
-
reservations.add_existing(
|
32
|
+
reservations.add_existing(instance_model, deployment, network_name, network_config['ip'], '', network_config['type'])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -59,10 +59,10 @@ module Bosh::Director
|
|
59
59
|
@reservations.delete(reservation)
|
60
60
|
end
|
61
61
|
|
62
|
-
def add_existing(
|
62
|
+
def add_existing(instance_model, deployment, network_name, ip, ip_type, existing_network_type)
|
63
63
|
network = deployment.network(network_name) || deployment.deleted_network(network_name)
|
64
|
-
@logger.debug("Registering existing reservation with #{ip_type} IP '#{format_ip(ip)}' for instance '#{
|
65
|
-
reservation = ExistingNetworkReservation.new(
|
64
|
+
@logger.debug("Registering existing reservation with #{ip_type} IP '#{format_ip(ip)}' for instance '#{instance_model}' on network '#{network.name}'")
|
65
|
+
reservation = ExistingNetworkReservation.new(instance_model, network, ip, existing_network_type)
|
66
66
|
deployment.ip_provider.reserve_existing_ips(reservation)
|
67
67
|
@reservations << reservation
|
68
68
|
end
|
@@ -10,7 +10,7 @@ module Bosh
|
|
10
10
|
@skip_drain = attrs.fetch(:skip_drain, false)
|
11
11
|
@recreate_deployment = attrs.fetch(:recreate_deployment, false)
|
12
12
|
@logger = attrs.fetch(:logger, Config.logger)
|
13
|
-
@dns_manager =
|
13
|
+
@dns_manager = DnsManagerProvider.create
|
14
14
|
end
|
15
15
|
|
16
16
|
attr_reader :desired_instance, :existing_instance, :instance, :skip_drain, :recreate_deployment
|
@@ -260,8 +260,8 @@ module Bosh
|
|
260
260
|
def env_changed?
|
261
261
|
job = @desired_instance.job
|
262
262
|
|
263
|
-
if @existing_instance && @existing_instance.
|
264
|
-
log_changes(__method__, @existing_instance.
|
263
|
+
if @existing_instance && @existing_instance.vm_env && job.env.spec != @existing_instance.vm_env
|
264
|
+
log_changes(__method__, @existing_instance.vm_env, job.env.spec, @existing_instance)
|
265
265
|
return true
|
266
266
|
end
|
267
267
|
false
|
@@ -2,15 +2,18 @@ module Bosh
|
|
2
2
|
module Director
|
3
3
|
module DeploymentPlan
|
4
4
|
class InstancePlanFactory
|
5
|
-
def initialize(instance_repo, states_by_existing_instance, skip_drain_decider, index_assigner, options = {})
|
5
|
+
def initialize(instance_repo, states_by_existing_instance, skip_drain_decider, index_assigner, network_reservation_repository, options = {})
|
6
6
|
@instance_repo = instance_repo
|
7
7
|
@skip_drain_decider = skip_drain_decider
|
8
8
|
@recreate_deployment = options.fetch('recreate', false)
|
9
9
|
@states_by_existing_instance = states_by_existing_instance
|
10
10
|
@index_assigner = index_assigner
|
11
|
+
@network_reservation_repository = network_reservation_repository
|
11
12
|
end
|
12
13
|
|
13
14
|
def obsolete_instance_plan(existing_instance_model)
|
15
|
+
existing_instance_state = instance_state(existing_instance_model)
|
16
|
+
@network_reservation_repository.fetch_network_reservations(existing_instance_model, existing_instance_state)
|
14
17
|
InstancePlan.new(
|
15
18
|
desired_instance: nil,
|
16
19
|
existing_instance: existing_instance_model,
|
@@ -21,11 +24,10 @@ module Bosh
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def desired_existing_instance_plan(existing_instance_model, desired_instance)
|
24
|
-
existing_instance_state =
|
25
|
-
|
27
|
+
existing_instance_state = instance_state(existing_instance_model)
|
26
28
|
desired_instance.index = @index_assigner.assign_index(desired_instance.job.name, existing_instance_model)
|
27
29
|
|
28
|
-
instance = @instance_repo.fetch_existing(desired_instance,
|
30
|
+
instance = @instance_repo.fetch_existing(existing_instance_model, existing_instance_state, desired_instance.job, desired_instance.index, desired_instance.deployment)
|
29
31
|
instance.update_description
|
30
32
|
InstancePlan.new(
|
31
33
|
desired_instance: desired_instance,
|
@@ -48,6 +50,12 @@ module Bosh
|
|
48
50
|
recreate_deployment: @recreate_deployment
|
49
51
|
)
|
50
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def instance_state(existing_instance_model)
|
57
|
+
@states_by_existing_instance[existing_instance_model]
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -28,11 +28,12 @@ module Bosh
|
|
28
28
|
def plan_obsolete_jobs(desired_jobs, existing_instances)
|
29
29
|
desired_job_names = Set.new(desired_jobs.map(&:name))
|
30
30
|
migrating_job_names = Set.new(desired_jobs.map(&:migrated_from).flatten.map(&:name))
|
31
|
-
existing_instances.reject do |existing_instance_model|
|
31
|
+
obsolete_existing_instances = existing_instances.reject do |existing_instance_model|
|
32
32
|
desired_job_names.include?(existing_instance_model.job) ||
|
33
|
-
|
34
|
-
end
|
35
|
-
|
33
|
+
migrating_job_names.include?(existing_instance_model.job)
|
34
|
+
end
|
35
|
+
obsolete_existing_instances.map do |obsolete_existing_instance|
|
36
|
+
@instance_plan_factory.obsolete_instance_plan(obsolete_existing_instance)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -1,27 +1,20 @@
|
|
1
1
|
module Bosh::Director::DeploymentPlan
|
2
2
|
class InstanceRepository
|
3
|
-
def initialize(logger)
|
3
|
+
def initialize(network_reservation_repostory, logger)
|
4
|
+
@network_reservation_repository = network_reservation_repostory
|
4
5
|
@logger = logger
|
5
6
|
end
|
6
7
|
|
7
|
-
def fetch_existing(
|
8
|
+
def fetch_existing(existing_instance_model, existing_instance_state, job, index, deployment)
|
8
9
|
@logger.debug("Fetching existing instance for: #{existing_instance_model.inspect}")
|
9
10
|
# if state was not specified in manifest, use saved state
|
10
|
-
job_state =
|
11
|
-
@logger.debug("Job instance states: #{
|
11
|
+
job_state = job.state_for_instance(existing_instance_model) || existing_instance_model.state
|
12
|
+
@logger.debug("Job instance states: #{job.instance_states}, found: #{job.state_for_instance(existing_instance_model)}, state: #{job_state}")
|
12
13
|
|
13
|
-
instance = Instance.create_from_job(
|
14
|
+
instance = Instance.create_from_job(job, index, job_state, deployment.model, existing_instance_state, existing_instance_model.availability_zone, @logger)
|
14
15
|
instance.bind_existing_instance_model(existing_instance_model)
|
15
16
|
|
16
|
-
|
17
|
-
existing_network_reservations = InstanceNetworkReservations.create_from_db(instance, desired_instance.deployment, @logger)
|
18
|
-
elsif existing_instance_state
|
19
|
-
# This is for backwards compatibility when we did not store
|
20
|
-
# network reservations in DB and constructed them from instance state
|
21
|
-
existing_network_reservations = InstanceNetworkReservations.create_from_state(instance, existing_instance_state, desired_instance.deployment, @logger)
|
22
|
-
else
|
23
|
-
existing_network_reservations = InstanceNetworkReservations.new(@logger)
|
24
|
-
end
|
17
|
+
existing_network_reservations = @network_reservation_repository.fetch_network_reservations(existing_instance_model, existing_instance_state)
|
25
18
|
instance.bind_existing_reservations(existing_network_reservations)
|
26
19
|
instance
|
27
20
|
end
|
@@ -14,7 +14,7 @@ module Bosh::Director
|
|
14
14
|
deployment_name = instance.deployment_model.name
|
15
15
|
job = instance_plan.desired_instance.job
|
16
16
|
instance_plan = instance_plan
|
17
|
-
dns_manager =
|
17
|
+
dns_manager = DnsManagerProvider.create
|
18
18
|
|
19
19
|
spec = {
|
20
20
|
'deployment' => deployment_name,
|
@@ -95,7 +95,7 @@ module Bosh::Director
|
|
95
95
|
class TemplateSpec
|
96
96
|
def initialize(full_spec)
|
97
97
|
@full_spec = full_spec
|
98
|
-
@dns_manager =
|
98
|
+
@dns_manager = DnsManagerProvider.create
|
99
99
|
end
|
100
100
|
|
101
101
|
def spec
|
@@ -27,7 +27,7 @@ module Bosh::Director::DeploymentPlan
|
|
27
27
|
reservation_type = reservation.network.ip_type(cidr_ip)
|
28
28
|
|
29
29
|
reserve_with_instance_validation(
|
30
|
-
reservation.
|
30
|
+
reservation.instance_model,
|
31
31
|
cidr_ip,
|
32
32
|
reservation,
|
33
33
|
reservation_type.eql?(:static)
|
@@ -88,7 +88,7 @@ module Bosh::Director::DeploymentPlan
|
|
88
88
|
Bosh::Director::Models::IpAddress.select(:address).all.map { |a| a.address }
|
89
89
|
end
|
90
90
|
|
91
|
-
def reserve_with_instance_validation(
|
91
|
+
def reserve_with_instance_validation(instance_model, ip, reservation, is_static)
|
92
92
|
# try to save IP first before validating its instance to prevent race conditions
|
93
93
|
save_ip(ip, reservation, is_static)
|
94
94
|
rescue IpFoundInDatabaseAndCanBeRetried
|
@@ -96,12 +96,12 @@ module Bosh::Director::DeploymentPlan
|
|
96
96
|
|
97
97
|
retry unless ip_address
|
98
98
|
|
99
|
-
validate_instance_and_update_reservation_type(
|
99
|
+
validate_instance_and_update_reservation_type(instance_model, ip, ip_address, reservation.network.name, is_static)
|
100
100
|
end
|
101
101
|
|
102
|
-
def validate_instance_and_update_reservation_type(
|
102
|
+
def validate_instance_and_update_reservation_type(instance_model, ip, ip_address, network_name, is_static)
|
103
103
|
reserved_instance = ip_address.instance
|
104
|
-
if reserved_instance ==
|
104
|
+
if reserved_instance == instance_model
|
105
105
|
if ip_address.static != is_static || ip_address.network_name != network_name
|
106
106
|
reservation_type = is_static ? 'static' : 'dynamic'
|
107
107
|
@logger.debug("Updating reservation for ip '#{ip}' with type '#{reservation_type}' and network '#{network_name}'")
|
@@ -111,14 +111,14 @@ module Bosh::Director::DeploymentPlan
|
|
111
111
|
return ip_address
|
112
112
|
else
|
113
113
|
raise Bosh::Director::NetworkReservationAlreadyInUse,
|
114
|
-
"Failed to reserve IP '#{ip}' for instance '#{
|
114
|
+
"Failed to reserve IP '#{ip}' for instance '#{instance_model}': " +
|
115
115
|
"already reserved by instance '#{reserved_instance.job}/#{reserved_instance.index}' " +
|
116
116
|
"from deployment '#{reserved_instance.deployment.name}'"
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
def save_ip(ip, reservation, is_static)
|
121
|
-
reservation.
|
121
|
+
reservation.instance_model.add_ip_address(
|
122
122
|
address: ip.to_i,
|
123
123
|
network_name: reservation.network.name,
|
124
124
|
task_id: Bosh::Director::Config.current_job.task_id,
|
@@ -48,12 +48,14 @@ module Bosh::Director::DeploymentPlan
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def contains_ip?(ip, network_name)
|
52
|
+
@ips.include?({ip: ip.to_i, network_name: network_name})
|
53
|
+
end
|
54
|
+
|
51
55
|
private
|
52
56
|
|
53
57
|
def add_ip(ip, network_name)
|
54
|
-
|
55
|
-
|
56
|
-
if @ips.include?(entry_to_add)
|
58
|
+
if contains_ip?(ip, network_name)
|
57
59
|
message = "Failed to reserve IP '#{ip.ip}' for '#{network_name}': already reserved"
|
58
60
|
@logger.error(message)
|
59
61
|
raise Bosh::Director::NetworkReservationAlreadyInUse, message
|
@@ -61,6 +63,7 @@ module Bosh::Director::DeploymentPlan
|
|
61
63
|
|
62
64
|
@logger.debug("Reserving ip '#{ip.ip}' for #{network_name}")
|
63
65
|
|
66
|
+
entry_to_add = {ip: ip.to_i, network_name: network_name}
|
64
67
|
@ips << entry_to_add
|
65
68
|
@recently_released_ips.delete(entry_to_add)
|
66
69
|
end
|
@@ -51,7 +51,7 @@ module Bosh::Director
|
|
51
51
|
end
|
52
52
|
|
53
53
|
raise NetworkReservationNotEnoughCapacity,
|
54
|
-
"Failed to reserve IP for '#{reservation.
|
54
|
+
"Failed to reserve IP for '#{reservation.instance_model}' for manual network '#{reservation.network.name}': no more available"
|
55
55
|
|
56
56
|
else
|
57
57
|
|
@@ -130,12 +130,12 @@ module Bosh::Director
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def filter_subnet_by_instance_az(reservation)
|
133
|
-
|
134
|
-
if
|
133
|
+
instance_az_name = reservation.instance_model.availability_zone
|
134
|
+
if instance_az_name.nil?
|
135
135
|
reservation.network.subnets
|
136
136
|
else
|
137
137
|
reservation.network.subnets.select do |subnet|
|
138
|
-
subnet.availability_zone_names.include?(
|
138
|
+
subnet.availability_zone_names.include?(instance_az_name)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -256,15 +256,8 @@ module Bosh::Director
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
-
def bind_unallocated_vms
|
260
|
-
instances.each do |instance|
|
261
|
-
instance.ensure_vm_allocated
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
259
|
def bind_instances(ip_provider)
|
266
260
|
instances.each(&:ensure_model_bound)
|
267
|
-
bind_unallocated_vms
|
268
261
|
bind_instance_networks(ip_provider)
|
269
262
|
end
|
270
263
|
|