Class: Bosh::Director::DeploymentPlan::PlacementPlanner::PlacedDesiredInstances

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(azs) ⇒ PlacedDesiredInstances

Returns a new instance of PlacedDesiredInstances.



8
9
10
11
12
13
14
15
16
# File 'lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb', line 8

def initialize(azs)
  @placed = {}
  (azs || []).each do |az|
    @placed[az] = []
  end

  @absent = []
  @existing = []
end

Instance Attribute Details

#absentObject (readonly)

Returns the value of attribute absent.



6
7
8
# File 'lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb', line 6

def absent
  @absent
end

#existingObject (readonly)

Returns the value of attribute existing.



6
7
8
# File 'lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb', line 6

def existing
  @existing
end

Instance Method Details

#azs_with_fewest_instancesObject



32
33
34
35
# File 'lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb', line 32

def azs_with_fewest_instances
  az_with_fewest = @placed.keys.min_by { |az|@placed[az].size }
  @placed.keys.select { |az| (@placed[az].size == @placed[az_with_fewest].size) && az }
end

#record_placement(az, desired_instance, existing_instance_model) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bosh/director/deployment_plan/placement_planner/placed_desired_instances.rb', line 18

def record_placement(az, desired_instance, existing_instance_model)
  desired_instance.az = az
  @placed[az] = @placed.fetch(az, []) << desired_instance

  if existing_instance_model
    existing << {
      desired_instance: desired_instance,
      existing_instance_model: existing_instance_model
    }
  else
    absent << desired_instance
  end
end