Class: VagrantZFS::Action::Box::Unpackage

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_zfs/action/box/unpackage.rb

Overview

Unpackages a downloaded box to a given directory with a given name.

This variant will first create a ZFS directory from a configured zpool and then unpack the box into the directory.

# Required Variables

  • ‘download.temp_path` - A location for the downloaded box. This is set by the Download action.

  • ‘box` - A Vagrant::Box object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Unpackage

Returns a new instance of Unpackage.



20
21
22
23
24
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 20

def initialize(app, env)
  @logger   = Log4r::Logger.new("vagrant_zfs::action::box::unpackage")
  @app = app
  @env = env
end

Instance Attribute Details

#box_directoryObject (readonly)

Returns the value of attribute box_directory.



18
19
20
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 18

def box_directory
  @box_directory
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 26

def call(env)
  @env = env

  setup_box_directory
  decompress

  @app.call(@env)
end

#decompressObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 69

def decompress
  Dir.chdir(@env["box_directory"]) do
    @env[:ui].info I18n.t("vagrant.actions.box.unpackage.extracting")
    begin
      Archive::Tar::Minitar.unpack(@env["download.temp_path"], @env["box_directory"].to_s)
    rescue SystemCallError
      raise Errors::BoxUnpackageFailure
    end
  end
end

#recover(env) ⇒ Object



35
36
37
38
39
40
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 35

def recover(env)
  if box_directory && File.directory?(box_directory)
    VagrantZFS::ZFS.destroy env[:zfs_name]
    FileUtils.rm_rf(box_directory)
  end
end

#setup_box_directoryObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 57

def setup_box_directory
  if File.directory?(@env["box_directory"])
    raise Errors::BoxAlreadyExists, :name => @env["box_name"]
  end

  puts "ZPOOL: #{zpool}"
  @env[:zfs_name] = "#{zpool}/vagrant_#{@env["box_name"]}"
  mountpoint = "#{@env["box_directory"]}"
  VagrantZFS::ZFS.create @env[:zfs_name], mountpoint
  @box_directory = @env["box_directory"]
end

#zpoolObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant_zfs/action/box/unpackage.rb', line 42

def zpool
  # Is the zpool specified in the Vagrantfile?
  if @env['global_config'].zfs.zpool
    @env['global_config'].zfs.zpool
  else
    # If we have only one zpool available, go with that.
    zpools = VagrantZFS::ZFS.zpool_list
    if zpools.length == 1
      zpools.first
    else
      raise Exception, "zpool not specified and more than one available."
    end
  end
end