class Bosh::Director::Manifest

Attributes

cloud_config_hash[R]
manifest_hash[R]
runtime_config_hash[R]

Public Class Methods

load_from_hash(manifest_hash, cloud_config, runtime_config) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 10
def self.load_from_hash(manifest_hash, cloud_config, runtime_config)
  cloud_config_hash =  cloud_config.nil? ? nil : cloud_config.manifest
  runtime_config_hash = runtime_config.nil? ? nil : runtime_config.manifest
  manifest_hash = manifest_hash.nil? ? {} : manifest_hash
  new(manifest_hash, cloud_config_hash, runtime_config_hash)
end
load_from_text(manifest_text, cloud_config, runtime_config) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 5
def self.load_from_text(manifest_text, cloud_config, runtime_config)
  manifest_text ||= '{}'
  self.load_from_hash(YAML.load(manifest_text), cloud_config, runtime_config)
end
new(manifest_hash, cloud_config_hash, runtime_config_hash) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 19
def initialize(manifest_hash, cloud_config_hash, runtime_config_hash)
  @manifest_hash = manifest_hash
  @cloud_config_hash = cloud_config_hash
  @runtime_config_hash = runtime_config_hash
end

Public Instance Methods

diff(other_manifest, redact) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 40
def diff(other_manifest, redact)
  Changeset.new(to_hash, other_manifest.to_hash).diff(redact).order
end
resolve_aliases() click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 25
def resolve_aliases
  hashed = to_hash
  hashed['resource_pools'].to_a.each do |rp|
    rp['stemcell']['version'] = resolve_stemcell_version(rp['stemcell'])
  end

  hashed['stemcells'].to_a.each do |stemcell|
    stemcell['version'] = resolve_stemcell_version(stemcell)
  end

  hashed['releases'].to_a.each do |release|
    release['version'] = resolve_release_version(release)
  end
end
to_hash() click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 44
def to_hash
  hash = @manifest_hash.merge(@cloud_config_hash || {})
  hash.merge(@runtime_config_hash || {}) do |key, old, new|
    if key == 'releases'
      if old && new
        old.to_set.merge(new.to_set).to_a
      else
        old.nil? ? new : old
      end
    else
      new
    end
  end
end

Private Instance Methods

match_resolvable_version(version) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 95
def match_resolvable_version(version)
  /(^|(?<prefix>.+)\.)latest$/.match(version.to_s)
end
resolve_release_version(release_def) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 84
def resolve_release_version(release_def)
  release_manager = Api::ReleaseManager.new
  resolvable_version = match_resolvable_version(release_def['version'])
  if resolvable_version
    release = release_manager.find_by_name(release_def['name'])
    return release_manager.sorted_release_versions(release, resolvable_version[:prefix]).last['version']
  end

  release_def['version'].to_s
end
resolve_stemcell_version(stemcell) click to toggle source
# File lib/bosh/director/manifest/manifest.rb, line 61
def resolve_stemcell_version(stemcell)
  stemcell_manager = Api::StemcellManager.new

  unless stemcell.is_a?(Hash)
    raise 'Invalid stemcell spec in the deployment manifest'
  end

  resolvable_version = match_resolvable_version(stemcell['version'])

  if resolvable_version
    if stemcell['os']
      latest_stemcell = stemcell_manager.latest_by_os(stemcell['os'], resolvable_version[:prefix])
    elsif stemcell['name']
      latest_stemcell = stemcell_manager.latest_by_name(stemcell['name'], resolvable_version[:prefix])
    else
      raise 'Stemcell definition must contain either name or os'
    end
    return latest_stemcell[:version].to_s
  end

  stemcell['version'].to_s
end