derelict_m 0.6.2a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.cane +2 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +18 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +22 -0
- data/derelict.gemspec +63 -0
- data/lib/derelict.rb +74 -0
- data/lib/derelict/box.rb +29 -0
- data/lib/derelict/box/manager.rb +111 -0
- data/lib/derelict/box/not_found.rb +16 -0
- data/lib/derelict/connection.rb +84 -0
- data/lib/derelict/connection/invalid.rb +14 -0
- data/lib/derelict/connection/not_found.rb +13 -0
- data/lib/derelict/exception.rb +6 -0
- data/lib/derelict/exception/optional_reason.rb +32 -0
- data/lib/derelict/executer.rb +237 -0
- data/lib/derelict/instance.rb +147 -0
- data/lib/derelict/instance/command_failed.rb +30 -0
- data/lib/derelict/instance/invalid.rb +14 -0
- data/lib/derelict/instance/missing_binary.rb +13 -0
- data/lib/derelict/instance/non_directory.rb +13 -0
- data/lib/derelict/instance/not_found.rb +13 -0
- data/lib/derelict/parser.rb +27 -0
- data/lib/derelict/parser/box_list.rb +53 -0
- data/lib/derelict/parser/box_list/invalid_format.rb +16 -0
- data/lib/derelict/parser/plugin_list.rb +63 -0
- data/lib/derelict/parser/plugin_list/invalid_format.rb +16 -0
- data/lib/derelict/parser/plugin_list/needs_reinstall.rb +22 -0
- data/lib/derelict/parser/status.rb +90 -0
- data/lib/derelict/parser/status/invalid_format.rb +16 -0
- data/lib/derelict/parser/version.rb +28 -0
- data/lib/derelict/parser/version/invalid_format.rb +16 -0
- data/lib/derelict/plugin.rb +29 -0
- data/lib/derelict/plugin/manager.rb +107 -0
- data/lib/derelict/plugin/not_found.rb +14 -0
- data/lib/derelict/utils.rb +11 -0
- data/lib/derelict/utils/logger.rb +59 -0
- data/lib/derelict/utils/logger/array_outputter.rb +43 -0
- data/lib/derelict/utils/logger/invalid_type.rb +15 -0
- data/lib/derelict/utils/logger/raw_formatter.rb +12 -0
- data/lib/derelict/version.rb +3 -0
- data/lib/derelict/virtual_machine.rb +190 -0
- data/lib/derelict/virtual_machine/invalid.rb +14 -0
- data/lib/derelict/virtual_machine/not_found.rb +18 -0
- data/spec/coverage_helper.rb +19 -0
- data/spec/derelict/box/manager_spec.rb +171 -0
- data/spec/derelict/box/not_found_spec.rb +13 -0
- data/spec/derelict/box_spec.rb +37 -0
- data/spec/derelict/connection/invalid_spec.rb +16 -0
- data/spec/derelict/connection/not_found_spec.rb +13 -0
- data/spec/derelict/connection_spec.rb +107 -0
- data/spec/derelict/exception/optional_reason_spec.rb +41 -0
- data/spec/derelict/exception_spec.rb +11 -0
- data/spec/derelict/executer_spec.rb +129 -0
- data/spec/derelict/instance/command_failed_spec.rb +40 -0
- data/spec/derelict/instance/invalid_spec.rb +16 -0
- data/spec/derelict/instance/missing_binary_spec.rb +13 -0
- data/spec/derelict/instance/non_directory_spec.rb +13 -0
- data/spec/derelict/instance/not_found_spec.rb +13 -0
- data/spec/derelict/instance_spec.rb +258 -0
- data/spec/derelict/parser/box_list/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/box_list_spec.rb +64 -0
- data/spec/derelict/parser/plugin_list/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/plugin_list/needs_reinstall_spec.rb +13 -0
- data/spec/derelict/parser/plugin_list_spec.rb +82 -0
- data/spec/derelict/parser/status/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/status_spec.rb +214 -0
- data/spec/derelict/parser/version/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/version_spec.rb +42 -0
- data/spec/derelict/parser_spec.rb +24 -0
- data/spec/derelict/plugin/manager_spec.rb +208 -0
- data/spec/derelict/plugin/not_found_spec.rb +13 -0
- data/spec/derelict/plugin_spec.rb +37 -0
- data/spec/derelict/utils/logger/array_outputter_spec.rb +40 -0
- data/spec/derelict/utils/logger/invalid_type_spec.rb +13 -0
- data/spec/derelict/utils/logger/raw_formatter_spec.rb +17 -0
- data/spec/derelict/utils/logger_spec.rb +35 -0
- data/spec/derelict/virtual_machine/invalid_spec.rb +16 -0
- data/spec/derelict/virtual_machine/not_found_spec.rb +34 -0
- data/spec/derelict/virtual_machine_spec.rb +356 -0
- data/spec/derelict_spec.rb +50 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/log_context.rb +36 -0
- metadata +332 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f616bfcc287eb2dc4f4ffc83de0657e74b85106a
|
4
|
+
data.tar.gz: e0552d84cc985a3035b5bfa15c7a4c80dfa33d07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc253a60c1642bbd4c55266f7be0449a0e39a82d0705fb0f8337c952441def545d6630147bc454be1ddc747fa06e259f5345c5b17a69fc6329625f29a48cb64e
|
7
|
+
data.tar.gz: '08756930ef5fd118c404160a9f67001ef7bd46413d32d46c721edea37a1938b91508ff2a2a3178f67358b11f9a2248b507cb84f44f83c6e6c99bffc8ab112141'
|
data/.cane
ADDED
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
before_install:
|
7
|
+
- gem update --system 2.1.11
|
8
|
+
- gem --version
|
9
|
+
deploy:
|
10
|
+
provider: rubygems
|
11
|
+
api_key:
|
12
|
+
secure: lm8VbzXJIylbk3bHC5KBU7x0zI5zDHgOaYUkrc4z8R2gjdW9RLAoX8dwJ0N2FEX24zMf3s1fPT4dg70YD2S7FnVy3zan25BP2C2FKGkQ5kqRzV+gJCSD0Hwk8Yj5Breh1RF3xutV12asLq/+rltei7Fu6BnE2pQDk9/gGSCxILs=
|
13
|
+
gem: derelict
|
14
|
+
on:
|
15
|
+
repo: bradfeehan/derelict
|
16
|
+
ruby: 2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brad Feehan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Derelict
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/derelict)
|
4
|
+
[](https://travis-ci.org/bradfeehan/derelict)
|
5
|
+
[](https://coveralls.io/r/bradfeehan/derelict)
|
6
|
+
[](https://codeclimate.com/github/bradfeehan/derelict)
|
7
|
+
[](https://gemnasium.com/bradfeehan/derelict)
|
8
|
+
|
9
|
+
Provides a Ruby API to control [Vagrant][1] where Vagrant is installed
|
10
|
+
via the Installer package on Mac OS X.
|
11
|
+
|
12
|
+
Currently a work-in-progress.
|
13
|
+
|
14
|
+
[1]: <https://www.vagrantup.com>
|
15
|
+
|
16
|
+
|
17
|
+
## Why?
|
18
|
+
|
19
|
+
Vagrant was historically available as a [gem][2], naturally providing a
|
20
|
+
Ruby API to control Vagrant in other Ruby libraries and applications.
|
21
|
+
However, [since version 1.1.0][3], [Vagrant is distributed exclusively
|
22
|
+
using an Installer package][4]. Derelict is a Ruby library that wraps
|
23
|
+
the Vagrant binary, shelling out and parsing the results of each
|
24
|
+
command.
|
25
|
+
|
26
|
+
[2]: <https://rubygems.org>
|
27
|
+
[3]: <https://groups.google.com/forum/#!msg/vagrant-up/kX_wvn7wcds/luwNur4kgDEJ>
|
28
|
+
[4]: <http://mitchellh.com/abandoning-rubygems>
|
29
|
+
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem "derelict"
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install derelict
|
44
|
+
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
Some examples of common operations using Derelict:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require "derelict"
|
52
|
+
|
53
|
+
# Determine if there's a "default" VM defined in /path/to/project
|
54
|
+
Derelict.instance.connect("/path/to/project").vm(:default).exists?
|
55
|
+
```
|
56
|
+
|
57
|
+
### Advanced
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require "derelict"
|
61
|
+
|
62
|
+
# Create an instance (represents a Vagrant installation)
|
63
|
+
instance = Derelict.instance("/path/to/vagrant")
|
64
|
+
instance = Derelict.instance # Defaults to /Applications/Vagrant
|
65
|
+
|
66
|
+
# Issue commands to the instance directly (not usually necessary)
|
67
|
+
result = instance.execute('--version') # Derelict::Executer object
|
68
|
+
print "success" if result.success? # if Vagrant's exit status was 0
|
69
|
+
print result.stdout # "Vagrant 1.3.3\n"
|
70
|
+
print result.status # 0
|
71
|
+
|
72
|
+
# Connect to a Vagrant project (containing a Vagrantfile)
|
73
|
+
connection = instance.connect("/path/to/project")
|
74
|
+
|
75
|
+
# Issue commands to the connection directly (runs from the project dir)
|
76
|
+
result = connection.execute(:up) # runs "vagrant up" in project dir
|
77
|
+
result.success? # Derelict::Executer object again
|
78
|
+
|
79
|
+
# Retrieve a particular VM from a connection (multi-machine support)
|
80
|
+
vm = connection.vm(:web) # "vm" is a Derelict::VirtualMachine
|
81
|
+
vm.exists? # does the connection define a "web" VM?
|
82
|
+
vm.state # current VM state (:running, :not_created...)
|
83
|
+
vm.running? # whether the VM is currently running or not
|
84
|
+
vm.up! # runs "vagrant up" for this VM only
|
85
|
+
vm.halt! # runs "vagrant halt" for this VM only
|
86
|
+
vm.destroy! # runs "vagrant destroy --force" for this VM
|
87
|
+
vm.reload! # runs "vagrant reload" for this VM only
|
88
|
+
vm.suspend! # runs "vagrant suspend" for this VM only
|
89
|
+
vm.resume! # runs "vagrant resume" for this VM only
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
# Define "spec" task using RSpec's built-in Rake task
|
5
|
+
RSpec::Core::RakeTask.new :spec do |spec|
|
6
|
+
spec.verbose = false
|
7
|
+
end
|
8
|
+
|
9
|
+
version_major = RbConfig::CONFIG["MAJOR"].to_i
|
10
|
+
version_minor = RbConfig::CONFIG["MINOR"].to_i
|
11
|
+
if version_major >= 2 or (version_major == 1 and version_minor >= 9)
|
12
|
+
require "cane/rake_task"
|
13
|
+
|
14
|
+
# Define "quality" task using Cane's built-in Rake task
|
15
|
+
Cane::RakeTask.new :quality do |quality|
|
16
|
+
quality.canefile = File.join File.dirname(__FILE__), ".cane"
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => [:spec, :quality]
|
20
|
+
else
|
21
|
+
task :default => :spec
|
22
|
+
end
|
data/derelict.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "derelict/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "derelict_m"
|
8
|
+
spec.version = Derelict::VERSION
|
9
|
+
spec.authors = ["Brad Feehan"]
|
10
|
+
spec.email = ["git@bradfeehan.com"]
|
11
|
+
spec.description = <<-END.strip.gsub(/ +/, " ").gsub(/^ /, "")
|
12
|
+
Provides a Ruby API to control Vagrant where Vagrant is \
|
13
|
+
installed via the Installer package on Mac OS X.
|
14
|
+
|
15
|
+
Vagrant was historically available as a gem, naturally \
|
16
|
+
providing a Ruby API to control Vagrant in other Ruby libraries \
|
17
|
+
and applications. However, since version 1.1.0, Vagrant is \
|
18
|
+
distributed exclusively using an Installer package. To control \
|
19
|
+
Vagrant when it's installed this way, other Ruby libraries and \
|
20
|
+
applications typically need to invoke the Vagrant binary, which \
|
21
|
+
requires forking a new process and parsing its output using \
|
22
|
+
string manipulation.
|
23
|
+
END
|
24
|
+
|
25
|
+
spec.summary =
|
26
|
+
"Ruby API for Vagrant installed via Installer package on Mac OS X."
|
27
|
+
spec.homepage = "https://github.com/bradfeehan/derelict"
|
28
|
+
spec.license = "MIT"
|
29
|
+
|
30
|
+
spec.files = `git ls-files`.split($/)
|
31
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
32
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_runtime_dependency "log4r", "~> 1.1.0", "!= 1.1.11"
|
36
|
+
spec.add_runtime_dependency "memoist"
|
37
|
+
spec.add_runtime_dependency "open4"
|
38
|
+
|
39
|
+
|
40
|
+
version_major = RbConfig::CONFIG["MAJOR"].to_i
|
41
|
+
version_minor = RbConfig::CONFIG["MINOR"].to_i
|
42
|
+
cane_supported = (version_major >= 2 or (version_major == 1 and version_minor >= 9))
|
43
|
+
|
44
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
45
|
+
spec.add_development_dependency "cane" if cane_supported
|
46
|
+
spec.add_development_dependency "coveralls"
|
47
|
+
spec.add_development_dependency "rake", "< 11.0"
|
48
|
+
spec.add_development_dependency "rspec", "< 3.0"
|
49
|
+
spec.add_development_dependency "simplecov"
|
50
|
+
spec.add_development_dependency "its"
|
51
|
+
spec.add_development_dependency "mime-types", "<2.0" # for coveralls
|
52
|
+
|
53
|
+
# When running on Travis CI, any passing builds will be deployed
|
54
|
+
# (i.e. pushed to RubyGems). This changes the version number so that
|
55
|
+
# these deployments are marked as pre-release versions (which will
|
56
|
+
# occur if the version number has a letter in it, so we add
|
57
|
+
# "travis" followed by the job number to the version string).
|
58
|
+
# So version 1.2.3 will be marked as (e.g.) "1.2.4.travis.567".
|
59
|
+
if ENV["TRAVIS"]
|
60
|
+
build = ENV["TRAVIS_JOB_NUMBER"].split(".").first
|
61
|
+
spec.version = "#{spec.version.to_s.succ}.travis.#{build}"
|
62
|
+
end
|
63
|
+
end
|
data/lib/derelict.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "derelict/version"
|
2
|
+
require "log4r"
|
3
|
+
require "memoist"
|
4
|
+
require "open4"
|
5
|
+
require "set"
|
6
|
+
require "shellwords"
|
7
|
+
|
8
|
+
Log4r::Logger["root"] # creates the level constants (INFO, etc).
|
9
|
+
|
10
|
+
# Main module/entry point for Derelict
|
11
|
+
module Derelict
|
12
|
+
autoload :Box, "derelict/box"
|
13
|
+
autoload :Connection, "derelict/connection"
|
14
|
+
autoload :Exception, "derelict/exception"
|
15
|
+
autoload :Executer, "derelict/executer"
|
16
|
+
autoload :Instance, "derelict/instance"
|
17
|
+
autoload :Parser, "derelict/parser"
|
18
|
+
autoload :Plugin, "derelict/plugin"
|
19
|
+
autoload :Utils, "derelict/utils"
|
20
|
+
autoload :VirtualMachine, "derelict/virtual_machine"
|
21
|
+
|
22
|
+
# Make functions accessible by Derelict.foo and private when included
|
23
|
+
module_function
|
24
|
+
|
25
|
+
# Include "logger" method to get a logger for this class
|
26
|
+
extend Utils::Logger
|
27
|
+
|
28
|
+
# Creates a new Derelict instance for a Vagrant installation
|
29
|
+
#
|
30
|
+
# * path: The path to the Vagrant installation (optional, defaults
|
31
|
+
# to Instance::DEFAULT_PATH)
|
32
|
+
def instance(path = Instance::DEFAULT_PATH)
|
33
|
+
logger.info "Creating and validating new instance for '#{path}'"
|
34
|
+
Instance.new(path).validate!
|
35
|
+
end
|
36
|
+
|
37
|
+
# Enables (or disables) Derelict's debug mode
|
38
|
+
#
|
39
|
+
# When in debug mode, Derelict will log to stderr. The debug level
|
40
|
+
# can be controlled as well (which affects the verbosity of the
|
41
|
+
# logging).
|
42
|
+
#
|
43
|
+
# Valid (symbol) keys for the options hash include:
|
44
|
+
#
|
45
|
+
# * enabled: Whether debug mode should be enabled (defaults to true)
|
46
|
+
# * level: Allows setting a custom log level (defaults to INFO)
|
47
|
+
def debug!(options = {})
|
48
|
+
options = debug_options_defaults.merge options
|
49
|
+
logger.level = options[:enabled] ? options[:level] : Log4r::OFF
|
50
|
+
|
51
|
+
if options[:enabled]
|
52
|
+
logger.add stderr unless logger.outputters.include? stderr
|
53
|
+
logger.info "enabling debug mode"
|
54
|
+
else
|
55
|
+
logger.info "disabling debug mode"
|
56
|
+
logger.remove "stderr"
|
57
|
+
end
|
58
|
+
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
# Retrieves the default values for the options hash for #debug!
|
64
|
+
def self.debug_options_defaults
|
65
|
+
{
|
66
|
+
:enabled => true,
|
67
|
+
:level => Log4r::INFO,
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.stderr
|
72
|
+
Log4r::Outputter.stderr
|
73
|
+
end
|
74
|
+
end
|
data/lib/derelict/box.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Derelict
|
2
|
+
# Represents an individual Vagrant box for a particular provider
|
3
|
+
class Box
|
4
|
+
autoload :Manager, "derelict/box/manager"
|
5
|
+
autoload :NotFound, "derelict/box/not_found"
|
6
|
+
|
7
|
+
attr_reader :name, :provider
|
8
|
+
|
9
|
+
# Initializes a box with a particular name and provider
|
10
|
+
#
|
11
|
+
# * name: The name of the box represented by this object
|
12
|
+
# * provider: The provider of the box represented by this object
|
13
|
+
def initialize(name, provider)
|
14
|
+
@name = name
|
15
|
+
@provider = provider
|
16
|
+
end
|
17
|
+
|
18
|
+
# Ensure equivalent Boxes are equal to this one
|
19
|
+
def ==(other)
|
20
|
+
other.name == name and other.provider == provider
|
21
|
+
end
|
22
|
+
alias_method :eql?, :==
|
23
|
+
|
24
|
+
# Make equivalent Boxes hash to the same value
|
25
|
+
def hash
|
26
|
+
name.hash ^ provider.hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Derelict
|
2
|
+
class Box
|
3
|
+
# A class that handles managing boxes for a Vagrant instance
|
4
|
+
class Manager
|
5
|
+
# Include "memoize" class method to memoize methods
|
6
|
+
extend Memoist
|
7
|
+
|
8
|
+
# Include "logger" method to get a logger for this class
|
9
|
+
include Utils::Logger
|
10
|
+
|
11
|
+
attr_reader :instance
|
12
|
+
|
13
|
+
# Initializes a Manager for use with a particular instance
|
14
|
+
#
|
15
|
+
# * instance: The Derelict::Instance which will have its
|
16
|
+
# boxes managed by this Manager
|
17
|
+
def initialize(instance)
|
18
|
+
@instance = instance
|
19
|
+
logger.debug "Successfully initialized #{description}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Retrieves the Set of currently installed boxes
|
23
|
+
def list
|
24
|
+
logger.info "Retrieving Vagrant box list for #{description}"
|
25
|
+
output = instance.execute!(:box, "list").stdout
|
26
|
+
Derelict::Parser::BoxList.new(output).boxes
|
27
|
+
end
|
28
|
+
memoize :list
|
29
|
+
|
30
|
+
# Determines whether a particular box is installed
|
31
|
+
#
|
32
|
+
# * box_name: Name of the box to look for (as a string)
|
33
|
+
def present?(box_name, provider)
|
34
|
+
fetch(box_name, provider)
|
35
|
+
true
|
36
|
+
rescue Box::NotFound
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds a box from a file or URL
|
41
|
+
#
|
42
|
+
# The provider will be automatically determined from the box
|
43
|
+
# file's manifest.
|
44
|
+
#
|
45
|
+
# * box_name: The name of the box to add (e.g. "precise64")
|
46
|
+
# * source: The URL or path to the box file
|
47
|
+
# * options: Hash of options. Valid keys:
|
48
|
+
# * log: Whether to log the output (optional, defaults to
|
49
|
+
# false)
|
50
|
+
def add(box_name, source, options = {})
|
51
|
+
options = {:log => false}.merge(options)
|
52
|
+
logger.info <<-END.gsub(/ {10}|\n\Z/, '')
|
53
|
+
Adding box '#{box_name}' from '#{source}' using #{description}
|
54
|
+
END
|
55
|
+
|
56
|
+
command = [:box, "add", box_name, source]
|
57
|
+
command << "--force" if options[:force]
|
58
|
+
|
59
|
+
log_block = options[:log] ? shell_log_block : nil
|
60
|
+
instance.execute!(*command, &log_block).tap do
|
61
|
+
flush_cache # flush memoized method return values
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Removes an installed box for a particular provider
|
66
|
+
#
|
67
|
+
# * box_name: Name of the box to remove (e.g. "precise64")
|
68
|
+
# * options: Hash of options. Valid keys:
|
69
|
+
# * log: Whether to log the output (optional, defaults
|
70
|
+
# to false)
|
71
|
+
# * provider: If specified, only the box for a particular
|
72
|
+
# provider is removed; otherwise (by default),
|
73
|
+
# the box is removed for all providers
|
74
|
+
def remove(box_name, options = {})
|
75
|
+
options = {:log => false, :provider => nil}.merge(options)
|
76
|
+
|
77
|
+
provider = options[:provider]
|
78
|
+
command = [:box, "remove", box_name]
|
79
|
+
command << provider unless provider.nil?
|
80
|
+
|
81
|
+
logger.info <<-END.gsub(/ {10}|\n\Z/, '')
|
82
|
+
Removing box '#{box_name}' for '#{provider}' using #{description}
|
83
|
+
END
|
84
|
+
|
85
|
+
log_block = options[:log] ? shell_log_block : nil
|
86
|
+
instance.execute!(*command, &log_block).tap do
|
87
|
+
flush_cache # flush memoized method return values
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Retrieves a box with a particular name
|
92
|
+
#
|
93
|
+
# * box_name: Name of the box to look for (as a string)
|
94
|
+
def fetch(box_name, provider)
|
95
|
+
box = list.find do |box|
|
96
|
+
box.name == box_name && box.provider == provider
|
97
|
+
end
|
98
|
+
|
99
|
+
raise Box::NotFound.new box_name, provider if box.nil?
|
100
|
+
box
|
101
|
+
end
|
102
|
+
|
103
|
+
# Provides a description of this Connection
|
104
|
+
#
|
105
|
+
# Mainly used for log messages.
|
106
|
+
def description
|
107
|
+
"Derelict::Box::Manager for #{instance.description}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|