vagrant-yaml 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +2 -2
- data/lib/vagrant-yaml.rb +1 -5
- data/lib/vagrant-yaml/command/yaml.rb +69 -0
- data/lib/vagrant-yaml/command/yaml_init.rb +82 -0
- data/lib/vagrant-yaml/command/yaml_update.rb +77 -0
- data/lib/vagrant-yaml/plugin.rb +26 -0
- data/lib/vagrant-yaml/version.rb +1 -1
- metadata +6 -6
- data/lib/vagrant-yaml/commands/yaml.rb +0 -60
- data/lib/vagrant-yaml/commands/yaml_init.rb +0 -79
- data/lib/vagrant-yaml/commands/yaml_update.rb +0 -74
- data/lib/vagrant_init.rb +0 -3
data/Readme.md
CHANGED
data/lib/vagrant-yaml.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'vagrant'
|
2
2
|
require 'vagrant-yaml/errors'
|
3
|
-
require 'vagrant-yaml/
|
4
|
-
require 'vagrant-yaml/commands/yaml_init'
|
5
|
-
require 'vagrant-yaml/commands/yaml_update'
|
6
|
-
|
7
|
-
Vagrant.commands.register(:yaml) { VagrantYaml::Command::Yaml }
|
3
|
+
require 'vagrant-yaml/plugin'
|
8
4
|
|
9
5
|
module VagrantYaml
|
10
6
|
# The source root is the path to the root directory of the this gem.
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VagrantYaml
|
5
|
+
module Command
|
6
|
+
class Yaml < Vagrant.plugin("2", :command)
|
7
|
+
def self.synopsis
|
8
|
+
"Manage YAML-based projects."
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(argv, env)
|
12
|
+
super
|
13
|
+
|
14
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
15
|
+
|
16
|
+
@subcommands = Vagrant::Registry.new
|
17
|
+
@subcommands.register(:init) do
|
18
|
+
require File.expand_path("../yaml_init", __FILE__)
|
19
|
+
YamlInit
|
20
|
+
end
|
21
|
+
|
22
|
+
@subcommands.register(:update) do
|
23
|
+
require File.expand_path("../yaml_update", __FILE__)
|
24
|
+
YamlUpdate
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute
|
29
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
30
|
+
# Print the help for all the box commands.
|
31
|
+
return help
|
32
|
+
end
|
33
|
+
|
34
|
+
# If we reached this far then we must have a subcommand. If not,
|
35
|
+
# then we also just print the help and exit.
|
36
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
37
|
+
return help if !command_class || !@sub_command
|
38
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
39
|
+
|
40
|
+
# Initialize and execute the command class
|
41
|
+
command_class.new(@sub_args, @env).execute
|
42
|
+
end
|
43
|
+
|
44
|
+
# Prints the help out for this command
|
45
|
+
def help
|
46
|
+
opts = OptionParser.new do |opts|
|
47
|
+
opts.banner = "Usage: vagrant yaml <command> [<args>]"
|
48
|
+
opts.separator ""
|
49
|
+
opts.separator "Available subcommands:"
|
50
|
+
|
51
|
+
# Add the available subcommands as separators in order to print them
|
52
|
+
# out as well.
|
53
|
+
keys = []
|
54
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
55
|
+
|
56
|
+
keys.sort.each do |key|
|
57
|
+
opts.separator " #{key}"
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.separator ""
|
61
|
+
opts.separator "For help on any individual command run `vagrant yaml COMMAND -h`"
|
62
|
+
end
|
63
|
+
|
64
|
+
@env.ui.info(opts.help, :prefix => false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant/util/template_renderer'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VagrantYaml
|
6
|
+
module Command
|
7
|
+
class YamlInit < Vagrant.plugin("2", :command)
|
8
|
+
|
9
|
+
def self.synopsis
|
10
|
+
"Initializes a new YAML-based Vagrant environment by creating a Vagrantfile, and config directories."
|
11
|
+
end
|
12
|
+
def execute
|
13
|
+
options = {}
|
14
|
+
|
15
|
+
opts = OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: vagrant yaml init [box-name] [box-url]"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse the options
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return if !argv
|
22
|
+
|
23
|
+
create_vagrantfile
|
24
|
+
create_directories
|
25
|
+
create_default_yaml(argv[0], argv[1])
|
26
|
+
create_local_default_yaml
|
27
|
+
create_symlinks
|
28
|
+
|
29
|
+
@env.ui.info(I18n.t("vagrant.plugins.yaml.commands.init.success"),
|
30
|
+
:prefix => false)
|
31
|
+
# Success, exit status 0
|
32
|
+
0
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_vagrantfile
|
36
|
+
save_path = @env.cwd.join("Vagrantfile")
|
37
|
+
raise Errors::VagrantfileExistsError if save_path.exist?
|
38
|
+
|
39
|
+
template_path = ::VagrantYaml.source_root.join("templates/Vagrantfile")
|
40
|
+
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
41
|
+
save_path.open("w+") do |f|
|
42
|
+
f.write(contents)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_directories
|
47
|
+
Dir.mkdir('vms-available')
|
48
|
+
Dir.mkdir('vms-enabled')
|
49
|
+
Dir.mkdir('local.d')
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_default_yaml(box_name=nil, box_url=nil)
|
53
|
+
save_path = @env.cwd.join("vms-available/default.yaml")
|
54
|
+
raise Errors::VagrantfileExistsError if save_path.exist?
|
55
|
+
|
56
|
+
template_path = ::VagrantYaml.source_root.join("templates/default.yaml")
|
57
|
+
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
58
|
+
:box_name => box_name,
|
59
|
+
:box_url => box_url)
|
60
|
+
save_path.open("w+") do |f|
|
61
|
+
f.write(contents)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_local_default_yaml
|
66
|
+
save_path = @env.cwd.join("local.d/default.yaml")
|
67
|
+
raise Errors::VagrantfileExistsError if save_path.exist?
|
68
|
+
template_path = ::VagrantYaml.source_root.join("templates/local.default.yaml")
|
69
|
+
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
70
|
+
save_path.open("w+") do |f|
|
71
|
+
f.write(contents)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_symlinks
|
76
|
+
File.symlink("../vms-available/default.yaml", "vms-enabled/default.yaml")
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant/util/template_renderer'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VagrantYaml
|
6
|
+
module Command
|
7
|
+
class YamlUpdate < 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 yaml 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.yaml.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-yaml.")
|
49
|
+
update
|
50
|
+
else
|
51
|
+
@logger.info("Not updating project since confirmation was declined.")
|
52
|
+
@env.ui.success(I18n.t("vagrant.plugins.yaml.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 = ::VagrantYaml.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.yaml.commands.update.success"),
|
69
|
+
:prefix => false)
|
70
|
+
|
71
|
+
# Success, exit status 0
|
72
|
+
0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VagrantYaml
|
3
|
+
class Plugin < Vagrant.plugin("2")
|
4
|
+
name "Yagrant YAML"
|
5
|
+
description <<-DESC
|
6
|
+
This plugin enables Vagrant to use YAML files to configure VMs.
|
7
|
+
DESC
|
8
|
+
|
9
|
+
command("yaml") do
|
10
|
+
require_relative "command/yaml"
|
11
|
+
Command::Yaml
|
12
|
+
end
|
13
|
+
|
14
|
+
command("yaml-init", primary: false) do
|
15
|
+
require_relative "command/yaml_init"
|
16
|
+
Command::YamlInit
|
17
|
+
end
|
18
|
+
|
19
|
+
command("yaml-update", primary: false) do
|
20
|
+
require_relative "command/yaml_update"
|
21
|
+
Command::YamlUpdate
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/vagrant-yaml/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -41,12 +41,12 @@ files:
|
|
41
41
|
- LICENSE
|
42
42
|
- Readme.md
|
43
43
|
- lib/vagrant-yaml.rb
|
44
|
-
- lib/vagrant-yaml/
|
45
|
-
- lib/vagrant-yaml/
|
46
|
-
- lib/vagrant-yaml/
|
44
|
+
- lib/vagrant-yaml/command/yaml.rb
|
45
|
+
- lib/vagrant-yaml/command/yaml_init.rb
|
46
|
+
- lib/vagrant-yaml/command/yaml_update.rb
|
47
47
|
- lib/vagrant-yaml/errors.rb
|
48
|
+
- lib/vagrant-yaml/plugin.rb
|
48
49
|
- lib/vagrant-yaml/version.rb
|
49
|
-
- lib/vagrant_init.rb
|
50
50
|
- locales/en.yml
|
51
51
|
- templates/Vagrantfile.erb
|
52
52
|
- templates/default.yaml.erb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'vagrant/util/template_renderer'
|
3
|
-
require 'vagrant/command/base'
|
4
|
-
|
5
|
-
module VagrantYaml
|
6
|
-
module Command
|
7
|
-
|
8
|
-
class Yaml < Vagrant::Command::Base
|
9
|
-
def initialize(argv, env)
|
10
|
-
super
|
11
|
-
|
12
|
-
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
13
|
-
|
14
|
-
@subcommands = Vagrant::Registry.new
|
15
|
-
@subcommands.register(:init) { VagrantYaml::Command::YamlInit }
|
16
|
-
@subcommands.register(:update) { VagrantYaml::Command::YamlUpdate }
|
17
|
-
end
|
18
|
-
|
19
|
-
def execute
|
20
|
-
if @main_args.include?("-h") || @main_args.include?("--help")
|
21
|
-
# Print the help for all the box commands.
|
22
|
-
return help
|
23
|
-
end
|
24
|
-
|
25
|
-
# If we reached this far then we must have a subcommand. If not,
|
26
|
-
# then we also just print the help and exit.
|
27
|
-
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
28
|
-
return help if !command_class || !@sub_command
|
29
|
-
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
30
|
-
|
31
|
-
# Initialize and execute the command class
|
32
|
-
command_class.new(@sub_args, @env).execute
|
33
|
-
end
|
34
|
-
|
35
|
-
# Prints the help out for this command
|
36
|
-
def help
|
37
|
-
opts = OptionParser.new do |opts|
|
38
|
-
opts.banner = "Usage: vagrant yaml <command> [<args>]"
|
39
|
-
opts.separator ""
|
40
|
-
opts.separator "Available subcommands:"
|
41
|
-
|
42
|
-
# Add the available subcommands as separators in order to print them
|
43
|
-
# out as well.
|
44
|
-
keys = []
|
45
|
-
@subcommands.each { |key, value| keys << key.to_s }
|
46
|
-
|
47
|
-
keys.sort.each do |key|
|
48
|
-
opts.separator " #{key}"
|
49
|
-
end
|
50
|
-
|
51
|
-
opts.separator ""
|
52
|
-
opts.separator "For help on any individual command run `vagrant yaml COMMAND -h`"
|
53
|
-
end
|
54
|
-
|
55
|
-
@env.ui.info(opts.help, :prefix => false)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'vagrant/util/template_renderer'
|
3
|
-
require 'vagrant/command/base'
|
4
|
-
|
5
|
-
module VagrantYaml
|
6
|
-
module Command
|
7
|
-
|
8
|
-
class YamlInit < Vagrant::Command::Base
|
9
|
-
def execute
|
10
|
-
options = {}
|
11
|
-
|
12
|
-
opts = OptionParser.new do |opts|
|
13
|
-
opts.banner = "Usage: vagrant yaml init [box-name] [box-url]"
|
14
|
-
end
|
15
|
-
|
16
|
-
# Parse the options
|
17
|
-
argv = parse_options(opts)
|
18
|
-
return if !argv
|
19
|
-
|
20
|
-
create_vagrantfile
|
21
|
-
create_directories
|
22
|
-
create_default_yaml(argv[0], argv[1])
|
23
|
-
create_local_default_yaml
|
24
|
-
create_symlinks
|
25
|
-
|
26
|
-
@env.ui.info(I18n.t("vagrant.plugins.yaml.commands.init.success"),
|
27
|
-
:prefix => false)
|
28
|
-
# Success, exit status 0
|
29
|
-
0
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_vagrantfile
|
33
|
-
save_path = @env.cwd.join("Vagrantfile")
|
34
|
-
raise Errors::VagrantfileExistsError if save_path.exist?
|
35
|
-
|
36
|
-
template_path = ::VagrantYaml.source_root.join("templates/Vagrantfile")
|
37
|
-
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
38
|
-
save_path.open("w+") do |f|
|
39
|
-
f.write(contents)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def create_directories
|
44
|
-
Dir.mkdir('vms-available')
|
45
|
-
Dir.mkdir('vms-enabled')
|
46
|
-
Dir.mkdir('local.d')
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_default_yaml(box_name=nil, box_url=nil)
|
50
|
-
save_path = @env.cwd.join("vms-available/default.yaml")
|
51
|
-
raise Errors::VagrantfileExistsError if save_path.exist?
|
52
|
-
|
53
|
-
template_path = ::VagrantYaml.source_root.join("templates/default.yaml")
|
54
|
-
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
55
|
-
:box_name => box_name,
|
56
|
-
:box_url => box_url)
|
57
|
-
save_path.open("w+") do |f|
|
58
|
-
f.write(contents)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def create_local_default_yaml
|
63
|
-
save_path = @env.cwd.join("local.d/default.yaml")
|
64
|
-
raise Errors::VagrantfileExistsError if save_path.exist?
|
65
|
-
template_path = ::VagrantYaml.source_root.join("templates/local.default.yaml")
|
66
|
-
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
67
|
-
save_path.open("w+") do |f|
|
68
|
-
f.write(contents)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def create_symlinks
|
73
|
-
File.symlink("../vms-available/default.yaml", "vms-enabled/default.yaml")
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'vagrant/util/template_renderer'
|
3
|
-
require 'vagrant/command/base'
|
4
|
-
|
5
|
-
module VagrantYaml
|
6
|
-
module Command
|
7
|
-
|
8
|
-
class YamlUpdate < Vagrant::Command::Base
|
9
|
-
def execute
|
10
|
-
options = {}
|
11
|
-
|
12
|
-
# Boolean whether we should actually go through with the update
|
13
|
-
# or not. This is true only if the "--force" flag is set or if the
|
14
|
-
# user confirms it.
|
15
|
-
do_update = false
|
16
|
-
|
17
|
-
opts = OptionParser.new do |opts|
|
18
|
-
opts.banner = "Usage: vagrant yaml update"
|
19
|
-
|
20
|
-
opts.on("-f", "--force", "Update without confirmation.") do |f|
|
21
|
-
options[:force] = f
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Parse the options
|
26
|
-
argv = parse_options(opts)
|
27
|
-
return if !argv
|
28
|
-
|
29
|
-
if options[:force]
|
30
|
-
do_update = true
|
31
|
-
else
|
32
|
-
choice = nil
|
33
|
-
begin
|
34
|
-
choice = @env.ui.ask(I18n.t("vagrant.plugins.yaml.commands.update.confirmation"))
|
35
|
-
|
36
|
-
rescue Errors::UIExpectsTTY
|
37
|
-
# We raise a more specific error but one which basically
|
38
|
-
# means the same thing.
|
39
|
-
raise Errors::UpdateRequiresForce
|
40
|
-
end
|
41
|
-
do_update = choice.upcase == "Y"
|
42
|
-
end
|
43
|
-
|
44
|
-
if do_update
|
45
|
-
@logger.info("Updating project with latest Vagrantfile from vagrant-yaml.")
|
46
|
-
update
|
47
|
-
else
|
48
|
-
@logger.info("Not updating project since confirmation was declined.")
|
49
|
-
@env.ui.success(I18n.t("vagrant.plugins.yaml.commands.update.will_not_update"),
|
50
|
-
:prefix => false)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def update
|
55
|
-
save_path = @env.cwd.join("Vagrantfile")
|
56
|
-
|
57
|
-
template_path = ::VagrantYaml.source_root.join("templates/Vagrantfile")
|
58
|
-
contents = Vagrant::Util::TemplateRenderer.render(template_path)
|
59
|
-
|
60
|
-
# Write out the contents
|
61
|
-
save_path.open("w+") do |f|
|
62
|
-
f.write(contents)
|
63
|
-
end
|
64
|
-
|
65
|
-
@env.ui.info(I18n.t("vagrant.plugins.yaml.commands.update.success"),
|
66
|
-
:prefix => false)
|
67
|
-
|
68
|
-
# Success, exit status 0
|
69
|
-
0
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
data/lib/vagrant_init.rb
DELETED