Class: Bosh::AwsCloud::AvailabilityZoneSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/aws/availability_zone_selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, default_name) ⇒ AvailabilityZoneSelector

Returns a new instance of AvailabilityZoneSelector.



5
6
7
8
# File 'lib/cloud/aws/availability_zone_selector.rb', line 5

def initialize(region, default_name)
  @region = region
  @default = default_name
end

Instance Attribute Details

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/cloud/aws/availability_zone_selector.rb', line 3

def region
  @region
end

Instance Method Details

#common_availability_zone(volume_az_names, resource_pool_az_name, vpc_subnet_az_name) ⇒ Object



10
11
12
13
14
15
# File 'lib/cloud/aws/availability_zone_selector.rb', line 10

def common_availability_zone(volume_az_names, resource_pool_az_name, vpc_subnet_az_name)
  zone_names = (volume_az_names + [resource_pool_az_name, vpc_subnet_az_name]).compact.uniq
  ensure_same_availability_zone(zone_names)

  zone_names.first || @default
end

#select_availability_zone(instance_id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cloud/aws/availability_zone_selector.rb', line 17

def select_availability_zone(instance_id)
  if instance_id
    region.instances[instance_id].availability_zone
  elsif @default
    @default
  else
    random_availability_zone
  end
end