vagrant-hosts 0.0.1rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ vagrant-hosts-*.gem
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2012 Adrien Thebo
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
@@ -0,0 +1,4 @@
1
+ vagrant-hosts
2
+ =============
3
+
4
+ Manage vagrant guest local DNS resolution.
@@ -0,0 +1,7 @@
1
+ # Declare top level vagrant hosts module.
2
+ module VagrantHosts; end
3
+
4
+ require 'vagrant-hosts/version'
5
+ require 'vagrant-hosts/provisioners/hosts'
6
+
7
+ Vagrant.provisioners.register(:hosts) { VagrantHosts::Provisioner }
@@ -0,0 +1,77 @@
1
+ require 'vagrant'
2
+ require 'vagrant-hosts'
3
+ require 'vagrant-hosts/ssh' # Guerrilla patch ssh download
4
+ require 'tempfile'
5
+
6
+
7
+ class VagrantHosts::Provisioner < Vagrant::Provisioners::Base
8
+
9
+ class Config < Vagrant::Config::Base
10
+
11
+ attr_reader :hosts
12
+
13
+ def initialize
14
+ @hosts = []
15
+ end
16
+
17
+ # Register a host for entry
18
+ #
19
+ # @param [String] address The IP address for aliases
20
+ # @param [Array] aliases An array of hostnames to assign to the IP address
21
+ def add_host(address, aliases)
22
+ @hosts << [address, aliases]
23
+ end
24
+
25
+ def validate(env, errors)
26
+ @hosts.each do |(address, aliases)|
27
+ unless aliases.is_a? Array
28
+ errors.add("#{address} should have an array of aliases, got #{aliases.inspect}:#{aliases.class}")
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.config_class
35
+ Config
36
+ end
37
+
38
+ def provision!
39
+ # too tired to do this. detect target platform, select according provider,
40
+ # add entries that are specified in the config and are not on the client
41
+
42
+ driver = Linux.new(@env, config)
43
+ driver.sync!
44
+ end
45
+
46
+ class Linux
47
+
48
+ def initialize(env, config)
49
+ @env, @config = env, config
50
+ end
51
+
52
+ def sync!
53
+ cache = Tempfile.new('vagrant-hosts')
54
+
55
+ # It would be really cool to synchronize this file instead of blindly
56
+ # smashing the remote hosts file, but this is the quick and dirty solution.
57
+ #@env[:vm].channel.download('/etc/hosts', cache.path)
58
+ #cache.rewind
59
+ #cache.truncate(0)
60
+
61
+ cache.write hosts_format
62
+ cache.flush
63
+
64
+ @env[:vm].channel.upload(cache.path, '/tmp/hosts')
65
+ @env[:vm].channel.sudo('install -m 644 /tmp/hosts /etc/hosts')
66
+ end
67
+
68
+ # Generates content appropriate for a linux hosts file
69
+ #
70
+ # @return [String] All hosts in the config joined into hosts records
71
+ def hosts_format
72
+ @config.hosts.inject('') do |str, (address, aliases)|
73
+ str << "#{address} #{aliases.join(' ')}\n"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,27 @@
1
+ require 'vagrant'
2
+ require 'vagrant/errors'
3
+ require 'vagrant/communication/ssh'
4
+
5
+ # Helloooooo monkey patching.
6
+
7
+ class Vagrant::Communication::SSH
8
+
9
+ # Download a remote file
10
+ #
11
+ # @param [String] from the path on the remote end
12
+ # @param [String] to the path on the local end
13
+ #
14
+ #
15
+ def download(from, to)
16
+ @logger.debug("Downlaoding: #{from} to #{to}")
17
+
18
+ connect do |connection|
19
+ scp = Net::SCP.new(connection)
20
+ scp.download!(from, to)
21
+ end
22
+
23
+ rescue Net::SCP::Error => e
24
+ raise Vagrant::Errors::SCPUnavailable if e.message =~ /\(127\)/
25
+ raise
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantHosts
2
+ VERSION = '0.0.1rc1'
3
+ end
@@ -0,0 +1 @@
1
+ require 'vagrant-hosts'
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
2
+ require 'vagrant-hosts/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'vagrant-hosts'
6
+ gem.version = VagrantHosts::VERSION
7
+ gem.date = Date.today.to_s
8
+
9
+ gem.summary = 'Manage static DNS on vagrant guests'
10
+ gem.description = <<-EOD
11
+ Manage static DNS entries and configuration for Vagrant guests.
12
+ EOD
13
+
14
+ gem.authors = 'Adrien Thebo'
15
+ gem.email = 'adrien@somethingsinistral.net'
16
+ gem.homepage = 'https://github.com/adrienthebo/vagrant-hosts'
17
+
18
+ gem.add_dependency 'vagrant', '~> 1.0'
19
+
20
+ gem.files = %x{git ls-files -z}.split("\0")
21
+ gem.require_path = 'lib'
22
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-hosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1rc1
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Adrien Thebo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description: ! ' Manage static DNS entries and configuration for Vagrant guests.
31
+
32
+ '
33
+ email: adrien@somethingsinistral.net
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - LICENSE
40
+ - README.markdown
41
+ - lib/vagrant-hosts.rb
42
+ - lib/vagrant-hosts/provisioners/hosts.rb
43
+ - lib/vagrant-hosts/ssh.rb
44
+ - lib/vagrant-hosts/version.rb
45
+ - lib/vagrant_init.rb
46
+ - vagrant-hosts.gemspec
47
+ homepage: https://github.com/adrienthebo/vagrant-hosts
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>'
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.1
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Manage static DNS on vagrant guests
71
+ test_files: []
72
+ has_rdoc: