class Bosh::Director::DeploymentPlan::PlacementPlanner::UnplacedExistingInstances

Public Class Methods

new(existing_instance_models) click to toggle source
# 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

Public Instance Methods

azs_sorted_by_existing_instance_count_descending(azs) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_instances() click to toggle source
# File lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb, line 17
def ignored_instances
  @instances.select(&:ignore)
end
instances_with_persistent_disk() click to toggle source
# 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
unclaimed() click to toggle source
# File lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb, line 38
def unclaimed
  @az_name_to_existing_instances.values.flatten
end

Private Instance Methods

initialize_azs_to_instances() click to toggle source
# File lib/bosh/director/deployment_plan/placement_planner/unplaced_existing_instances.rb, line 44
def initialize_azs_to_instances
  az_name_to_existing_instances = {}
  @instances.each do |instance|
    instances = az_name_to_existing_instances.fetch(instance.availability_zone, [])
    instances << instance
    az_name_to_existing_instances[instance.availability_zone] = instances
  end
  az_name_to_existing_instances
end