class Bosh::Director::DeploymentPlan::Template

Attributes

model[R]
name[R]
package_models[R]
release[R]
template_scoped_properties[R]

Public Class Methods

new(release, name) click to toggle source

@param [DeploymentPlan::ReleaseVersion] release Release version @param [String] name Template name

# File lib/bosh/director/deployment_plan/template.rb, line 20
def initialize(release, name)
  @release = release
  @name = name
  @model = nil
  @package_models = []
  @logger = Config.logger
  @link_infos = {}

  # This hash will contain the properties specific to this template,
  # it will be a hash where the keys are the deployment job name, and
  # the value of each key will be the properties defined in template
  # section of the deployment manifest. This way if a template is used
  # in multiple deployment jobs, the properties will not be shared across
  # jobs
  @template_scoped_properties = {}
end

Public Instance Methods

add_template_scoped_properties(template_scoped_properties, deployment_job_name) click to toggle source
# File lib/bosh/director/deployment_plan/template.rb, line 190
def add_template_scoped_properties(template_scoped_properties, deployment_job_name)
  @template_scoped_properties[deployment_job_name] = template_scoped_properties
end
bind_existing_model(model) click to toggle source
# File lib/bosh/director/deployment_plan/template.rb, line 51
def bind_existing_model(model)
  @model = model
end
bind_models() click to toggle source

Looks up template model and its package models in DB @return [void]

# File lib/bosh/director/deployment_plan/template.rb, line 39
def bind_models
  @model = @release.get_template_model_by_name(@name)

  if @model.nil?
    raise DeploymentUnknownTemplate, "Can't find job '#{@name}'"
  end

  @package_models = @model.package_names.map do |name|
    @release.get_package_model_by_name(name)
  end
end
bind_template_scoped_properties(deployment_job_name) click to toggle source
# File lib/bosh/director/deployment_plan/template.rb, line 198
def bind_template_scoped_properties(deployment_job_name)
  bound_template_scoped_properties = {}
  properties.each_pair do |name, definition|
    copy_property(
        bound_template_scoped_properties,
        @template_scoped_properties[deployment_job_name],
        name,
        definition["default"]
    )
  end
  @template_scoped_properties[deployment_job_name] = bound_template_scoped_properties
end
blobstore_id() click to toggle source

@return [String]

# File lib/bosh/director/deployment_plan/template.rb, line 85
def blobstore_id
  present_model.blobstore_id
end
download_blob() click to toggle source

Downloads template blob to a given path @return [String] Path to downloaded blob

# File lib/bosh/director/deployment_plan/template.rb, line 57
def download_blob
  uuid = SecureRandom.uuid
  path = File.join(Dir.tmpdir, "template-#{uuid}")

  @logger.debug("Downloading job '#{@name}' (#{blobstore_id})...")
  t1 = Time.now

  File.open(path, "w") do |f|
    App.instance.blobstores.blobstore.get(blobstore_id, f)
  end

  @logger.debug("Job '#{@name}' downloaded to #{path} " +
                "(took #{Time.now - t1}s)")

  path
end
has_template_scoped_properties(deployment_job_name) click to toggle source
# File lib/bosh/director/deployment_plan/template.rb, line 194
def has_template_scoped_properties(deployment_job_name)
  return !@template_scoped_properties[deployment_job_name].nil?
end
logs() click to toggle source

@return [Array]

# File lib/bosh/director/deployment_plan/template.rb, line 90
def logs
  present_model.logs
end
properties() click to toggle source

@return [Hash]

# File lib/bosh/director/deployment_plan/template.rb, line 95
def properties
  present_model.properties
end
sha1() click to toggle source

@return [String]

# File lib/bosh/director/deployment_plan/template.rb, line 80
def sha1
  present_model.sha1
end
version() click to toggle source

@return [String]

# File lib/bosh/director/deployment_plan/template.rb, line 75
def version
  present_model.version
end

Private Instance Methods

present_model() click to toggle source

Returns model only if it's present, fails otherwise @return [Models::Template]

# File lib/bosh/director/deployment_plan/template.rb, line 255
def present_model
  if @model.nil?
    raise DirectorError, "Job '#{@name}' model is unbound"
  end
  @model
end