Class: Bosh::Director::DeploymentPlan::PlacementPlanner::UnplacedExistingInstances

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

Instance Method Summary collapse

Constructor Details

#initialize(existing_instance_models) ⇒ UnplacedExistingInstances

Returns a new instance of UnplacedExistingInstances.



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

def initialize(existing_instance_models)
  @instances = existing_instance_models.sort_by { |instance_model| instance_model.index }
  @az_name_to_existing_instances  = initialize_azs_to_instances
end

Instance Method Details

#azs_sorted_by_existing_instance_count_descending(azs) ⇒ Object



21
22
23
24
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 21

def azs_sorted_by_existing_instance_count_descending(azs)
  return nil if azs.nil?
  azs.sort_by { |az| - @az_name_to_existing_instances.fetch(az.name, []).size }
end

#claim_instance(existing_instance) ⇒ Object



26
27
28
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 26

def claim_instance(existing_instance)
  @az_name_to_existing_instances[existing_instance.availability_zone].delete(existing_instance)
end

#claim_instance_for_az(az) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 30

def claim_instance_for_az(az)
  az_name = az.nil? ? nil : az.name
  instances = @az_name_to_existing_instances[az_name]
  unless instances.nil? || instances.empty?
    instances.shift
  end
end

#ignored_instancesObject



17
18
19
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 17

def ignored_instances
  @instances.select(&:ignore)
end

#instances_with_persistent_diskObject



11
12
13
14
15
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 11

def instances_with_persistent_disk
  @instances.select do |instance_model|
    instance_model.persistent_disks && instance_model.persistent_disks.count > 0
  end
end

#unclaimedObject



38
39
40
# File 'lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb', line 38

def unclaimed
  @az_name_to_existing_instances.values.flatten
end