Class: Bosh::Stemcell::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/stemcell/archive.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '') ⇒ Archive

Returns a new instance of Archive.


9
10
11
12
# File 'lib/bosh/stemcell/archive.rb', line 9

def initialize(path = '')
  @path = path
  validate_stemcell
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


7
8
9
# File 'lib/bosh/stemcell/archive.rb', line 7

def path
  @path
end

Instance Method Details

#extract(tar_options = {}, &block) ⇒ Object


40
41
42
43
44
45
46
47
48
49
# File 'lib/bosh/stemcell/archive.rb', line 40

def extract(tar_options = {}, &block)
  Dir.mktmpdir do |tmp_dir|
    tar_cmd = "tar xzf #{path} --directory #{tmp_dir}"
    tar_cmd << " --exclude=#{tar_options[:exclude]}" if tar_options.has_key?(:exclude)

    Rake::FileUtilsExt.sh(tar_cmd)

    block.call(tmp_dir, manifest)
  end
end

#infrastructureObject


22
23
24
# File 'lib/bosh/stemcell/archive.rb', line 22

def infrastructure
  cloud_properties.fetch('infrastructure')
end

#light?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/bosh/stemcell/archive.rb', line 36

def light?
  infrastructure == 'aws' && has_ami?
end

#manifestObject


14
15
16
# File 'lib/bosh/stemcell/archive.rb', line 14

def manifest
  @manifest ||= Psych.load(`tar -Oxzf #{path} stemcell.MF`)
end

#nameObject


18
19
20
# File 'lib/bosh/stemcell/archive.rb', line 18

def name
  manifest.fetch('name')
end

#sha1Object


30
31
32
33
34
# File 'lib/bosh/stemcell/archive.rb', line 30

def sha1
  sha1 = manifest.fetch('sha1')
  raise 'sha1 must not be nil' unless sha1
  sha1.to_s
end

#versionObject


26
27
28
# File 'lib/bosh/stemcell/archive.rb', line 26

def version
  cloud_properties.fetch('version')
end