Class: PEBuild::Archive

Inherits:
Object
  • Object
show all
Includes:
Idempotent
Defined in:
lib/pe_build/archive.rb

Overview

Represents a packed Puppet Enterprise archive

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Idempotent

#idempotent

Constructor Details

#initialize(filename, env) ⇒ Archive

Returns a new instance of Archive.

Parameters:

  • filename (String)

    The uninterpolated filename

  • env (Hash)


43
44
45
46
47
48
49
50
# File 'lib/pe_build/archive.rb', line 43

def initialize(filename, env)
  @filename = filename
  @env      = env

  @archive_dir = PEBuild.archive_directory(@env)

  @logger = Log4r::Logger.new('vagrant::pe_build::archive')
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



39
40
41
# File 'lib/pe_build/archive.rb', line 39

def env
  @env
end

#filenameString

Returns The filename. Thing.

Returns:

  • (String)

    The filename. Thing



37
38
39
# File 'lib/pe_build/archive.rb', line 37

def filename
  @filename
end

#seriesString

Returns The release series of PE. Completely optional and currently has no effect other than being an interpolation token available for use in download_root.

Returns:

  • (String)

    The release series of PE. Completely optional and currently has no effect other than being an interpolation token available for use in download_root.

See Also:

Since:

  • 0.9.0



33
34
35
# File 'lib/pe_build/archive.rb', line 33

def series
  @series
end

#versionString

Returns The version of Puppet Enterprise.

Returns:

  • (String)

    The version of Puppet Enterprise



28
29
30
# File 'lib/pe_build/archive.rb', line 28

def version
  @version
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/pe_build/archive.rb', line 89

def exist?
  File.exist? archive_path
end

#fetch(str) ⇒ Object

Parameters:

  • str (String)

    A string representation of the download source URI



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pe_build/archive.rb', line 53

def fetch(str)
  return if self.exist?

  if str.nil?
    @env.ui.error "Cannot fetch installer #{versioned_path @filename}; no download source available."
    @env.ui.error ""
    @env.ui.error "Installers available for use:"

    collection = PEBuild::ArchiveCollection.new(@archive_dir, @env)
    collection.display

    raise PEBuild::ArchiveNoInstallerSource, :filename => versioned_path(@filename)
  end

  uri = source_uri(str)
  dst = File.join(@archive_dir, versioned_path(@filename))

  PEBuild::Transfer.copy(uri, dst)
end

#installer_dirObject



102
103
104
# File 'lib/pe_build/archive.rb', line 102

def installer_dir
  versioned_path(@filename).gsub(/.tar(?:\.gz)?/, '')
end

#source_uri(base_uri) ⇒ Object

Parameters:

  • base_uri (String, URI)

    A base uri for downloads.



98
99
100
# File 'lib/pe_build/archive.rb', line 98

def source_uri(base_uri)
  URI.parse(versioned_path("#{base_uri.to_s}/#{@filename}"))
end

#to_sObject



93
94
95
# File 'lib/pe_build/archive.rb', line 93

def to_s
  versioned_path(@filename)
end

#unpack_to(fs_dir) ⇒ Object

Parameters:

  • fs_dir (String)

    The base directory to extract the installer to



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/pe_build/archive.rb', line 74

def unpack_to(fs_dir)
  unless exist?
    raise PEBuild::ArchiveMissing, :filename => @filename
  end

  archive = PEBuild::Unpack.generate(archive_path, fs_dir)
  begin
    idempotent(archive.creates, "Unpacked archive #{versioned_path filename}") do
      archive.unpack
    end
  rescue Zlib::GzipFile::Error => e
    raise PEBuild::ArchiveUnreadable, :filename => @filename, :message => e.message
  end
end