Class: Bosh::Director::DeploymentPlan::JobAvailabilityZoneParser

Inherits:
Object
  • Object
show all
Includes:
ValidationHelper
Defined in:
lib/bosh/director/deployment_plan/job_availability_zone_parser.rb

Instance Method Summary collapse

Methods included from ValidationHelper

#safe_property

Instance Method Details

#check_contains(az_names, networks, job) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/bosh/director/deployment_plan/job_availability_zone_parser.rb', line 15

def check_contains(az_names, networks, job)
  networks.each do |network|
    unless network.has_azs?(az_names)
      raise JobNetworkMissingRequiredAvailabilityZone,
        "Instance group '#{job.name}' must specify availability zone that matches availability zones of network '#{network.name}'"
    end
  end
end

#check_validity_of(az_names, job_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bosh/director/deployment_plan/job_availability_zone_parser.rb', line 24

def check_validity_of(az_names, job_name)
  if az_names.empty?
    raise JobMissingAvailabilityZones, "Instance group '#{job_name}' has empty availability zones"
  end

  az_names.each do |name|
    unless name.is_a?(String)
      raise JobInvalidAvailabilityZone, "Instance group '#{job_name}' has invalid availability zone '#{name}', string expected"
    end
  end
end

#look_up_from_deployment(az_names, deployment, job_name) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/bosh/director/deployment_plan/job_availability_zone_parser.rb', line 36

def look_up_from_deployment(az_names, deployment, job_name)
  az_names.map do |name|
    az = deployment.availability_zone(name)
    if az.nil?
      raise JobUnknownAvailabilityZone, "Instance group '#{job_name}' references unknown availability zone '#{name}'"
    end
    az
  end
end

#parse(job_spec, job, deployment, networks) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/bosh/director/deployment_plan/job_availability_zone_parser.rb', line 6

def parse(job_spec, job, deployment, networks)
  az_names = safe_property(job_spec, 'azs', class: Array, optional: true)
  check_contains(az_names, networks, job)

  return nil if az_names.nil?
  check_validity_of(az_names, job.name)
  look_up_from_deployment(az_names, deployment, job.name)
end