vagrant-ghost 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f7324291014420cc8974f67bb919306781d56f0
4
- data.tar.gz: b0731e3ac2351f218d35db97edf5bb813c361cd3
3
+ metadata.gz: 1b1272341d9841d5f7da7d21cac09cb20fdaca5c
4
+ data.tar.gz: 68a981863d585cde147053db205a1666ae4672c2
5
5
  SHA512:
6
- metadata.gz: 8089840cbdc356d96e42bce47c1afe082f7112f128581199757ab5f900349edca85820bc3eee5ff696e9e728472d6d76593878170638b67681b9c11dd0fdf8b7
7
- data.tar.gz: dc16f9a522dfb027f1a81cbc46641f76d1bd22c1df6146689ac6bc351a1395b3d248f2b81e3c8307468934979bb7689e04f87e56ea918177fe4ad3e9c7304015
6
+ metadata.gz: 9a75231f462e4f1d99c96d792377eff33a4259ae198593244305eee6c22fe5762d93a7bad3ddf50b8f4635c2938e9c3fd0a13bb2be9933dd4a80d47eb496e4bc
7
+ data.tar.gz: 0e105a8cddafa500fd491409a00ac2be9463fc09cb87cec329ccf433383cb1cbf145d1d058efb949df8b8300bdd3712a145ce4aeb4127399d46af4d382685594
data/.gitignore CHANGED
@@ -1,23 +1,7 @@
1
- .idea
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- *.bundle
20
- *.so
21
- *.o
22
- *.a
23
- mkmf.log
1
+ *gem
2
+ .bindle
3
+ .config
4
+ Gemfile.lock
5
+ doc
6
+ pkg
7
+ .idea
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- #gemspec
3
+ # Specify your gem's dependencies in vagrant-ghost.gemspec
4
+ gemspec
4
5
 
5
6
  group :development do
6
7
  gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
@@ -8,4 +9,4 @@ end
8
9
 
9
10
  group :plugins do
10
11
  gem "vagrant-ghost", path: "."
11
- end
12
+ end
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2015 Eric Mann
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 10up, John P Bloch, Eric Mann
4
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:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
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.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,29 +1,43 @@
1
1
  # Vagrant::Ghost
2
2
 
3
- TODO: Write a gem description
4
-
3
+ This plugin adds an entry to your /etc/hosts file on the host system.
4
+
5
+ On **up**, **resume** and **reload** commands, it tries to add the information, if its not already in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
6
+
7
+ On **halt**, **destroy**, and **suspend** those entries will be removed again.
8
+
5
9
  ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'vagrant-ghost'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install vagrant-ghost
18
-
10
+
11
+ $ vagrant plugin install vagrant-ghost
12
+
13
+ Uninstall it with:
14
+
15
+ $ vagrant plugin uninstall vagrant-ghost
16
+
19
17
  ## Usage
20
-
21
- TODO: Write usage instructions here
18
+
19
+ At the moment, the only things you need, are the hostname and a :private_network network with a fixed ip.
20
+
21
+ config.vm.network :private_network, ip: "192.168.3.10"
22
+ config.vm.hostname = "www.testing.de"
23
+ config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
24
+
25
+ This ip and the hostname will be used for the entry in the /etc/hosts file.
26
+
27
+ ## Changelog
28
+
29
+ ### 0.1.0
30
+ * Initial release
22
31
 
23
32
  ## Contributing
24
33
 
