vagrant-hostmaster 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/vagrant/hostmaster.rb +6 -0
- data/lib/vagrant/hostmaster/command/list.rb +33 -0
- data/lib/vagrant/hostmaster/command/remove.rb +31 -0
- data/lib/vagrant/hostmaster/command/root.rb +68 -0
- data/lib/vagrant/hostmaster/command/update.rb +37 -0
- data/lib/vagrant/hostmaster/config.rb +7 -0
- data/lib/vagrant/hostmaster/version.rb +5 -0
- data/lib/vagrant_init.rb +1 -0
- data/vagrant-hostmaster.gemspec +19 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 S. Brent Faulkner
|
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,29 @@
|
|
1
|
+
# Vagrant::Hostmaster
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vagrant-hostmaster'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vagrant-hostmaster
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Hostmaster
|
3
|
+
module Command
|
4
|
+
class List < Vagrant::Command::Base
|
5
|
+
def execute
|
6
|
+
options = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: vagrant hosts list"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Parse the options
|
11
|
+
argv = parse_options(options)
|
12
|
+
return if !argv
|
13
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 0
|
14
|
+
|
15
|
+
with_target_vms do |vm|
|
16
|
+
list vm
|
17
|
+
end
|
18
|
+
|
19
|
+
# Success, exit status 0
|
20
|
+
0
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def list(vm)
|
25
|
+
type, (address, *) = vm.config.vm.networks.first
|
26
|
+
address ||= '127.0.0.1'
|
27
|
+
signature = "# VAGRANT: #{vm.uuid}"
|
28
|
+
system %Q(grep '#{signature}$' /etc/hosts)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Hostmaster
|
3
|
+
module Command
|
4
|
+
class Remove < Vagrant::Command::Base
|
5
|
+
def execute
|
6
|
+
options = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: vagrant hosts remove [<vm-name> [...]]"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Parse the options
|
11
|
+
argv = parse_options(options)
|
12
|
+
return if !argv
|
13
|
+
|
14
|
+
with_target_vms(argv) do |vm|
|
15
|
+
remove vm
|
16
|
+
end
|
17
|
+
|
18
|
+
# Success, exit status 0
|
19
|
+
0
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def remove(vm)
|
24
|
+
@env.ui.info("Removing host entry for #{vm.name} VM. Administrator privileges will be required...", :prefix => false)
|
25
|
+
signature = "# VAGRANT: #{vm.uuid}"
|
26
|
+
system %Q(sudo sed -e '/#{signature}$/ d' -ibak /etc/hosts)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Hostmaster
|
3
|
+
module Command
|
4
|
+
class Root < Vagrant::Command::Base
|
5
|
+
def initialize(argv, env)
|
6
|
+
super
|
7
|
+
|
8
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
9
|
+
|
10
|
+
@subcommands = Vagrant::Registry.new
|
11
|
+
@subcommands.register(:list) do
|
12
|
+
require File.expand_path("../list", __FILE__)
|
13
|
+
List
|
14
|
+
end
|
15
|
+
|
16
|
+
@subcommands.register(:remove) do
|
17
|
+
require File.expand_path("../remove", __FILE__)
|
18
|
+
Remove
|
19
|
+
end
|
20
|
+
|
21
|
+
@subcommands.register(:update) do
|
22
|
+
require File.expand_path("../update", __FILE__)
|
23
|
+
Update
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
29
|
+
# Print the help for all the hosts commands.
|
30
|
+
return help
|
31
|
+
end
|
32
|
+
|
33
|
+
# If we reached this far then we must have a subcommand. If not,
|
34
|
+
# then we also just print the help and exit.
|
35
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
36
|
+
return help if !command_class || !@sub_command
|
37
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
38
|
+
|
39
|
+
# Initialize and execute the command class
|
40
|
+
command_class.new(@sub_args, @env).execute
|
41
|
+
end
|
42
|
+
|
43
|
+
# Prints the help out for this command
|
44
|
+
def help
|
45
|
+
opts = OptionParser.new do |opts|
|
46
|
+
opts.banner = "Usage: vagrant hosts <command> [<args>]"
|
47
|
+
opts.separator ""
|
48
|
+
opts.separator "Available subcommands:"
|
49
|
+
|
50
|
+
# Add the available subcommands as separators in order to print them
|
51
|
+
# out as well.
|
52
|
+
keys = []
|
53
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
54
|
+
|
55
|
+
keys.sort.each do |key|
|
56
|
+
opts.separator " #{key}"
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.separator ""
|
60
|
+
opts.separator "For help on any individual command run `vagrant hosts COMMAND -h`"
|
61
|
+
end
|
62
|
+
|
63
|
+
@env.ui.info(opts.help, :prefix => false)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Hostmaster
|
3
|
+
module Command
|
4
|
+
class Update < Vagrant::Command::Base
|
5
|
+
def execute
|
6
|
+
options = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: vagrant hosts update [<vm-name> [...]]"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Parse the options
|
11
|
+
argv = parse_options(options)
|
12
|
+
return if !argv
|
13
|
+
|
14
|
+
with_target_vms(argv) do |vm|
|
15
|
+
update vm
|
16
|
+
end
|
17
|
+
|
18
|
+
# Success, exit status 0
|
19
|
+
0
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def update(vm)
|
24
|
+
@env.ui.info("Updating host entry for #{vm.name} VM. Administrator privileges will be required...", :prefix => false)
|
25
|
+
type, (address, *) = vm.config.vm.networks.first
|
26
|
+
address ||= '127.0.0.1'
|
27
|
+
signature = "# VAGRANT: #{vm.uuid}"
|
28
|
+
system %Q(sudo sh -c 'sed -e "/#{signature}$/ d" -ibak /etc/hosts')
|
29
|
+
host_names = [vm.config.vm.host_name]
|
30
|
+
host_names += Array(vm.config.hosts.aliases)
|
31
|
+
host_entry = "#{address} #{host_names.join(' ')} #{signature}"
|
32
|
+
system %Q(sudo sh -c 'echo "#{host_entry}" >>/etc/hosts')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/vagrant_init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'vagrant/hostmaster'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/vagrant/hostmaster/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["S. Brent Faulkner"]
|
6
|
+
gem.email = ["brent.faulkner@mosaic.com"]
|
7
|
+
gem.description = %q{Vagrant plugin to modify host and guest hostfiles.}
|
8
|
+
gem.summary = %q{Vagrant plugin to modify host and guest hostfiles.}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "vagrant-hostmaster"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Vagrant::Hostmaster::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency('rake')
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-hostmaster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 2
|
9
|
+
version: 0.6.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- S. Brent Faulkner
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-08-17 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :development
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 0
|
28
|
+
version: "0"
|
29
|
+
name: rake
|
30
|
+
requirement: *id001
|
31
|
+
prerelease: false
|
32
|
+
description: Vagrant plugin to modify host and guest hostfiles.
|
33
|
+
email:
|
34
|
+
- brent.faulkner@mosaic.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- .gitignore
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- lib/vagrant/hostmaster.rb
|
48
|
+
- lib/vagrant/hostmaster/command/list.rb
|
49
|
+
- lib/vagrant/hostmaster/command/remove.rb
|
50
|
+
- lib/vagrant/hostmaster/command/root.rb
|
51
|
+
- lib/vagrant/hostmaster/command/update.rb
|
52
|
+
- lib/vagrant/hostmaster/config.rb
|
53
|
+
- lib/vagrant/hostmaster/version.rb
|
54
|
+
- lib/vagrant_init.rb
|
55
|
+
- vagrant-hostmaster.gemspec
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: ""
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Vagrant plugin to modify host and guest hostfiles.
|
86
|
+
test_files: []
|
87
|
+
|