Class: Bosh::AwsCloud::AvailabilityZoneSelector
- Inherits:
-
Object
- Object
- Bosh::AwsCloud::AvailabilityZoneSelector
- Defined in:
- lib/cloud/aws/availability_zone_selector.rb
Instance Attribute Summary collapse
-
#region ⇒ Object
Returns the value of attribute region.
Instance Method Summary collapse
- #common_availability_zone(volume_az_names, resource_pool_az_name, vpc_subnet_az_name) ⇒ Object
-
#initialize(region, default_name) ⇒ AvailabilityZoneSelector
constructor
A new instance of AvailabilityZoneSelector.
- #select_availability_zone(instance_id) ⇒ Object
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
#region ⇒ Object
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 16 17 18 |
# 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 if zone_names.size > 1 volume_az_error_string = ", and volume in #{volume_az_names.join(', ')}" unless volume_az_names.empty? raise Bosh::Clouds::CloudError, "can't use multiple availability zones: subnet in #{vpc_subnet_az_name}, VM in #{resource_pool_az_name}#{volume_az_error_string}" end zone_names.first || @default end |
#select_availability_zone(instance_id) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/cloud/aws/availability_zone_selector.rb', line 20 def select_availability_zone(instance_id) if instance_id region.instances[instance_id].availability_zone elsif @default @default else random_availability_zone end end |