Class: Bosh::Deployer::JobTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/deployer/job_template.rb

Defined Under Namespace

Classes: FetchError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_spec, blobstore) ⇒ JobTemplate

Returns a new instance of JobTemplate.



12
13
14
15
16
17
18
# File 'lib/bosh/deployer/job_template.rb', line 12

def initialize(template_spec, blobstore)
  @name = template_spec.fetch('name')
  @version = template_spec.fetch('version')
  @sha1 = template_spec.fetch('sha1')
  @blobstore_id = template_spec.fetch('blobstore_id')
  @blobstore = blobstore
end

Instance Attribute Details

#blobstore_idObject (readonly)

Returns the value of attribute blobstore_id.



10
11
12
# File 'lib/bosh/deployer/job_template.rb', line 10

def blobstore_id
  @blobstore_id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/bosh/deployer/job_template.rb', line 10

def name
  @name
end

#sha1Object (readonly)

Returns the value of attribute sha1.



10
11
12
# File 'lib/bosh/deployer/job_template.rb', line 10

def sha1
  @sha1
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/bosh/deployer/job_template.rb', line 10

def version
  @version
end

Instance Method Details

#download_blobObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bosh/deployer/job_template.rb', line 20

def download_blob
  uuid = SecureRandom.uuid
  path = File.join(Dir.tmpdir, "template-#{uuid}")
  File.open(path, 'w') do |f|
    blobstore.get(blobstore_id, f)
  end
  path
rescue Bosh::Blobstore::BlobstoreError => e
  if e.message.include?('Could not fetch object')
    raise FetchError.new
  else
    raise e
  end
end