vagrant-hostmaster 0.6.2 → 0.6.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Vagrant::Hostmaster
1
+ # vagrant-hostmaster
2
2
 
3
- TODO: Write a gem description
3
+ vagrant-hostmaster is a Vagrant plugin to manage /etc/hosts entries on both the host OS and guest VMs.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,32 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Usage: vagrant hosts <command> [<args>]
22
+
23
+ Available subcommands:
24
+ list
25
+ remove
26
+ update
27
+
28
+ For help on any individual command run `vagrant hosts COMMAND -h`
29
+
30
+ ### List Host Entries
31
+
32
+ vagrant hosts list
33
+
34
+ ### Remove Host Entries
35
+
36
+ vagrant hosts remove [<vm-name> [...]]
37
+
38
+ ### Update Host Entries
39
+
40
+ vagrant hosts update [<vm-name> [...]]
41
+
42
+ ## TODO
43
+
44
+ 1. add commands to modify guests
45
+
46
+ 2. add provisioning support so that changes are made automatically
22
47
 
23
48
  ## Contributing
24
49
 
@@ -1,6 +1,7 @@
1
1
  require 'vagrant/hostmaster/version'
2
2
  require 'vagrant/hostmaster/command/root'
3
3
  require 'vagrant/hostmaster/config'
4
+ require 'vagrant/hostmaster/vm'
4
5
 
5
6
  Vagrant.commands.register(:hosts) { Vagrant::Hostmaster::Command::Root }
6
7
  Vagrant.config_keys.register(:hosts) { Vagrant::Hostmaster::Config }
@@ -13,20 +13,12 @@ module Vagrant
13
13
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 0
14
14
 
15
15
  with_target_vms do |vm|
16
- list vm
16
+ Hostmaster::VM.new(vm).list
17
17
  end
18
18
 
19
19
  # Success, exit status 0
20
20
  0
21
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
22
  end
31
23
  end
32
24
  end
@@ -12,19 +12,13 @@ module Vagrant
12
12
  return if !argv
13
13
 
14
14
  with_target_vms(argv) do |vm|
15
- remove vm
15
+ @env.ui.info("Removing host entry for #{vm.name} VM. Administrator privileges will be required...", :prefix => false)
16
+ Hostmaster::VM.new(vm).remove
16
17
  end
17
18
 
18
19
  # Success, exit status 0
19
20
  0
20
21
  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
22
  end
29
23
  end
30
24
  end
@@ -12,25 +12,13 @@ module Vagrant
12
12
  return if !argv
13
13
 
14
14
  with_target_vms(argv) do |vm|
15
- update vm
15
+ @env.ui.info("Updating host entry for #{vm.name} VM. Administrator privileges will be required...", :prefix => false)
16
+ Hostmaster::VM.new(vm).update
16
17
  end
17
18
 
18
19
  # Success, exit status 0
19
20
  0
20
21
  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
22
  end
35
23
  end
36
24
  end
@@ -1,6 +1,7 @@
1
1
  module Vagrant
2
2
  module Hostmaster
3
3
  class Config < Vagrant::Config::Base
4
+ attr_accessor :name
4
5
  attr_accessor :aliases
5
6
  end
6
7
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Hostmaster
3
- VERSION = "0.6.2"
3
+ VERSION = "0.6.12"
4
4
  end
5
5
  end
