Class: Vagrant::Box
- Inherits:
-
Object
- Object
- Vagrant::Box
- Defined in:
- lib/vagrant/box.rb
Overview
Represents a "box," which is simply a packaged vagrant environment.
Boxes are simply tar
files which contain an exported VirtualBox
virtual machine, at the least. They are created with vagrant package
and may contain additional files if specified by the creator. This
class serves to help manage these boxes, although most of the logic
is kicked out to middlewares.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
The environment which this box belongs to.
-
#name ⇒ Object
The name of the box.
-
#uri ⇒ Object
The URI for a new box.
Class Method Summary collapse
-
.add(env, name, uri) ⇒ Object
Adds a new box with given name from the given URI.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Implemented for comparison with other boxes.
-
#add ⇒ Object
Begins the process of adding a box to the vagrant installation.
-
#destroy ⇒ Object
Begins the process of destroying this box.
-
#directory ⇒ String
Returns the directory to the location of this boxes content in the local filesystem.
-
#initialize(env = nil, name = nil) ⇒ Box
constructor
Creates a new box instance.
-
#ovf_file ⇒ String
Returns path to the OVF file of the box.
-
#repackage(options = nil) ⇒ Object
Begins sequence to repackage this box.
Constructor Details
#initialize(env = nil, name = nil) ⇒ Box
Creates a new box instance. Given an optional name
parameter,
newly created instance will have that name, otherwise it defaults
to nil
.
Note: This method does not actually create the box, but merely returns a new, abstract representation of it. To add a box, see #add.
40 41 42 43 |
# File 'lib/vagrant/box.rb', line 40 def initialize(env=nil, name=nil) @name = name @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
The environment which this box belongs to. Although this could actually be many environments, this points to the environment of a specific instance.
18 19 20 |
# File 'lib/vagrant/box.rb', line 18 def env @env end |
#name ⇒ Object
The name of the box.
10 11 12 |
# File 'lib/vagrant/box.rb', line 10 def name @name end |
#uri ⇒ Object
The URI for a new box. This is not available for existing boxes.
13 14 15 |
# File 'lib/vagrant/box.rb', line 13 def uri @uri end |
Class Method Details
.add(env, name, uri) ⇒ Object
Adds a new box with given name from the given URI. This method begins the process of adding a box from a given URI by setting up the Vagrant::Box instance and calling #add.
27 28 29 30 31 |
# File 'lib/vagrant/box.rb', line 27 def add(env, name, uri) box = new(env, name) box.uri = uri box.add end |
Instance Method Details
#<=>(other) ⇒ Object
Implemented for comparison with other boxes. Comparison is implemented by simply comparing name.
85 86 87 88 |
# File 'lib/vagrant/box.rb', line 85 def <=>(other) return super if !other.is_a?(self.class) name <=> other.name end |
#add ⇒ Object
Begins the process of adding a box to the vagrant installation. This
method requires that name
and uri
be set. The logic of this method
is kicked out to the box_add
registered middleware.
59 60 61 62 |
# File 'lib/vagrant/box.rb', line 59 def add raise Errors::BoxAlreadyExists, :name => name if File.directory?(directory) env.actions.run(:box_add, { "box" => self, "validate" => false }) end |
#destroy ⇒ Object
Begins the process of destroying this box. This cannot be undone!
65 66 67 |
# File 'lib/vagrant/box.rb', line 65 def destroy env.actions.run(:box_remove, { "box" => self, "validate" => false }) end |
#directory ⇒ String
Returns the directory to the location of this boxes content in the local filesystem. Note that if the box isn't imported yet, then the path may not yet exist, but still represents where the box will be imported to.
79 80 81 |
# File 'lib/vagrant/box.rb', line 79 def directory env.boxes_path.join(name) end |
#ovf_file ⇒ String
Returns path to the OVF file of the box. The OVF file is an open virtual machine file which contains specifications of the exported virtual machine this box contains.
This will only be valid once the box is imported.
52 53 54 |
# File 'lib/vagrant/box.rb', line 52 def ovf_file directory.join(env.config.vm.box_ovf) end |
#repackage(options = nil) ⇒ Object
Begins sequence to repackage this box.
70 71 72 |
# File 'lib/vagrant/box.rb', line 70 def repackage(=nil) env.actions.run(:box_repackage, { "box" => self, "validate" => false }.merge( || {})) end |