Class: Bosh::Director::DeploymentPlan::NetworkPlanner::ReservationReconciler
- Inherits:
-
Object
- Object
- Bosh::Director::DeploymentPlan::NetworkPlanner::ReservationReconciler
- Defined in:
- lib/bosh/director/deployment_plan/network_planner/reservation_reconciler.rb
Instance Method Summary collapse
-
#initialize(instance_plan, logger) ⇒ ReservationReconciler
constructor
A new instance of ReservationReconciler.
- #reconcile(existing_reservations) ⇒ Object
Constructor Details
#initialize(instance_plan, logger) ⇒ ReservationReconciler
Returns a new instance of ReservationReconciler.
4 5 6 7 |
# File 'lib/bosh/director/deployment_plan/network_planner/reservation_reconciler.rb', line 4 def initialize(instance_plan, logger) @instance_plan = instance_plan @logger = logger end |
Instance Method Details
#reconcile(existing_reservations) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bosh/director/deployment_plan/network_planner/reservation_reconciler.rb', line 9 def reconcile(existing_reservations) unplaced_existing_reservations = Set.new(existing_reservations) existing_network_plans = [] desired_reservations = @instance_plan.network_plans.map{ |np| np.reservation } desired_network_plans = desired_reservations.map do |reservation| Plan.new(reservation: reservation) end existing_reservations.each do |existing_reservation| unless az_is_desired(existing_reservation) @logger.debug("Can't reuse reservation #{existing_reservation}, existing reservation az does not match desired az '#{@instance_plan.desired_instance.availability_zone}'") next end desired_reservation = desired_reservations.find do |reservation| reservation.network == existing_reservation.network && (reservation.dynamic? || reservation.ip == existing_reservation.ip) end if desired_reservation && existing_reservation.reserved? @logger.debug("For desired reservation #{desired_reservation} found existing reservation on the same network #{existing_reservation}") if both_are_dynamic_reservations(existing_reservation, desired_reservation) || both_are_static_reservations_with_same_ip(existing_reservation, desired_reservation) @logger.debug("Reusing existing reservation #{existing_reservation} for '#{desired_reservation}'") existing_network_plans << Plan.new(reservation: existing_reservation, existing: true) unplaced_existing_reservations.delete(existing_reservation) desired_network_plans.delete_if { |plan| plan.reservation == desired_reservation } else @logger.debug("Can't reuse reservation #{existing_reservation} for #{desired_reservation}") end else @logger.debug("Unneeded reservation #{existing_reservation}") end end obsolete_network_plans = unplaced_existing_reservations.map do |reservation| Plan.new(reservation: reservation, obsolete: true) end existing_network_plans + desired_network_plans + obsolete_network_plans end |