@@ -0,0 +1,68 @@
1
+ require 'forwardable'
2
+
3
+ module Vagrant
4
+ module Hostmaster
5
+ class VM
6
+ extend Forwardable
7
+
8
+ def_delegators :@vm, :config, :env, :name, :uuid
9
+
10
+ def initialize(vm)
11
+ @vm = vm
12
+ end
13
+
14
+ def add
15
+ sudo %Q(sh -c 'echo "#{host_entry}" >>/etc/hosts')
16
+ end
17
+
18
+ def list
19
+ system %Q(grep '#{signature}$' /etc/hosts)
20
+ end
21
+
22
+ def remove
23
+ sudo %Q(sed -e '/#{signature}$/ d' -ibak /etc/hosts)
24
+ end
25
+
26
+ def update
27
+ remove && add
28
+ end
29
+
30
+ protected
31
+ def address
32
+ @address ||= (addresses && addresses.first || '127.0.0.1')
33
+ end
34
+
35
+ def addresses
36
+ @network_addresses ||= (network && network.last)
37
+ end
38
+
39
+ def host_aliases
40
+ @host_aliases ||= Array(config.hosts.aliases)
41
+ end
42
+
43
+ def host_entry
44
+ @host_entry ||= "#{address} #{host_names.join(' ')} #{signature}"
45
+ end
46
+
47
+ def host_name
48
+ @host_name ||= (config.hosts.name || config.vm.host_name)
49
+ end
50
+
51
+ def host_names
52
+ @host_names ||= (Array(host_name) + host_aliases)
53
+ end
54
+
55
+ def network
56
+ @network ||= config.vm.networks.first
57
+ end
58
+
59
+ def signature
60
+ @signature ||= "# VAGRANT: #{uuid}"
61
+ end
62
+
63
+ def sudo(command)
64
+ system %Q(sudo #{command})
65
+ end
66
+ end
67
+ end
68
+ end
@@ -4,9 +4,9 @@ require File.expand_path('../lib/vagrant/hostmaster/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["S. Brent Faulkner"]
6
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 = ""
7
+ gem.description = %q{vagrant-hostmaster is a Vagrant plugin to manage /etc/hosts entries on both the host OS and guest VMs.}
8
+ gem.summary = %q{Vagrant plugin to manage /etc/hosts entries.}
9
+ gem.homepage = "https://github.com/mosaicxm/vagrant-hostmaster"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,5 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Vagrant::Hostmaster::VERSION
17
17
 
18
+ gem.add_dependency('vagrant', '~>1.0.3')
18
19
  gem.add_development_dependency('rake')
19
20
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 2
9
- version: 0.6.2
8
+ - 12
9
+ version: 0.6.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - S. Brent Faulkner
@@ -14,12 +14,26 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-08-17 00:00:00 -04:00
17
+ date: 2012-08-18 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- type: :development
21
+ type: :runtime
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 1
28
+ - 0
29
+ - 3
30
+ version: 1.0.3
31
+ name: vagrant
32
+ requirement: *id001
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
@@ -27,9 +41,9 @@ dependencies:
27
41
  - 0
28
42
  version: "0"
29
43
  name: rake
30
- requirement: *id001
44
+ requirement: *id002
31
45
  prerelease: false
32
- description: Vagrant plugin to modify host and guest hostfiles.
46
+ description: vagrant-hostmaster is a Vagrant plugin to manage /etc/hosts entries on both the host OS and guest VMs.
33
47
  email:
34
48
  - brent.faulkner@mosaic.com
35
49
  executables: []
@@ -51,10 +65,11 @@ files:
51
65
  - lib/vagrant/hostmaster/command/update.rb
52
66
  - lib/vagrant/hostmaster/config.rb
53
67
  - lib/vagrant/hostmaster/version.rb
68
+ - lib/vagrant/hostmaster/vm.rb
54
69
  - lib/vagrant_init.rb
55
70
  - vagrant-hostmaster.gemspec
56
71
  has_rdoc: true
57
- homepage: ""
72
+ homepage: https://github.com/mosaicxm/vagrant-hostmaster
58
73
  licenses: []
59
74
 
60
75
  post_install_message:
@@ -82,6 +97,6 @@ rubyforge_project:
82
97
  rubygems_version: 1.3.6
83
98
  signing_key:
84
99
  specification_version: 3
85
- summary: Vagrant plugin to modify host and guest hostfiles.
100
+ summary: Vagrant plugin to manage /etc/hosts entries.
86
101
  test_files: []
87
102