Chapter 09/circuit-oneops-1-master/components/cookbooks/lb/providers/load_balancer.rb
# TODO: error handling
# TODO: count instances in each zone and warn if not equal
# TODO: warn if only one availability zone
error handling
TODO: count instances in each zone and warn if not equal
TODO: warn if only one availability zone
error handling TODO : count instances in each zone and warn if not equal TODO : warn if only one availability zone
def load_current_resource
  @current_lb = load_balancer_by_name(new_resource.lb_name)
  @current_resource = Chef::Resource::LbLoadBalancer.new(new_resource.lb_name)
  @current_resource.lb_name(new_resource.lb_name)
  @current_resource.aws_access_key(new_resource.aws_access_key)
  @current_resource.aws_secret_access_key(new_resource.aws_secret_access_key)
  @current_resource.region(new_resource.region)
  @current_resource.listeners(new_resource.listeners)
  @current_resource.timeout(new_resource.timeout)
  if @current_lb
    @current_resource.availability_zones(@current_lb['AvailabilityZones'])
    @current_resource.instances(@current_lb['Instances'])
  end
  @current_resource.availability_zones || @current_resource.availability_zones([])
  @current_resource.instances || @current_resource.instances([])
  if new_resource.instances.nil? && new_resource.search_query
    new_resource.instances(search(:node, new_resource.search_query).map { |n| n['ec2']['instance_id']})
  end
  all_zones = availability_zone_for_instances(new_resource.instances)
  unique_zones = all_zones.compact.uniq
  if new_resource.availability_zones.nil?
    new_resource.availability_zones(unique_zones)
  end
end
def load_current_resource @current_lb = load_balancer_by_name ( new_resource . lb_name ) @current_resource = Chef :: Resource :: LbLoadBalancer . new ( new_resource . lb_name ) @current_resource . lb_name ( new_resource . lb_name ) @current_resource . aws_access_key ( new_resource . aws_access_key ) @current_resource . aws_secret_access_key ( new_resource . aws_secret_access_key ) @current_resource . region ( new_resource . region ) @current_resource . listeners ( new_resource . listeners ) @current_resource . timeout ( new_resource . timeout ) if @current_lb @current_resource . availability_zones ( @current_lb [ 'AvailabilityZones' ] ) @current_resource . instances ( @current_lb [ 'Instances' ] ) end @current_resource . availability_zones || @current_resource . availability_zones ( [ ] ) @current_resource . instances || @current_resource . instances ( [ ] ) if new_resource . instances . nil? && new_resource . search_query new_resource . instances ( search ( :node , new_resource . search_query ) . map { | n | n [ 'ec2' ] [ 'instance_id' ] } ) end all_zones = availability_zone_for_instances ( new_resource . instances ) unique_zones = all_zones . compact . uniq if new_resource . availability_zones . nil? new_resource . availability_zones ( unique_zones ) end end
TODO: error handling
TODO: count instances in each zone and warn if not equal
TODO: warn if only one availability zone
TODO : error handling TODO : count instances in each zone and warn if not equal TODO : warn if only one availability zone