Class: Bosh::Director::DeploymentPlan::Template
- Includes:
- ValidationHelper, Template::PropertyHelper
- Defined in:
- lib/bosh/director/deployment_plan/template.rb
Instance Attribute Summary collapse
-
#link_infos ⇒ Object
readonly
Returns the value of attribute link_infos.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package_models ⇒ Object
readonly
Returns the value of attribute package_models.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#template_scoped_properties ⇒ Object
readonly
Returns the value of attribute template_scoped_properties.
Instance Method Summary collapse
- #add_link_from_manifest(job_name, kind, link_name, source) ⇒ Object
- #add_link_from_release(job_name, kind, link_name, source) ⇒ Object
- #add_template_scoped_properties(template_scoped_properties, deployment_job_name) ⇒ Object
- #bind_existing_model(model) ⇒ Object
-
#bind_models ⇒ void
Looks up template model and its package models in DB.
- #bind_template_scoped_properties(deployment_job_name) ⇒ Object
- #blobstore_id ⇒ String
-
#consumed_links(job_name) ⇒ Object
return [Array].
- #consumes_link_info(job_name, link_name) ⇒ Object
-
#download_blob ⇒ String
Downloads template blob to a given path.
- #has_template_scoped_properties(deployment_job_name) ⇒ Object
-
#initialize(release, name) ⇒ Template
constructor
A new instance of Template.
- #logs ⇒ Array
-
#model_consumed_links ⇒ Object
return [Array].
-
#model_provided_links ⇒ Object
return [Array].
- #properties ⇒ Hash
-
#provided_links(job_name) ⇒ Object
return [Array].
- #provides_link_info(job_name, link_name) ⇒ Object
- #sha1 ⇒ String
- #version ⇒ String
Methods included from ValidationHelper
Constructor Details
#initialize(release, name) ⇒ Template
Returns a new instance of Template.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#link_infos ⇒ Object (readonly)
Returns the value of attribute link_infos.
15 16 17 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 15 def link_infos @link_infos end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
12 13 14 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 12 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 9 def name @name end |
#package_models ⇒ Object (readonly)
Returns the value of attribute package_models.
13 14 15 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 13 def package_models @package_models end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
10 11 12 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 10 def release @release end |
#template_scoped_properties ⇒ Object (readonly)
Returns the value of attribute template_scoped_properties.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 16 def template_scoped_properties @template_scoped_properties end |
Instance Method Details
#add_link_from_manifest(job_name, kind, link_name, source) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 147 def add_link_from_manifest(job_name, kind, link_name, source) @link_infos[job_name] ||= {} @link_infos[job_name][kind] ||= {} @link_infos[job_name][kind][link_name] ||= {} if source.eql? 'nil' # This is the case where the user set link source to nil explicitly in the deployment manifest # We should skip the binding of this link, even if it exist. This is used only when the link # is optional @link_infos[job_name][kind][link_name]['skip_link'] = true else errors = [] if kind == "consumes" errors = validate_consume_link(source, link_name, job_name) elsif kind == "provides" errors.concat(validate_provide_link(link_name, job_name)) end errors.concat(validate_link_def(source, link_name, job_name)) if errors.size > 0 raise errors.join("\n") end source_hash = source.to_a source_hash.each do |key, value| @link_infos[job_name][kind][link_name][key] = value end end end |
#add_link_from_release(job_name, kind, link_name, source) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 127 def add_link_from_release(job_name, kind, link_name, source) @link_infos[job_name] ||= {} @link_infos[job_name][kind] ||= {} @link_infos[job_name][kind][link_name] ||= {} if source.eql? 'nil' # This is the case where the user set link source to nil explicitly in the deployment manifest # We should skip the binding of this link, even if it exist. This is used only when the link # is optional @link_infos[job_name][kind][link_name]['skip_link'] = true else source.to_a.each do |key, value| if key == "properties" key = "link_properties_exported" end @link_infos[job_name][kind][link_name][key] = value end end end |
#add_template_scoped_properties(template_scoped_properties, deployment_job_name) ⇒ Object
190 191 192 |
# 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) ⇒ Object
51 52 53 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 51 def bind_existing_model(model) @model = model end |
#bind_models ⇒ void
This method returns an undefined value.
Looks up template model and its package models in DB
39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# 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 ⇒ String
85 86 87 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 85 def blobstore_id present_model.blobstore_id end |
#consumed_links(job_name) ⇒ Object
return [Array]
110 111 112 113 114 115 116 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 110 def consumed_links(job_name) if @link_infos[job_name] != nil && @link_infos[job_name]["consumes"] != nil @link_infos[job_name]["consumes"].map { |_, link_info| TemplateLink.parse("consumes", link_info) } else return [] end end |
#consumes_link_info(job_name, link_name) ⇒ Object
177 178 179 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 177 def consumes_link_info(job_name, link_name) @link_infos.fetch(job_name, {}).fetch('consumes', {}).fetch(link_name, {}) end |
#download_blob ⇒ String
Downloads template blob to a given path
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
194 195 196 |
# 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 ⇒ Array
90 91 92 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 90 def logs present_model.logs end |
#model_consumed_links ⇒ Object
return [Array]
100 101 102 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 100 def model_consumed_links present_model.consumes.to_a.map { |l| TemplateLink.parse("consumes", l) } end |
#model_provided_links ⇒ Object
return [Array]
105 106 107 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 105 def model_provided_links present_model.provides.to_a.map { |l| TemplateLink.parse('provides', l) } end |
#properties ⇒ Hash
95 96 97 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 95 def properties present_model.properties end |
#provided_links(job_name) ⇒ Object
return [Array]
119 120 121 122 123 124 125 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 119 def provided_links(job_name) if @link_infos[job_name] != nil && @link_infos[job_name]["provides"] != nil @link_infos[job_name]["provides"].map { |_, link_info| TemplateLink.parse("provides", link_info) } else return [] end end |
#provides_link_info(job_name, link_name) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 181 def provides_link_info(job_name, link_name) @link_infos.fetch(job_name, {}).fetch('provides', {}).each do |index, link| if link['as'] == link_name return link end end return @link_infos.fetch(job_name, {}).fetch('provides', {}).fetch(link_name, {}) end |
#sha1 ⇒ String
80 81 82 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 80 def sha1 present_model.sha1 end |
#version ⇒ String
75 76 77 |
# File 'lib/bosh/director/deployment_plan/template.rb', line 75 def version present_model.version end |