Class: Bosh::Cli::DeploymentManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/deployment_manifest.rb

Instance Method Summary collapse

Constructor Details

#initialize(manifest_hash) ⇒ DeploymentManifest

Returns a new instance of DeploymentManifest.



5
6
7
# File 'lib/cli/deployment_manifest.rb', line 5

def initialize(manifest_hash)
  @manifest_hash = manifest_hash
end

Instance Method Details

#normalizeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cli/deployment_manifest.rb', line 9

def normalize
  normalized = Bosh::Common::DeepCopy.copy(manifest_hash)

  # for backwards compatibility, new directors always convert stemcell and release versions to string
  if normalized['resource_pools']
    normalized['resource_pools'].each do |rp|
      rp['stemcell']['version'] = rp['stemcell']['version'].to_s
    end
  end

  if normalized['releases']
    normalized['releases'].each do |release|
      release['version'] = release['version'].to_s
    end
  end

  %w(releases networks jobs resource_pools disk_pools).each do |section|
    normalized[section] ||= []

    unless normalized[section].kind_of?(Array)
      manifest_error("#{section} is expected to be an array")
    end

    normalized[section] = normalized[section].inject({}) do |acc, e|
      if e["name"].blank?
        manifest_error("missing name for one of entries in '#{section}'")
      end
      if acc.has_key?(e["name"])
        manifest_error("duplicate entry '#{e['name']}' in '#{section}'")
      end
      acc[e["name"]] = e
      acc
    end
  end

  normalized["networks"].each do |network_name, network|
    # VIP and dynamic networks do not require subnet,
    # but if it's there we can run some sanity checks
    next unless network.has_key?("subnets")

    unless network["subnets"].kind_of?(Array)
      manifest_error("network subnets is expected to be an array")
    end

    subnets = network["subnets"].inject({}) do |acc, e|
      if e["range"].blank?
        manifest_error("missing range for one of subnets " +
                         "in '#{network_name}'")
      end
      if acc.has_key?(e["range"])
        manifest_error("duplicate network range '#{e['range']}' " +
                         "in '#{network}'")
      end
      acc[e["range"]] = e
      acc
    end

    normalized["networks"][network_name]["subnets"] = subnets
  end

  normalized
end