vagrant-pirate 0.2.0 → 0.3.0
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 +4 -4
- data/features/fleet.feature +34 -0
- data/features/help.feature +10 -12
- data/features/ship.feature +16 -21
- data/features/step_definitions/vagrant_steps.rb +30 -0
- data/features/support/env.rb +5 -5
- data/lib/vagrant-pirate.rb +1 -1
- data/lib/vagrant-pirate/command/{pirate_ship.rb → fleet.rb} +32 -19
- data/lib/vagrant-pirate/command/pirate.rb +8 -6
- data/lib/vagrant-pirate/command/ship.rb +73 -0
- data/lib/vagrant-pirate/config/pirate.rb +2 -14
- data/lib/vagrant-pirate/errors.rb +21 -3
- data/lib/vagrant-pirate/{vagrant-pirate.rb → pirate.rb} +40 -27
- data/lib/vagrant-pirate/plugin.rb +9 -8
- data/lib/vagrant-pirate/version.rb +2 -2
- data/locales/en.yml +30 -12
- data/tasks/cucumber.rake +1 -1
- data/templates/{default.yaml.erb → Piratefile.erb} +0 -0
- data/templates/{Vagrantfile.erb → Vagrantfile_fleet.erb} +0 -0
- data/templates/Vagrantfile_ship.erb +16 -0
- data/vagrant-pirate.gemspec +1 -1
- metadata +10 -7
- data/lib/vagrant-pirate/command/pirate_update.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34fae5c76d4b0a545453514b6b97748e5a6853da
|
4
|
+
data.tar.gz: 73d1e410e8dfea98add9d35ab7a364f2da6c8d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b81186308a7b48611a35c57f98885520d441ef9a4004d567b997bae4c8ba7160dba4a48d35af593f235cd509f5e0bad4ea57ceeb3c754919036844ff518e6ab
|
7
|
+
data.tar.gz: 16e1f49461211119bf20534de4e87fc14e17b05e027bff5eec2e69f159c4940452fea916f24c04fdbf014eb7de73cf474768b1cb2dfbb7abd6f2c63348deead6
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: 'vagrant pirate fleet' command
|
2
|
+
|
3
|
+
In order to start using a complex YAML-based Vagrant project
|
4
|
+
As a user using vagrant-pirate
|
5
|
+
I want to initialize a new full-featured project
|
6
|
+
|
7
|
+
Scenario: Running 'vagrant pirate fleet'
|
8
|
+
Given a directory named "test_fleet"
|
9
|
+
And I cd to "test_fleet"
|
10
|
+
When I successfully run `vagrant pirate fleet`
|
11
|
+
Then the following directories should exist:
|
12
|
+
| local.d |
|
13
|
+
| available.d |
|
14
|
+
| available.d/default |
|
15
|
+
| enabled.d |
|
16
|
+
| enabled.d/vm1 |
|
17
|
+
| enabled.d/vm2 |
|
18
|
+
And the following files should exist:
|
19
|
+
| Vagrantfile |
|
20
|
+
| available.d/default/Piratefile |
|
21
|
+
| local.d/vm1.yaml |
|
22
|
+
| local.d/vm2.yaml |
|
23
|
+
And the output should contain "A `Vagrantfile` has been placed in this directory. A default directory containing"
|
24
|
+
|
25
|
+
@up
|
26
|
+
Scenario: Running 'vagrant up' after initializing a full project
|
27
|
+
Given a Vagrant project directory named "test_fleet_up"
|
28
|
+
When I successfully run `vagrant pirate fleet`
|
29
|
+
And I successfully run `vagrant up`
|
30
|
+
And I successfully run `vagrant ssh vm1 -c "hostname -f"`
|
31
|
+
And I successfully run `vagrant ssh vm2 -c "hostname -f"`
|
32
|
+
Then the output should contain "vm1.example.com"
|
33
|
+
Then the output should contain "vm2.example.com"
|
34
|
+
|
data/features/help.feature
CHANGED
@@ -8,36 +8,34 @@ Feature: Command help text
|
|
8
8
|
When I successfully run `vagrant help`
|
9
9
|
Then the output should contain "pirate"
|
10
10
|
And the output should contain "Manage YAML-based projects."
|
11
|
+
And the output should not contain "pirate-fleet"
|
11
12
|
And the output should not contain "pirate-ship"
|
12
|
-
And the output should not contain "pirate-update"
|
13
13
|
|
14
14
|
Scenario: Running 'vagrant list-commands'
|
15
15
|
When I successfully run `vagrant list-commands`
|
16
16
|
Then the output should contain "pirate"
|
17
17
|
And the output should contain "Manage YAML-based projects."
|
18
|
+
And the output should contain "pirate-fleet"
|
19
|
+
And the output should contain "Initializes a new Vagrant environment by creating a Vagrantfile and YAML config files."
|
18
20
|
And the output should contain "pirate-ship"
|
19
21
|
And the output should contain "Initializes a new Vagrant environment by creating a Vagrantfile and YAML config files."
|
20
|
-
And the output should contain "pirate-update"
|
21
|
-
And the output should contain "Updates a YAML-based Vagrant environment."
|
22
22
|
|
23
23
|
Scenario: Running 'vagrant pirate'
|
24
24
|
When I successfully run `vagrant pirate`
|
25
25
|
Then the output should contain "Usage: vagrant pirate <command> [<args>]"
|
26
26
|
And the output should contain "Available subcommands:"
|
27
|
+
And the output should contain "fleet"
|
27
28
|
And the output should contain "ship"
|
28
|
-
And the output should contain "update"
|
29
29
|
And the output should contain "For help on any individual command run `vagrant pirate COMMAND -h`"
|
30
30
|
|
31
|
-
Scenario: Running 'vagrant pirate
|
32
|
-
When I successfully run `vagrant pirate
|
33
|
-
Then the output should contain "Usage: vagrant pirate
|
31
|
+
Scenario: Running 'vagrant pirate fleet -h'
|
32
|
+
When I successfully run `vagrant pirate fleet -h`
|
33
|
+
Then the output should contain "Usage: vagrant pirate fleet [box-name] [box-url]"
|
34
34
|
And the output should contain "-h, --help"
|
35
35
|
And the output should contain "Print this help"
|
36
36
|
|
37
|
-
Scenario: Running 'vagrant pirate
|
38
|
-
When I successfully run `vagrant pirate
|
39
|
-
Then the output should contain "Usage: vagrant pirate
|
40
|
-
And the output should contain "-f, --force"
|
41
|
-
And the output should contain "Update without confirmation."
|
37
|
+
Scenario: Running 'vagrant pirate ship -h'
|
38
|
+
When I successfully run `vagrant pirate ship -h`
|
39
|
+
Then the output should contain "Usage: vagrant pirate ship [box-name] [box-url]"
|
42
40
|
And the output should contain "-h, --help"
|
43
41
|
And the output should contain "Print this help"
|
data/features/ship.feature
CHANGED
@@ -1,28 +1,23 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: 'vagrant pirate ship' command
|
2
2
|
|
3
3
|
In order to start using a YAML-based Vagrant project
|
4
4
|
As a user using vagrant-pirate
|
5
|
-
I want to initialize a new project
|
5
|
+
I want to initialize a new basic project
|
6
6
|
|
7
7
|
Scenario: Running 'vagrant pirate ship'
|
8
|
-
Given a directory named "
|
9
|
-
And I cd to "
|
8
|
+
Given a directory named "test_ship"
|
9
|
+
And I cd to "test_ship"
|
10
10
|
When I successfully run `vagrant pirate ship`
|
11
|
-
Then the following
|
12
|
-
| local.d |
|
13
|
-
| available.d |
|
14
|
-
| enabled.d |
|
15
|
-
And the following files should exist:
|
11
|
+
Then the following files should exist:
|
16
12
|
| Vagrantfile |
|
17
|
-
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
And
|
25
|
-
And
|
26
|
-
|
27
|
-
|
28
|
-
And the output should contain "file to see how it works."
|
13
|
+
| Piratefile |
|
14
|
+
And the output should contain "A `Vagrantfile` and `Piratefile` (YAML VM config file) have been placed in this"
|
15
|
+
|
16
|
+
@up
|
17
|
+
Scenario: Running 'vagrant up' after initializing a basic project
|
18
|
+
Given a Vagrant project directory named "test_ship_up"
|
19
|
+
When I successfully run `vagrant pirate ship`
|
20
|
+
And I successfully run `vagrant up`
|
21
|
+
And I successfully run `vagrant ssh vm1 -c "hostname -f"`
|
22
|
+
Then the output should contain "vm1.example.com"
|
23
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Given(/^a Vagrant project directory named "(.*?)"$/) do |dir_name|
|
2
|
+
# Running 'vagrant up' (in a subsequent step) will take longer than the
|
3
|
+
# default 3 seconds that Aruba allows a process to run. So we set it to
|
4
|
+
# 2 minutes, unless it's already explicitely been set with:
|
5
|
+
# "Given The default aruba timeout is X seconds"
|
6
|
+
@aruba_timeout_seconds ||= 120
|
7
|
+
|
8
|
+
create_dir(dir_name)
|
9
|
+
cd(dir_name)
|
10
|
+
|
11
|
+
# We register the directory we'll be running 'vagrant up' in, so that we
|
12
|
+
# can 'vagrant destroy' it in our 'After' hook. Since the 'After' hook runs
|
13
|
+
# after each scenario, it's safe to re-use a single environment variable.
|
14
|
+
# If we ever want to support using this step multiple times in a single
|
15
|
+
# scenario, we'll need to re-work this.
|
16
|
+
ENV['vagrant_test_dir'] = Pathname.new(Dir.pwd).join(current_dir).to_s
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
After do |scenario|
|
21
|
+
if ENV.member?('vagrant_test_dir')
|
22
|
+
# chdir's persist within the process, so we'll need to get back where we
|
23
|
+
# started.
|
24
|
+
orig_dir = Dir.pwd
|
25
|
+
# @TODO Print the below calls and their output when @announce is set.
|
26
|
+
Dir.chdir(ENV.delete('vagrant_test_dir'))
|
27
|
+
`vagrant destroy -f`
|
28
|
+
Dir.chdir(orig_dir)
|
29
|
+
end
|
30
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# Since simplecov
|
2
|
-
# we
|
3
|
-
#
|
1
|
+
# Since simplecov needs to run in the same process as the code being analyzed,
|
2
|
+
# we initialize simplecov at the very beginning of our plugin. To only do so
|
3
|
+
# during tests, we wrap it in a check for an environment variable.
|
4
4
|
ENV['COVERAGE'] = 'true'
|
5
5
|
require 'coveralls'
|
6
|
-
# Since simplecov is running under a separate process, we need to retrieve
|
7
|
-
# results afterwards.
|
6
|
+
# Since simplecov is running under a separate process, we need to retrieve and
|
7
|
+
# merge the results afterwards.
|
8
8
|
Coveralls.wear_merged!
|
9
9
|
require 'aruba/cucumber'
|
data/lib/vagrant-pirate.rb
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
require 'vagrant'
|
12
12
|
require 'vagrant-pirate/errors'
|
13
13
|
require 'vagrant-pirate/plugin'
|
14
|
-
require 'vagrant-pirate/
|
14
|
+
require 'vagrant-pirate/pirate'
|
15
15
|
|
16
16
|
# Add our custom translations to the load path
|
17
17
|
I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
|
@@ -2,18 +2,17 @@ require 'optparse'
|
|
2
2
|
require 'vagrant/util/template_renderer'
|
3
3
|
|
4
4
|
module VagrantPlugins
|
5
|
-
module
|
5
|
+
module Pirate
|
6
6
|
module Command
|
7
|
-
class
|
7
|
+
class Fleet < Vagrant.plugin("2", :command)
|
8
8
|
|
9
9
|
def self.synopsis
|
10
10
|
"Initializes a new Vagrant environment by creating a Vagrantfile and YAML config files."
|
11
11
|
end
|
12
12
|
def execute
|
13
13
|
options = {}
|
14
|
-
|
15
14
|
opts = OptionParser.new do |opts|
|
16
|
-
opts.banner = "Usage: vagrant pirate
|
15
|
+
opts.banner = "Usage: vagrant pirate fleet [box-name] [box-url]"
|
17
16
|
end
|
18
17
|
|
19
18
|
# Parse the options
|
@@ -22,12 +21,12 @@ module VagrantPlugins
|
|
22
21
|
|
23
22
|
create_vagrantfile
|
24
23
|
create_directories
|
25
|
-
|
24
|
+
create_piratefile(argv[0], argv[1])
|
26
25
|
create_vm_yaml('vm1')
|
27
26
|
create_vm_yaml('vm2')
|
28
27
|
|
29
28
|
@env.ui.info(I18n.t(
|
30
|
-
"vagrant.plugins.pirate.commands.
|
29
|
+
"vagrant.plugins.pirate.commands.fleet.success",
|
31
30
|
avail_dir: 'available.d',
|
32
31
|
enabled_dir: 'enabled.d',
|
33
32
|
local_dir: 'local.d'
|
@@ -38,9 +37,11 @@ module VagrantPlugins
|
|
38
37
|
|
39
38
|
def create_vagrantfile
|
40
39
|
save_path = @env.cwd.join("Vagrantfile")
|
41
|
-
|
40
|
+
if save_path.exist?
|
41
|
+
raise ::Pirate::Errors::VagrantfileExistsError, :command => 'fleet'
|
42
|
+
end
|
42
43
|
|
43
|
-
template_path = ::
|
44
|
+
template_path = ::Pirate.gangway.join("templates/Vagrantfile_fleet")
|
44
45
|
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
45
46
|
save_path.open("w+") do |f|
|
46
47
|
f.write(contents)
|
@@ -48,16 +49,21 @@ module VagrantPlugins
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def create_directories
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
['available.d', 'enabled.d', 'local.d', 'available.d/default'].each do |dir|
|
53
|
+
if ::Pirate.haven.join(dir).exist?
|
54
|
+
raise ::Pirate::Errors::ConfigDirExistsError, :this_dir => dir, :command => 'fleet'
|
55
|
+
end
|
56
|
+
Dir.mkdir(dir)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
|
-
def
|
57
|
-
save_path =
|
58
|
-
|
60
|
+
def create_piratefile(box_name=nil, box_url=nil)
|
61
|
+
save_path = ::Pirate.haven.join("available.d/default/Piratefile")
|
62
|
+
if save_path.exist?
|
63
|
+
raise ::Pirate::Errors::PiratefileExistsError, :this_dir => save_path.dirname, :command => 'fleet'
|
64
|
+
end
|
59
65
|
|
60
|
-
template_path = ::
|
66
|
+
template_path = ::Pirate.gangway.join("templates/Piratefile")
|
61
67
|
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
62
68
|
:box_name => box_name,
|
63
69
|
:box_url => box_url)
|
@@ -67,10 +73,17 @@ module VagrantPlugins
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def create_vm_yaml(vm_name)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
source = "enabled.d/" + vm_name
|
77
|
+
target = "../available.d/default/"
|
78
|
+
if ::Pirate.haven.join(source).exist?
|
79
|
+
raise ::Pirate::Errors::SymlinkExistsError, :source => source, :command => 'fleet'
|
80
|
+
end
|
81
|
+
File.symlink(target, source)
|
82
|
+
save_path = ::Pirate.haven.join("local.d/" + vm_name + ".yaml")
|
83
|
+
if save_path.exist?
|
84
|
+
raise ::Pirate::Errors::LocalFileExistsError, :save_path => save_path, :command => 'fleet'
|
85
|
+
end
|
86
|
+
template_path = ::Pirate.gangway.join("templates/local.yaml")
|
74
87
|
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
75
88
|
:hostname => vm_name + ".example.com")
|
76
89
|
save_path.open("w+") do |f|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
|
-
module
|
4
|
+
module Pirate
|
5
5
|
module Command
|
6
6
|
class Pirate < Vagrant.plugin("2", :command)
|
7
7
|
def self.synopsis
|
@@ -14,15 +14,17 @@ module VagrantPlugins
|
|
14
14
|
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
15
15
|
|
16
16
|
@subcommands = Vagrant::Registry.new
|
17
|
+
|
17
18
|
@subcommands.register(:ship) do
|
18
|
-
require File.expand_path("../
|
19
|
-
|
19
|
+
require File.expand_path("../ship", __FILE__)
|
20
|
+
Ship
|
20
21
|
end
|
21
22
|
|
22
|
-
@subcommands.register(:
|
23
|
-
require File.expand_path("../
|
24
|
-
|
23
|
+
@subcommands.register(:fleet) do
|
24
|
+
require File.expand_path("../fleet", __FILE__)
|
25
|
+
Fleet
|
25
26
|
end
|
27
|
+
|
26
28
|
end
|
27
29
|
|
28
30
|
def execute
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant/util/template_renderer'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Pirate
|
6
|
+
module Command
|
7
|
+
class Ship < Vagrant.plugin("2", :command)
|
8
|
+
|
9
|
+
def self.synopsis
|
10
|
+
"Initializes a new Vagrant environment by creating a Vagrantfile and YAML config files."
|
11
|
+
end
|
12
|
+
def execute
|
13
|
+
options = {}
|
14
|
+
opts = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: vagrant pirate ship [box-name] [box-url]"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Parse the options
|
19
|
+
argv = parse_options(opts)
|
20
|
+
return if !argv
|
21
|
+
|
22
|
+
create_vagrantfile
|
23
|
+
create_piratefile(argv[0], argv[1])
|
24
|
+
create_vm_yaml('vm1')
|
25
|
+
|
26
|
+
@env.ui.info(I18n.t("vagrant.plugins.pirate.commands.ship.success"), :prefix => false)
|
27
|
+
|
28
|
+
# Success, exit status 0
|
29
|
+
0
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_vagrantfile
|
33
|
+
save_path = @env.cwd.join("Vagrantfile")
|
34
|
+
if save_path.exist?
|
35
|
+
raise ::Pirate::Errors::VagrantfileExistsError, :command => 'ship'
|
36
|
+
end
|
37
|
+
|
38
|
+
template_path = ::Pirate.gangway.join("templates/Vagrantfile_ship")
|
39
|
+
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
40
|
+
save_path.open("w+") do |f|
|
41
|
+
f.write(contents)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_piratefile(box_name=nil, box_url=nil)
|
46
|
+
save_path = ::Pirate.haven.join("Piratefile")
|
47
|
+
if save_path.exist?
|
48
|
+
raise ::Pirate::Errors::PiratefileExistsError, :this_dir => save_path.dirname, :command => 'ship'
|
49
|
+
end
|
50
|
+
|
51
|
+
template_path = ::Pirate.gangway.join("templates/Piratefile")
|
52
|
+
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
53
|
+
:box_name => box_name,
|
54
|
+
:box_url => box_url)
|
55
|
+
save_path.open("w+") do |f|
|
56
|
+
f.write(contents)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_vm_yaml(vm_name)
|
61
|
+
source = ::Pirate.haven.join(vm_name)
|
62
|
+
# TODO: target need to be relative
|
63
|
+
target = ::Pirate.haven.join(".")
|
64
|
+
if source.exist?
|
65
|
+
raise ::Pirate::Errors::SymlinkExistsError, :source => source, :command => 'ship'
|
66
|
+
end
|
67
|
+
File.symlink('.', source)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module VagrantPlugins
|
2
|
-
module
|
2
|
+
module Pirate
|
3
3
|
module Config
|
4
4
|
class Pirate < Vagrant.plugin("2", :config)
|
5
5
|
attr_accessor :map
|
@@ -10,22 +10,10 @@ module VagrantPlugins
|
|
10
10
|
|
11
11
|
def finalize!
|
12
12
|
if @map == UNSET_VALUE
|
13
|
-
@map = { "local" => "local.d", "enabled" => "
|
13
|
+
@map = { "local" => "local.d", "enabled" => "enabled.d" }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def validate(machine)
|
18
|
-
errors = _detected_errors
|
19
|
-
@map.each() do |name, conf_dir|
|
20
|
-
current_dir = Dir.pwd + '/' + conf_dir
|
21
|
-
if !File.directory?(current_dir)
|
22
|
-
errors << "Configuration directories must exist: #{current_dir}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
{ "pirate" => errors }
|
27
|
-
end
|
28
|
-
|
29
17
|
end
|
30
18
|
end
|
31
19
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Pirate
|
2
2
|
module Errors
|
3
3
|
|
4
4
|
class PirateError < Vagrant::Errors::VagrantError
|
@@ -9,9 +9,27 @@ module VagrantPirate
|
|
9
9
|
error_key :vagrantfile_exists
|
10
10
|
end
|
11
11
|
|
12
|
-
class
|
13
|
-
error_key :
|
12
|
+
class PiratefileExistsError < PirateError
|
13
|
+
error_key :piratefile_exists
|
14
14
|
end
|
15
15
|
|
16
|
+
class ConfigDirExistsError < PirateError
|
17
|
+
error_key :config_dir_exists
|
18
|
+
end
|
19
|
+
|
20
|
+
class ConfigDirMissingError < PirateError
|
21
|
+
error_key :config_dir_missing
|
22
|
+
end
|
23
|
+
|
24
|
+
class LocalFileExistsError < PirateError
|
25
|
+
error_key :local_file_exists
|
26
|
+
end
|
27
|
+
|
28
|
+
class SymlinkExistsError < PirateError
|
29
|
+
error_key :symlink_exists
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
16
34
|
end
|
17
35
|
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module Pirate
|
2
2
|
# The source root is the path to the root directory of the this gem.
|
3
|
-
def self.
|
4
|
-
@
|
3
|
+
def self.gangway
|
4
|
+
@gangway ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
5
|
+
end
|
6
|
+
|
7
|
+
# The project root directory.
|
8
|
+
# TODO: can we retrive this from Vagrant::Environment?
|
9
|
+
def self.haven
|
10
|
+
@haven ||= Pathname.new(Dir.pwd)
|
5
11
|
end
|
6
12
|
|
7
13
|
# Apply settings loaded from YAML to a vm.
|
@@ -22,49 +28,56 @@ module VagrantPirate
|
|
22
28
|
def self.sail_ho!(first, second)
|
23
29
|
second.each_pair do |k,v|
|
24
30
|
if first[k].is_a?(Hash) and second[k].is_a?(Hash)
|
25
|
-
|
31
|
+
sail_ho!(first[k], second[k])
|
26
32
|
else
|
27
33
|
first[k] = second[k]
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
|
-
|
33
|
-
def self.
|
34
|
-
|
35
|
-
|
38
|
+
# Define our config directories
|
39
|
+
def self.get_map(plunder)
|
40
|
+
dirs = {}
|
36
41
|
# Set defaults
|
37
|
-
|
38
|
-
|
42
|
+
dirs['local'] = ::Pirate.haven.join('local.d')
|
43
|
+
dirs['enabled'] = ::Pirate.haven.join('enabled.d')
|
39
44
|
# Override defaults with config, if it's set, since config finalizing
|
40
45
|
# occurs too late for our purposes.
|
41
46
|
if plunder.pirate.map.is_a?(Hash)
|
42
47
|
if plunder.pirate.map.has_key?('local')
|
43
|
-
|
48
|
+
dirs['local'] = ::Pirate.haven.join(plunder.pirate.map['local'])
|
44
49
|
end
|
45
50
|
if plunder.pirate.map.has_key?('enabled')
|
46
|
-
|
51
|
+
dirs['enabled'] = ::Pirate.haven.join(plunder.pirate.map['enabled'])
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
|
-
#
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# Scan our vms-enabled/ directory for YAML config files
|
57
|
-
if File.directory?(enabled_dir)
|
58
|
-
config_files = Dir.glob("#{enabled_dir}/*.yaml")
|
59
|
-
else
|
60
|
-
raise Errors::EnabledDirMissing,
|
61
|
-
:enabled_dir => enabled_dir
|
55
|
+
# We only check that the 'enabled' directory exists, since the 'local' one
|
56
|
+
# is optional and the existence of the files therein are checked indivi-
|
57
|
+
# dually.
|
58
|
+
if not dirs['enabled'].directory?
|
59
|
+
raise Errors::ConfigDirMissingError, :label => 'enabled',:missing_dir => dirs['enabled']
|
62
60
|
end
|
63
61
|
|
62
|
+
dirs
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.Arrr!(plunder)
|
66
|
+
require "yaml"
|
67
|
+
|
68
|
+
# Get our config directories
|
69
|
+
map = ::Pirate.get_map(plunder)
|
70
|
+
|
71
|
+
# Scan our enabled directory for Piratefiles (YAML config files)
|
72
|
+
config_dirs = Dir.glob(map['enabled'] + '*/')
|
73
|
+
|
64
74
|
# Build up a list of the VMs we'll provision, and their config_files
|
65
75
|
vms = {}
|
66
|
-
|
67
|
-
|
76
|
+
config_dirs.each do |config_dir|
|
77
|
+
piratefile = Pathname.new(config_dir).join('Piratefile')
|
78
|
+
if piratefile.file?
|
79
|
+
vms.update({ File.basename(config_dir) => piratefile})
|
80
|
+
end
|
68
81
|
end
|
69
82
|
|
70
83
|
# VM-specific configuration loaded from YAML config files
|
@@ -74,7 +87,7 @@ module VagrantPirate
|
|
74
87
|
yml = {} if !yml.is_a?(Hash)
|
75
88
|
|
76
89
|
# Allow local overrides
|
77
|
-
local_file = "#{
|
90
|
+
local_file = map['local'] + "#{vm}.yaml"
|
78
91
|
if File.exists?(local_file)
|
79
92
|
local = YAML.load_file local_file
|
80
93
|
sail_ho!(yml, local) if local.is_a?(Hash)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'vagrant-pirate/
|
1
|
+
require 'vagrant-pirate/pirate'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
|
-
module
|
4
|
+
module Pirate
|
5
5
|
class Plugin < Vagrant.plugin("2")
|
6
|
-
name "Yagrant
|
6
|
+
name "Yagrant Pirate"
|
7
7
|
description <<-DESC
|
8
8
|
This plugin enables Vagrant to use YAML files to configure VMs.
|
9
9
|
DESC
|
@@ -19,14 +19,15 @@ module VagrantPlugins
|
|
19
19
|
end
|
20
20
|
|
21
21
|
command("pirate-ship", primary: false) do
|
22
|
-
require_relative "command/
|
23
|
-
Command::
|
22
|
+
require_relative "command/ship"
|
23
|
+
Command::Ship
|
24
24
|
end
|
25
25
|
|
26
|
-
command("pirate-
|
27
|
-
require_relative "command/
|
28
|
-
Command::
|
26
|
+
command("pirate-fleet", primary: false) do
|
27
|
+
require_relative "command/fleet"
|
28
|
+
Command::Fleet
|
29
29
|
end
|
30
|
+
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.
|
1
|
+
module Pirate
|
2
|
+
VERSION = "0.3.0"
|
3
3
|
end
|
data/locales/en.yml
CHANGED
@@ -3,15 +3,22 @@ en:
|
|
3
3
|
plugins:
|
4
4
|
pirate:
|
5
5
|
commands:
|
6
|
+
fleet:
|
7
|
+
success: |-
|
8
|
+
A `Vagrantfile` has been placed in this directory. A default directory containing
|
9
|
+
a Piratefile (Yaml VM config file) has been placed in '%{avail_dir}', and symlinks
|
10
|
+
to it, placed in '%{enabled_dir}'. Finally, files to contain local overrides were
|
11
|
+
placed in '%{local_dir}'. Unlike a regular Vagrantfile, this one parses and applies
|
12
|
+
the configuration in the Piratefiles it finds under '%{enabled_dir}'. You are now
|
13
|
+
ready to `vagrant up` your first virtual environment! Please read the comments in
|
14
|
+
the default Yaml VM config file to see how it works.
|
6
15
|
ship:
|
7
16
|
success: |-
|
8
|
-
A `Vagrantfile`
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
virtual environment! Please read the comments in the default Yaml VM config
|
14
|
-
file to see how it works.
|
17
|
+
A `Vagrantfile` and `Piratefile` (YAML VM config file) have been placed in this
|
18
|
+
directory, along with a symlink to it (that defines the VM name). Unlike a regular
|
19
|
+
Vagrantfile, this one parses and applies the configuration in the Piratefile. You
|
20
|
+
are now ready to `vagrant up` your first virtual environment! Please read the
|
21
|
+
comments in the Piratefile to see how it works.
|
15
22
|
update:
|
16
23
|
success: |-
|
17
24
|
Vagrantfile updated using the latest one from vagrant-pirate.
|
@@ -24,9 +31,20 @@ en:
|
|
24
31
|
errors:
|
25
32
|
vagrantfile_exists: |-
|
26
33
|
`Vagrantfile` already exists in this directory. Remove it before running `vagrant
|
27
|
-
pirate
|
28
|
-
|
34
|
+
pirate %{command}`.
|
35
|
+
piratefile_exists: |-
|
36
|
+
`Piratefile` already exists in '%{this_dir}'.
|
37
|
+
Remove it before running `vagrant pirate %{command}`.
|
38
|
+
config_dir_exists: |-
|
39
|
+
Config directory already exists at '%{this_dir}'.
|
40
|
+
Remove it before running `vagrant pirate %{command}`.
|
41
|
+
config_dir_missing: |-
|
29
42
|
A valid directory must be specified where YAML configs for the VMs can be found.
|
30
|
-
Current config points to a non-existent directory:
|
31
|
-
>>> %{
|
32
|
-
|
43
|
+
Current `%{label}` config points to a non-existent directory:
|
44
|
+
>>> %{missing_dir}
|
45
|
+
local_file_exists: |-
|
46
|
+
Local override file already exists at `%{save_path}`.
|
47
|
+
Remove it before running `vagrant pirate %{command}`.
|
48
|
+
symlink_exists: |-
|
49
|
+
Symlink to available config directory already exists at %{source}.
|
50
|
+
Remove it before running `vagrant pirate %{command}`.
|
data/tasks/cucumber.rake
CHANGED
@@ -7,5 +7,5 @@ desc 'Default task which runs all cucumber tests'
|
|
7
7
|
Coveralls::RakeTask.new
|
8
8
|
task :default => [:features, 'coveralls:push']
|
9
9
|
Cucumber::Rake::Task.new(:features) do |t|
|
10
|
-
t.cucumber_opts = "features --no-source --format pretty"
|
10
|
+
t.cucumber_opts = "features --no-source --format pretty --tags ~@up"
|
11
11
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version.
|
5
|
+
# Don't be touching this, Matey, lest ye send us all down to Dany Jones' locker!
|
6
|
+
VAGRANTFILE_API_VERSION = "2"
|
7
|
+
|
8
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |plunder|
|
9
|
+
|
10
|
+
# Specify the directories in which to look for YAML VM config files.
|
11
|
+
plunder.pirate.map = { 'enabled' => '.' }
|
12
|
+
|
13
|
+
# Load, parse and apply YAML VM configs.
|
14
|
+
Pirate::Arrr!(plunder)
|
15
|
+
|
16
|
+
end
|
data/vagrant-pirate.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/vagrant-pirate/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "vagrant-pirate"
|
6
|
-
s.version =
|
6
|
+
s.version = Pirate::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Christopher Gervais"]
|
9
9
|
s.email = ["chris@ergonlogic.com"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-pirate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Gervais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|
@@ -94,22 +94,25 @@ files:
|
|
94
94
|
- LICENSE
|
95
95
|
- Rakefile
|
96
96
|
- Readme.md
|
97
|
+
- features/fleet.feature
|
97
98
|
- features/help.feature
|
98
99
|
- features/ship.feature
|
100
|
+
- features/step_definitions/vagrant_steps.rb
|
99
101
|
- features/support/env.rb
|
100
102
|
- lib/vagrant-pirate.rb
|
103
|
+
- lib/vagrant-pirate/command/fleet.rb
|
101
104
|
- lib/vagrant-pirate/command/pirate.rb
|
102
|
-
- lib/vagrant-pirate/command/
|
103
|
-
- lib/vagrant-pirate/command/pirate_update.rb
|
105
|
+
- lib/vagrant-pirate/command/ship.rb
|
104
106
|
- lib/vagrant-pirate/config/pirate.rb
|
105
107
|
- lib/vagrant-pirate/errors.rb
|
108
|
+
- lib/vagrant-pirate/pirate.rb
|
106
109
|
- lib/vagrant-pirate/plugin.rb
|
107
|
-
- lib/vagrant-pirate/vagrant-pirate.rb
|
108
110
|
- lib/vagrant-pirate/version.rb
|
109
111
|
- locales/en.yml
|
110
112
|
- tasks/cucumber.rake
|
111
|
-
- templates/
|
112
|
-
- templates/
|
113
|
+
- templates/Piratefile.erb
|
114
|
+
- templates/Vagrantfile_fleet.erb
|
115
|
+
- templates/Vagrantfile_ship.erb
|
113
116
|
- templates/local.yaml.erb
|
114
117
|
- vagrant-pirate.gemspec
|
115
118
|
homepage: https://github.com/PraxisLabs/vagrant-pirate
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'vagrant/util/template_renderer'
|
3
|
-
|
4
|
-
module VagrantPlugins
|
5
|
-
module VagrantPirate
|
6
|
-
module Command
|
7
|
-
class PirateUpdate < Vagrant.plugin("2", :command)
|
8
|
-
def self.synopsis
|
9
|
-
"Updates a YAML-based Vagrant environment."
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute
|
13
|
-
options = {}
|
14
|
-
|
15
|
-
# Boolean whether we should actually go through with the update
|
16
|
-
# or not. This is true only if the "--force" flag is set or if the
|
17
|
-
# user confirms it.
|
18
|
-
do_update = false
|
19
|
-
|
20
|
-
opts = OptionParser.new do |opts|
|
21
|
-
opts.banner = "Usage: vagrant pirate update"
|
22
|
-
|
23
|
-
opts.on("-f", "--force", "Update without confirmation.") do |f|
|
24
|
-
options[:force] = f
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Parse the options
|
29
|
-
argv = parse_options(opts)
|
30
|
-
return if !argv
|
31
|
-
|
32
|
-
if options[:force]
|
33
|
-
do_update = true
|
34
|
-
else
|
35
|
-
choice = nil
|
36
|
-
begin
|
37
|
-
choice = @env.ui.ask(I18n.t("vagrant.plugins.pirate.commands.update.confirmation"))
|
38
|
-
|
39
|
-
rescue Errors::UIExpectsTTY
|
40
|
-
# We raise a more specific error but one which basically
|
41
|
-
# means the same thing.
|
42
|
-
raise Errors::UpdateRequiresForce
|
43
|
-
end
|
44
|
-
do_update = choice.upcase == "Y"
|
45
|
-
end
|
46
|
-
|
47
|
-
if do_update
|
48
|
-
@logger.info("Updating project with latest Vagrantfile from vagrant-pirate.")
|
49
|
-
update
|
50
|
-
else
|
51
|
-
@logger.info("Not updating project since confirmation was declined.")
|
52
|
-
@env.ui.success(I18n.t("vagrant.plugins.pirate.commands.update.will_not_update"),
|
53
|
-
:prefix => false)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def update
|
58
|
-
save_path = @env.cwd.join("Vagrantfile")
|
59
|
-
|
60
|
-
template_path = ::VagrantPirate.source_root.join("templates/Vagrantfile")
|
61
|
-
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
62
|
-
|
63
|
-
# Write out the contents
|
64
|
-
save_path.open("w+") do |f|
|
65
|
-
f.write(contents)
|
66
|
-
end
|
67
|
-
|
68
|
-
@env.ui.info(I18n.t("vagrant.plugins.pirate.commands.update.success"),
|
69
|
-
:prefix => false)
|
70
|
-
|
71
|
-
# Success, exit status 0
|
72
|
-
0
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|