25
- 1. Fork it ( https://github.com/[my-github-username]/vagrant-ghost/fork )
34
+ 1. Fork it
26
35
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
36
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
37
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
38
+ 5. Create new Pull Request
39
+
40
+ ## Credits
41
+
42
+ This is a fork of [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater).
43
+ ```
data/Rakefile CHANGED
@@ -1,4 +1,2 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'bundler/gem_tasks'
4
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module Ghost
3
+ module Action
4
+ class CacheHosts
5
+ include Ghost
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @machine = env[:machine]
10
+ end
11
+
12
+ def call(env)
13
+ cacheHostEntries
14
+ @app.call(env)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Ghost
3
+ module Action
4
+ class RemoveHosts
5
+ include Ghost
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @machine = env[:machine]
10
+ @ui = env[:ui]
11
+ end
12
+
13
+ def call(env)
14
+ @ui.info "Removing hosts"
15
+ removeHostEntries
16
+ @app.call(env)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "../Ghost"
2
+ module VagrantPlugins
3
+ module Ghost
4
+ module Action
5
+ class UpdateHosts
6
+ include Ghost
7
+
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @ui = env[:ui]
13
+ end
14
+
15
+ def call(env)
16
+ @ui.info "Checking for host entries"
17
+ @app.call(env)
18
+ addHostEntries()
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,130 @@
1
+ module VagrantPlugins
2
+ module Ghost
3
+ module Ghost
4
+ @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
5
+
6
+ def getIps
7
+ ips = []
8
+ @machine.config.vm.networks.each do |network|
9
+ key, options = network[0], network[1]
10
+ ip = options[:ip] if key == :private_network
11
+ ips.push(ip) if ip
12
+ end
13
+
14
+ begin
15
+ network = @machine.provider.driver.read_guest_ip
16
+ if network['ip']
17
+ ips.push( network['ip'] ) unless ips.include? network['ip']
18
+ end
19
+ rescue
20
+ end
21
+
22
+ return ips
23
+ end
24
+
25
+ def getHostnames
26
+ hostnames = Array(@machine.config.vm.hostname)
27
+ if @machine.config.ghost.aliases
28
+ hostnames.concat(@machine.config.ghost.aliases)
29
+ end
30
+ return hostnames
31
+ end
32
+
33
+ def addHostEntries
34
+ ips = getIps
35
+ hostnames = getHostnames
36
+ file = File.open(@@hosts_path, "rb")
37
+ hostsContents = file.read
38
+ uuid = @machine.id
39
+ name = @machine.name
40
+ entries = []
41
+ ips.each do |ip|
42
+ hostEntries = getHostEntries(ip, hostnames, name, uuid)
43
+ hostEntries.each do |hostEntry|
44
+ escapedEntry = Regexp.quote(hostEntry)
45
+ if !hostsContents.match(/#{escapedEntry}/)
46
+ @ui.info "adding to (#@@hosts_path) : #{hostEntry}"
47
+ entries.push(hostEntry)
48
+ end
49
+ end
50
+ end
51
+ addToHosts(entries)
52
+ end
53
+
54
+ def cacheHostEntries
55
+ @machine.config.ghost.id = @machine.id
56
+ end
57
+
58
+ def removeHostEntries
59
+ if !@machine.id and !@machine.config.ghost.id
60
+ @ui.warn "No machine id, nothing removed from #@@hosts_path"
61
+ return
62
+ end
63
+ file = File.open(@@hosts_path, "rb")
64
+ hostsContents = file.read
65
+ uuid = @machine.id || @machine.config.ghost.id
66
+ hashedId = Digest::MD5.hexdigest(uuid)
67
+ if hostsContents.match(/#{hashedId}/)
68
+ removeFromHosts
69
+ end
70
+ end
71
+
72
+ def host_entry(ip, hostnames, name, uuid = self.uuid)
73
+ %Q(#{ip} #{hostnames.join(' ')} #{signature(name, uuid)})
74
+ end
75
+
76
+ def getHostEntries(ip, hostnames, name, uuid = self.uuid)
77
+ entries = []
78
+ hostnames.each do |hostname|
79
+ entries.push(%Q(#{ip} #{hostname} #{signature(name, uuid)}))
80
+ end
81
+ return entries
82
+ end
83
+
84
+ def addToHosts(entries)
85
+ return if entries.length == 0
86
+ content = entries.join("\n").strip
87
+ if !File.writable?(@@hosts_path)
88
+ sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
89
+ else
90
+ content = "\n" + content
91
+ hostsFile = File.open(@@hosts_path, "a")
92
+ hostsFile.write(content)
93
+ hostsFile.close()
94
+ end
95
+ end
96
+
97
+ def removeFromHosts(options = {})
98
+ uuid = @machine.id || @machine.config.ghost.id
99
+ hashedId = Digest::MD5.hexdigest(uuid)
100
+ if !File.writable?(@@hosts_path)
101
+ sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
102
+ else
103
+ hosts = ""
104
+ File.open(@@hosts_path).each do |line|
105
+ hosts << line unless line.include?(hashedId)
106
+ end
107
+ hostsFile = File.open(@@hosts_path, "w")
108
+ hostsFile.write(hosts)
109
+ hostsFile.close()
110
+ end
111
+ end
112
+
113
+
114
+
115
+ def signature(name, uuid = self.uuid)
116
+ hashedId = Digest::MD5.hexdigest(uuid)
117
+ %Q(# VAGRANT: #{hashedId} (#{name}) / #{uuid})
118
+ end
119
+
120
+ def sudo(command)
121
+ return if !command
122
+ if Vagrant::Util::Platform.windows?
123
+ `#{command}`
124
+ else
125
+ `sudo #{command}`
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,52 @@
1
+ module VagrantPlugins
2
+ module Ghost
3
+ class Command < Vagrant.plugin('2', :command)
4
+ include Ghost
5
+
6
+ def execute
7
+ options = {}
8
+ opts = OptionParser.new do |o|
9
+ o.banner = 'Usage: vagrant ghost [vm-name]'
10
+ o.separator ''
11
+
12
+ o.on('--provider provider', String, 'Update machines with the specific provider.') do |provider|
13
+ options[:provider] = provider
14
+ end
15
+ end
16
+
17
+ argv = parse_options(opts)
18
+ options[:provider] ||= @env.default_provider
19
+
20
+ @ui = @env.ui
21
+
22
+ with_target_vms(argv, options) do |machine|
23
+ @machine = machine
24
+
25
+ # Always remove hosts to make sure old entries don't stick around
26
+ removeHostEntries
27
+ # Add all hosts again if the vm is up
28
+ addHostEntries if is_running?
29
+ end
30
+ 0
31
+ rescue Exception => e
32
+ @env.ui.error "Something went wrong!"
33
+ @env.ui.error " #{e.message}"
34
+ @env.ui.error " #{e.backtrace.inspect}"
35
+ 1
36
+ end
37
+
38
+ protected
39
+
40
+ def is_running?(machine=nil)
41
+ machine ||= @machine
42
+
43
+ case machine.provider_name.to_sym
44
+ when :hyperv, :virtualbox
45
+ return :running == machine.state.id
46
+ end
47
+
48
+ false
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,10 +1,10 @@
1
- module VagrantPlugins
2
- module Ghost
3
- class Config < Vagrant.plugin( 2, :config )
4
- attr_accessor :name
5
- attr_accessor :aliases
6
- attr_accessor :id
7
- attr_accessor :remove_on_suspend
8
- end
9
- end
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module Ghost
5
+ class Config < Vagrant.plugin("2", :config)
6
+ attr_accessor :aliases
7
+ attr_accessor :id
8
+ end
9
+ end
10
10
  end
@@ -0,0 +1,53 @@
1
+ require "vagrant-ghost/Action/UpdateHosts"
2
+ require "vagrant-ghost/Action/CacheHosts"
3
+ require "vagrant-ghost/Action/RemoveHosts"
4
+
5
+ module VagrantPlugins
6
+ module Ghost
7
+ class Plugin < Vagrant.plugin('2')
8
+ name 'Ghost'
9
+ description <<-DESC
10
+ This plugin manages your hosts files internally and externally
11
+ DESC
12
+
13
+ config(:ghost) do
14
+ require_relative 'config'
15
+ Config
16
+ end
17
+
18
+ action_hook(:ghost, :machine_action_up) do |hook|
19
+ hook.append(Action::UpdateHosts)
20
+ end
21
+
22
+ action_hook(:ghost, :machine_action_halt) do |hook|
23
+ hook.append(Action::RemoveHosts)
24
+ end
25
+
26
+ action_hook(:ghost, :machine_action_suspend) do |hook|
27
+ hook.append(Action::RemoveHosts)
28
+ end
29
+
30
+ action_hook(:ghost, :machine_action_destroy) do |hook|
31
+ hook.prepend(Action::CacheHosts)
32
+ end
33
+
34
+ action_hook(:ghost, :machine_action_destroy) do |hook|
35
+ hook.append(Action::RemoveHosts)
36
+ end
37
+
38
+ action_hook(:ghost, :machine_action_reload) do |hook|
39
+ hook.prepend(Action::RemoveHosts)
40
+ hook.append(Action::UpdateHosts)
41
+ end
42
+
43
+ action_hook(:ghost, :machine_action_resume) do |hook|
44
+ hook.append(Action::UpdateHosts)
45
+ end
46
+
47
+ command(:ghost, primary: false) do
48
+ require_relative 'command'
49
+ Command
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Ghost
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/lib/vagrant-ghost.rb CHANGED
@@ -1,49 +1,10 @@
1
- begin
2
- require 'vagrant'
3
- rescue LoadError
4
- raise 'The Vagrant Ghost plugin must be run within Vagrant.'
5
- end
6
-
7
- require 'vagrant-ghost/version'
8
- require 'vagrant-ghost/vm'
9
- require 'vagrant-ghost/middleware/remove'
10
- require 'vagrant-ghost/middleware/update'
1
+ require "vagrant-ghost/version"
2
+ require "vagrant-ghost/plugin"
11
3
 
12
4
  module VagrantPlugins
13
5
  module Ghost
14
- class Plugin < Vagrant.plugin( 2 )
15
- name 'Ghost'
16
- description <<-DESC
17
- Something something something
18
- DESC
19
-
20
- config( :ghost ) do
21
- require 'vagrant-ghost/config'
22
- Ghost::Config
23
- end
24
-
25
- action_hook( :ghost, :machine_action_destroy ) do |hook|
26
- hook.append( Ghost::Middleware::Remove )
27
- end
28
-
29
- action_hook( :ghost, :machine_action_up ) do |hook|
30
- hook.append( Vagrant::Action::VM::Provision, Ghost::Middleware::Update )
31
- end
32
-
33
- action_hook( :ghost, :machine_action_reload ) do |hook|
34
- hook.append( Ghost::Middleware::Update )
35
- end
36
-
37
- action_hook( :ghost, :machine_action_resume ) do |hook|
38
- hook.append( Ghost::Middleware::Update )
39
- end
40
-
41
- command( 'ghost' ) do
42
- require 'vagrant-ghost/command/root'
43
- require 'vagrant-ghost/command/base'
44
-
45
- Command::Root
46
- end
47
- end
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
+ end
48
9
  end
49
10
  end
@@ -6,54 +6,23 @@ require 'vagrant-ghost/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "vagrant-ghost"
8
8
  spec.version = VagrantPlugins::Ghost::VERSION
9
- spec.platform = Gem::Platform::RUBY
10
- spec.authors = ["Eric Mann"]
11
- spec.email = ["eric@eamann.com"]
12
- spec.summary = %q{Vagrant plugin to manage /etc/hosts}
13
- spec.description = %q{Vagrant plugin to manage /etc/hosts}
14
- spec.homepage = "https://github.com/ericmann/vagrant-ghost"
15
- spec.license = "MIT"
16
-
17
- #spec.files = `git ls-files -z`.split("\x0")
18
- #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- #spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.6"
23
- spec.add_development_dependency "rake"
9
+ spec.authors = ["John P Bloch", "Eric Mann"]
10
+ spec.email = ["john.bloch@10up.com","eric.mann@10up.com"]
24
11
 
25
- # The following block of code determines the files that should be included
26
- # in the gem. It does this by reading all the files in the directory where
27
- # this gemspec is, and parsing out the ignored files from the gitignore.
28
- # Note that the entire gitignore(5) syntax is not supported, specifically
29
- # the "!" syntax, but it should mostly work correctly.
30
- root_path = File.dirname(__FILE__)
31
- all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
32
- all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
33
- gitignore_path = File.join(root_path, ".gitignore")
34
- gitignore = File.readlines(gitignore_path)
35
- gitignore.map! { |line| line.chomp.strip }
36
- gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
12
+ if spec.respond_to?(:metadata)
13
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ end
37
15
 
38
- unignored_files = all_files.reject do |file|
39
- # Ignore any directories, the gemspec only cares about files
40
- next true if File.directory?(file)
16
+ spec.summary = "Update Hosts"
17
+ spec.description = "Update hosts"
18
+ spec.homepage = "https://github.com/10up/vagrant-ghost"
19
+ spec.license = "MIT"
41
20
 
42
- # Ignore any paths that match anything in the gitignore. We do
43
- # two tests here:
44
- #
45
- # - First, test to see if the entire path matches the gitignore.
46
- # - Second, match if the basename does, this makes it so that things
47
- # like '.DS_Store' will match sub-directories too (same behavior
48
- # as git).
49
- #
50
- gitignore.any? do |ignore|
51
- File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
52
- File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
53
- end
54
- end
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
55
25
 
56
- spec.files = unignored_files
57
- spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
58
- spec.require_path = 'lib'
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 10.0"
59
28
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ghost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
+ - John P Bloch
7
8
  - Eric Mann
8
9
  autorequire:
9
- bindir: bin
10
+ bindir: exe
10
11
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
12
+ date: 2015-03-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -16,56 +17,57 @@ dependencies:
16
17
  requirements:
17
18
  - - ~>
18
19
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
+ version: '1.7'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - ~>
25
26
  - !ruby/object:Gem::Version
26
- version: '1.6'
27
+ version: '1.7'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ~>
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: '10.0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ~>
39
40
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Vagrant plugin to manage /etc/hosts
41
+ version: '10.0'
42
+ description: Update hosts
42
43
  email:
43
- - eric@eamann.com
44
+ - john.bloch@10up.com
45
+ - eric.mann@10up.com
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
47
49
  files:
50
+ - .gitignore
48
51
  - Gemfile
49
- - lib/vagrant-ghost/command/base.rb
50
- - lib/vagrant-ghost/command/list.rb
51
- - lib/vagrant-ghost/command/remove.rb
52
- - lib/vagrant-ghost/command/root.rb
53
- - lib/vagrant-ghost/command/update.rb
54
- - lib/vagrant-ghost/config.rb
55
- - lib/vagrant-ghost/middleware/remove.rb
56
- - lib/vagrant-ghost/middleware/update.rb
57
- - lib/vagrant-ghost/version.rb
58
- - lib/vagrant-ghost/vm.rb
59
- - lib/vagrant-ghost.rb
60
52
  - LICENSE.txt
61
- - Rakefile
62
53
  - README.md
54
+ - Rakefile
55
+ - lib/vagrant-ghost.rb
56
+ - lib/vagrant-ghost/Action/CacheHosts.rb
57
+ - lib/vagrant-ghost/Action/RemoveHosts.rb
58
+ - lib/vagrant-ghost/Action/UpdateHosts.rb
59
+ - lib/vagrant-ghost/Ghost.rb
60
+ - lib/vagrant-ghost/command.rb
61
+ - lib/vagrant-ghost/config.rb
62
+ - lib/vagrant-ghost/plugin.rb
63
+ - lib/vagrant-ghost/version.rb
63
64
  - vagrant-ghost.gemspec
64
- - .gitignore
65
- homepage: https://github.com/ericmann/vagrant-ghost
65
+ homepage: https://github.com/10up/vagrant-ghost
66
66
  licenses:
67
67
  - MIT
68
- metadata: {}
68
+ metadata:
69
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'' to prevent pushes to
70
+ rubygems.org, or delete to allow pushes to any server.'
69
71
  post_install_message:
70
72
  rdoc_options: []
71
73
  require_paths:
@@ -85,5 +87,5 @@ rubyforge_project:
85
87
  rubygems_version: 2.0.14
86
88
  signing_key:
87
89
  specification_version: 4
88
- summary: Vagrant plugin to manage /etc/hosts
90
+ summary: Update Hosts
89
91
  test_files: []
@@ -1,32 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Command
4
- class Base < Vagrant.plugin( 2, :command )
5
- def execute
6
- sub_command = self.class.name.split('::').last.downcase
7
-
8
- parser = OptionParser.new do |opts|
9
- opts.banner = "Usage: vagrant ghost #{sub_command} [vm-name]"
10
- end
11
-
12
- # Parse the options
13
- argv = parse_options(parser)
14
- return if !argv
15
-
16
- with_target_vms(argv) do |vm|
17
- if vm.state == :running
18
- Ghost::VM.new(vm).send sub_command.to_sym
19
- elsif vm.created?
20
- vm.ui.info I18n.t("vagrant.commands.common.vm_not_running")
21
- else
22
- vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
23
- end
24
- end
25
-
26
- # Success, exit status 0
27
- 0
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,8 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Command
4
- class List < Ghost::Command::Base
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Command
4
- class Remove < Ghost::Command::Base
5
- end
6
- end
7
- end
8
- end
@@ -1,72 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Command
4
- class Root < Vagrant.plugin( 2, :command )
5
- def self.synopsis
6
- "manages hosts file: addition, removal, etc."
7
- end
8
-
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(:list) do
16
- require File.expand_path("../list", __FILE__)
17
- List
18
- end
19
-
20
- @subcommands.register(:remove) do
21
- require File.expand_path("../remove", __FILE__)
22
- Remove
23
- end
24
-
25
- @subcommands.register(:update) do
26
- require File.expand_path("../update", __FILE__)
27
- Update
28
- end
29
- end
30
-
31
- def execute
32
- if @main_args.include?("-h") || @main_args.include?("--help")
33
- # Print the help for all the hosts commands.
34
- return help
35
- end
36
-
37
- # If we reached this far then we must have a subcommand. If not,
38
- # then we also just print the help and exit.
39
- command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
40
- return help if !command_class || !@sub_command
41
- @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
42
-
43
- # Initialize and execute the command class
44
- command_class.new(@sub_args, @env).execute
45
- end
46
-
47
- # Prints the help out for this command
48
- def help
49
- opts = OptionParser.new do |opts|
50
- opts.banner = "Usage: vagrant ghost <command> [<args>]"
51
- opts.separator ""
52
- opts.separator "Available subcommands:"
53
-
54
- # Add the available subcommands as separators in order to print them
55
- # out as well.
56
- keys = []
57
- @subcommands.each { |key, value| keys << key.to_s }
58
-
59
- keys.sort.each do |key|
60
- opts.separator " #{key}"
61
- end
62
-
63
- opts.separator ""
64
- opts.separator "For help on any individual command run `vagrant ghost COMMAND -h`"
65
- end
66
-
67
- @env.ui.info(opts.help, :prefix => false)
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,8 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Command
4
- class Update < Ghost::Command::Base
5
- end
6
- end
7
- end
8
- end
@@ -1,21 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Middleware
4
- class Remove
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- remove env[:vm] if env["vm"].created?
11
- @app.call(env)
12
- end
13
-
14
- protected
15
- def remove(vm)
16
- Ghost::VM.new(vm).remove(:guests => false)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- module VagrantPlugins
2
- module Ghost
3
- module Middleware
4
- class Update
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- @app.call(env)
11
- update env[:vm] if env["vm"].state == :running
12
- end
13
-
14
- protected
15
- def update(vm)
16
- Ghost::VM.new(vm).update
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,154 +0,0 @@
1
- require 'forwardable'
2
-
3
- module VagrantPlugins
4
- module Ghost
5
- class VM
6
- extend Forwardable
7
-
8
- def_delegators :@vm, :channel, :config, :env, :name, :uuid
9
-
10
- class << self
11
- def expand_path(relative_path, relative_to)
12
- File.expand_path(relative_path, relative_to)
13
- end
14
-
15
- def hosts_path
16
- Util::Platform.windows? ? expand_path('system32/drivers/etc/hosts', ENV['SYSTEMROOT']) : '/etc/hosts'
17
- end
18
- end
19
-
20
- def initialize( vm )
21
- @vm = vm
22
- end
23
-
24
- def add(options = {})
25
- if process_local?(options)
26
- env.ui.info("Adding host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
27
- sudo add_command
28
- end
29
-
30
- with_other_vms { |vm| channel.sudo vm.add_command(:uuid => uuid, :hosts_path => hosts_path) } if process_guests?(options)
31
- end
32
-
33
- def hosts_path
34
- # TODO: if windows guests are supported, this will need to be smarter
35
- "/etc/hosts"
36
- end
37
-
38
- def list(options = {})
39
- if process_local?(options)
40
- output = `#{list_command}`.chomp
41
- env.ui.info("[local] #{output}\n\n", :prefix => false) unless output.empty?
42
- end
43
-
44
- if process_guests?(options)
45
- entries = ""
46
- with_other_vms do |vm|
47
- channel.execute(vm.list_command(:uuid => uuid, :hosts_path => hosts_path), :error_check => false) do |type, data|
48
- entries << data if type == :stdout
49
- end
50
- end
51
- entries = entries.split($/).collect { |entry| "[#{name}] #{entry}" }.join("\n")
52
- env.ui.info("#{entries}\n\n", :prefix => false) unless entries.empty?
53
- end
54
- end
55
-
56
- def remove(options = {})
57
- if process_local?(options)
58
- env.ui.info("Removing host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
59
- sudo remove_command
60
- end
61
- with_other_vms { |vm| channel.sudo vm.remove_command(:uuid => uuid, :hosts_path => hosts_path) } if process_guests?(options)
62
- end
63
-
64
- def update(options = {})
65
- if process_local?(options)
66
- env.ui.info("Updating host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
67
- sudo(remove_command) && sudo(add_command)
68
- end
69
- with_other_vms { |vm| channel.sudo(vm.remove_command(:uuid => uuid, :hosts_path => hosts_path)) && channel.sudo(vm.add_command(:uuid => uuid, :hosts_path => hosts_path)) } if process_guests?(options)
70
- end
71
-
72
- protected
73
- def add_command(options = {})
74
- uuid = options[:uuid] || self.uuid
75
- hosts_path = options[:hosts_path] || self.class.hosts_path
76
- %Q(sh -c 'echo "#{host_entry(uuid)}" >>#{hosts_path}')
77
- end
78
-
79
- def address
80
- # network parameters consist of an address and a hash of options
81
- @address ||= (network_parameters && network_parameters.first)
82
- end
83
-
84
- def host_aliases
85
- @host_aliases ||= Array(config.hosts.aliases)
86
- end
87
-
88
- def host_entry(uuid = self.uuid)
89
- %Q(#{address} #{host_names.join(' ')} #{signature(uuid)})
90
- end
91
-
92
- def host_name
93
- @host_name ||= (config.hosts.name || config.vm.host_name)
94
- end
95
-
96
- def host_names
97
- @host_names ||= (Array(host_name) + host_aliases)
98
- end
99
-
100
- def process_guests?(options = {})
101
- {:guests => true}.merge(options)[:guests]
102
- end
103
-
104
- def process_local?(options = {})
105
- {:local => true}.merge(options)[:local]
106
- end
107
-
108
- def list_command(options = {})
109
- uuid = options[:uuid] || self.uuid
110
- hosts_path = options[:hosts_path] || self.class.hosts_path
111
- %Q(grep '#{signature(uuid)}$' #{hosts_path})
112
- end
113
-
114
- def network
115
- # hostonly networks are the only ones we're interested in
116
- @network ||= networks.find { |type,network_parameters| type == :hostonly }
117
- end
118
-
119
- def network_parameters
120
- # network is a pair of a network type and the network parameters
121
- @network_parameters ||= (network && network.last)
122
- end
123
-
124
- def networks
125
- @networks ||= config.vm.networks
126
- end
127
-
128
- def remove_command(options = {})
129
- uuid = options[:uuid] || self.uuid
130
- hosts_path = options[:hosts_path] || self.class.hosts_path
131
- %Q(sed -e '/#{signature(uuid)}$/ d' -ibak #{hosts_path})
132
- end
133
-
134
- def signature(uuid = self.uuid)
135
- %Q(# VAGRANT: #{uuid} (#{name}))
136
- end
137
-
138
- def sudo(command)
139
- if Util::Platform.windows?
140
- `#{command}`
141
- else
142
- `sudo #{command}`
143
- end
144
- end
145
-
146
- def with_other_vms
147
- env.vms.each do |name,vm|
148
- yield Ghost::VM.new(vm) if vm.config.vm.networks.any? { |type,network_parameters| type == :hostonly } && vm.name != self.name
149
- end
150
- end
151
-
152
- end
153
- end
154
- end