Class: Vara::Metadata::Stemcell

Inherits:
Object
  • Object
show all
Defined in:
lib/vara/metadata/stemcell.rb

Overview

Note:

Unlike Vara::ReleaseMetadata and Vara::CompiledPackagesMetadata, this class does not have a settable URL because there is an inferred URL from the global BOSH stemcell blobstore.

“Struct” representing the information about the stemcell field in metadata.yml

Examples:

entry from metadata.yml

stemcell:
  name: bosh-vsphere-esxi-ubuntu
  version: '2366'
  file: bosh-stemcell-2366-vsphere-esxi-ubuntu.tgz
  md5: 0fbdcd100f716d127f821b1b4335135a

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version:, file:, md5:, sha1:) ⇒ Stemcell

Returns a new instance of Stemcell.

Parameters:

  • name (String)
  • version (String)
  • file (String)
  • md5 (String)


50
51
52
53
54
55
56
# File 'lib/vara/metadata/stemcell.rb', line 50

def initialize(name:, version:, file:, md5:, sha1:)
  @name     = name
  @version  = version
  @basename = file
  @md5      = md5
  @sha1     = sha1
end

Instance Attribute Details

#basenameString (readonly)

Returns the filename of the stemcell.

Returns:

  • (String)

    the filename of the stemcell



20
21
22
# File 'lib/vara/metadata/stemcell.rb', line 20

def basename
  @basename
end

#md5String (readonly)

Returns md5 checksum of the stemcell.

Returns:

  • (String)

    md5 checksum of the stemcell



23
24
25
# File 'lib/vara/metadata/stemcell.rb', line 23

def md5
  @md5
end

#nameString (readonly)

Returns the name of the stemcell.

Returns:

  • (String)

    the name of the stemcell.



14
15
16
# File 'lib/vara/metadata/stemcell.rb', line 14

def name
  @name
end

#sha1String (readonly)

Returns sha1 checksum of the stemcell.

Returns:

  • (String)

    sha1 checksum of the stemcell



26
27
28
# File 'lib/vara/metadata/stemcell.rb', line 26

def sha1
  @sha1
end

#versionString (readonly)

Returns the version of the stemcell.

Returns:

  • (String)

    the version of the stemcell.



17
18
19
# File 'lib/vara/metadata/stemcell.rb', line 17

def version
  @version
end

Class Method Details

.from_file(path_to_stemcell) ⇒ Vara::StemcellMetadata

Infers the metadata given a stemcell file on disk

Parameters:

  • path_to_stemcell (String)

    The path to the stemcell file on disk

Returns:

  • (Vara::StemcellMetadata)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vara/metadata/stemcell.rb', line 31

def self.from_file(path_to_stemcell)
  md5      = Digest::MD5.file(path_to_stemcell).hexdigest
  sha1     = Digest::SHA1.file(path_to_stemcell).hexdigest
  basename = File.basename(path_to_stemcell)

  stemcell_parts = basename.gsub(/^bosh-stemcell-/, '').gsub(/\.tgz$/, '')

  raw_version, iaas, hypervisor, os = stemcell_parts.split('-')
  version                           = raw_version.tr('_', '.')

  name = ['bosh', iaas, hypervisor, os].join('-')

  new(name: name, version: version, file: basename, md5: md5, sha1: sha1)
end

Instance Method Details

#awsnil

Returns the interface for downloader requires this method.

Returns:

  • (nil)

    the interface for downloader requires this method



65
66
67
# File 'lib/vara/metadata/stemcell.rb', line 65

def aws
  nil
end

#to_sString

Returns a markdown-style URL with the basename attribute.

Returns:

  • (String)

    a markdown-style URL with the basename attribute.



70
71
72
# File 'lib/vara/metadata/stemcell.rb', line 70

def to_s
  "[#{basename}](#{url})"
end

#urlString

Returns the inferred blobstore URL of the stemcell, assuming it is a BOSH public stemcell.

Returns:

  • (String)

    the inferred blobstore URL of the stemcell, assuming it is a BOSH public stemcell



59
60
61
62
# File 'lib/vara/metadata/stemcell.rb', line 59

def url
  iaas = basename.gsub(/.*\d-(\w+)-.*/, '\1')
  "http://bosh-jenkins-artifacts.cf-app.com/bosh-stemcell/#{iaas}/#{basename}"
end