vagrant-vlan 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f55078a75af1e44111a5c49ae7928b90facdc47b
4
+ data.tar.gz: d39d272e37cc3eed46f20aab035d7f3a30442eaa
5
+ SHA512:
6
+ metadata.gz: 5cf39e099e129a6ffddaadaea73eca4d14cc0ea417ab3658913108b5cdf9b86ea0abe00489bd48d7192e377654e6e0fab1e871601445e7d668cf4c5438073de6
7
+ data.tar.gz: bc5148510aba3ff4c232bf499eb6ae9badfb5dc8b427e62c109e5bc9af328954ea6d5a89f91102012f58acc6291ef0f2644a25b22d1807be8d4925009c56de88
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # editors
5
+ *.swp
6
+
7
+ # Bundler/Rubygems
8
+ *.gem
9
+ .bundle
10
+ pkg/*
11
+ tags
12
+ Gemfile.lock
13
+
14
+ # Vagrant
15
+ .vagrant
16
+ Vagrantfile
17
+ !example_box/Vagrantfile
18
+
19
+ # RVM files for gemset/ruby setting
20
+ .ruby-*
21
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-host-route.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
8
+ end
9
+
10
+ group :plugins do
11
+ gem "vagrant-vlan", path: "."
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Arctic Wolf Networks
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,58 @@
1
+ # Vagrant VLAN Plugin
2
+
3
+ A plugin to configure a VLAN within a guest.
4
+
5
+ The implementation relies on Vagrant's guest capabilities. Currently, the plugin
6
+ supports only Debian-derived guests and in particular has been tested only on
7
+ Ubuntu. However, contributions to add support for other guests are more than
8
+ welcome.
9
+
10
+ ## Installation
11
+
12
+ Use `vagrant plugin install`:
13
+
14
+ $ vagrant plugin install vagrant-vlan
15
+
16
+ ## Usage
17
+
18
+ Setting up a VLAN is accomplished using the `config.vlan.add`
19
+ gestures. The gesture takes similar parameters to `config.vm.network`, with
20
+ some exceptions. Valid parameters are as follows:
21
+
22
+ * `vlan`
23
+ The VLAN identifier. An integer in the range [1, 4094].
24
+ * `parent`
25
+ The parent (or physical) interface to which the VLAN interface should attach.
26
+ * `type`
27
+ Method of IP assignment. Valid values are "dhcp" and "static".
28
+ * `ip`
29
+ Required if `type` is "static". The IP address to be assigned to the interface.
30
+ * `netmask`
31
+ Required if `type` is "static". The netmask to use for the interface.
32
+
33
+ The name of the interface will be constructed automatically using the format
34
+ `parent`.`vlan`.
35
+
36
+ Note that the VLAN plugin runs immediately after Vagrant network configuration,
37
+ so `parent` can include interfaces configured using `config.vm.network`.
38
+
39
+ ### Example
40
+
41
+ Create VLAN 5 on interface `eth0`, and assign it the static IP 10.0.1.2/24.
42
+ The name of the VLAN interface will be `eth0.5`.
43
+
44
+ ```ruby
45
+ config.vlan.add vlan: 5, parent: "eth0",
46
+ type: "static", ip: "10.0.1.2", netmask: "255.255.255.0"
47
+ ```
48
+
49
+ The `config` object in the example is what was passed by Vagrant to the
50
+ `config.vm.define` block.
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
@@ -0,0 +1,33 @@
1
+ module VagrantPlugins
2
+ module VLAN
3
+ class Action
4
+ def initialize(app, env)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ vlans = env[:machine].config.vlan.vlans.map do |vlan|
10
+ normalize_config(vlan)
11
+ end
12
+
13
+ # Call subsequent middleware steps. We'll do our setup at the
14
+ # end
15
+ @app.call(env)
16
+
17
+ if !vlans.empty?
18
+ env[:ui].output("Configuring VLANs...")
19
+ env[:machine].guest.capability(:configure_vlans, vlans)
20
+ end
21
+ end
22
+
23
+ def normalize_config(config)
24
+ return {
25
+ :type => "dhcp",
26
+ :auto_config => true,
27
+ :ip => nil,
28
+ :netmask => "255.255.255.0"
29
+ }.merge(config || {})
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module VLAN
5
+ class Config < Vagrant.plugin(2, :config)
6
+ def initialize
7
+ @__vlans = []
8
+ end
9
+
10
+ def add(**options)
11
+ @__vlans << options.dup
12
+ end
13
+
14
+ def vlans
15
+ @__vlans
16
+ end
17
+
18
+ def merge(other)
19
+ super.tap do |result|
20
+ result.instance_variable_set(:@__vlans, @__vlans + other.vlans)
21
+ end
22
+ end
23
+
24
+ def validate(machine)
25
+ errors = _detected_errors || []
26
+
27
+ vlans.each do |vlan|
28
+ errors << "The VLAN interface name will be constructed automatically." if vlan.include? :interface
29
+ errors << "A VLAN id must be specified." if !vlan.include? :vlan
30
+ errors << "The VLAN id must be an integer in the range [1, 4094]." if !vlan[:vlan].is_a?(Integer) || !vlan[:vlan].between?(1, 4094)
31
+ errors << "A parent interface must be specified." if !vlan.include? :parent
32
+ end
33
+
34
+ { "vlan" => errors }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,69 @@
1
+ require "set"
2
+ require "tempfile"
3
+
4
+ require "vagrant/util/template_renderer"
5
+
6
+ module VagrantPlugins
7
+ module GuestDebian
8
+ module Cap
9
+ class ConfigureVLANs
10
+ include Vagrant::Util
11
+
12
+ # Heavily borrowed from VagrantPlugins::Debian::Cap::ConfigureNetworks.
13
+ def self.configure_vlans(machine, vlans)
14
+ machine.communicate.tap do |comm|
15
+ # Verify the kernel module is installed and loaded.
16
+ if !comm.test("lsmod | grep 8021q")
17
+ comm.sudo("apt-get install vlan")
18
+ comm.sudo("modprobe 8021q")
19
+ end
20
+
21
+ # First, remove any previous network modifications
22
+ # from the interface file.
23
+ comm.sudo("sed -e '/^#VAGRANT-VLAN-BEGIN/,/^#VAGRANT-VLAN-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
24
+ comm.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
25
+ comm.sudo("rm /tmp/vagrant-network-interfaces")
26
+
27
+ # Accumulate the configurations to add to the interfaces file as
28
+ # well as what interfaces we're actually configuring since we use that
29
+ # later.
30
+ interfaces = Set.new
31
+ entries = []
32
+ vlans.each do |vlan|
33
+ vlan[:interface] = "#{vlan[:parent]}.#{vlan[:vlan]}"
34
+ interfaces.add(vlan[:interface])
35
+ entry = TemplateRenderer.render(File.join(File.dirname(__FILE__), "vlan"),
36
+ :options => vlan)
37
+
38
+ entries << entry
39
+ end
40
+
41
+ # Perform the careful dance necessary to reconfigure
42
+ # the network interfaces
43
+ temp = Tempfile.new("vagrant")
44
+ temp.binmode
45
+ temp.write(entries.join("\n"))
46
+ temp.close
47
+
48
+ comm.upload(temp.path, "/tmp/vagrant-network-entry")
49
+
50
+ # Bring down all the interfaces we're reconfiguring. By bringing down
51
+ # each specifically, we avoid reconfiguring eth0 (the NAT interface) so
52
+ # SSH never dies.
53
+ interfaces.each do |interface|
54
+ comm.sudo("/sbin/ifdown #{interface} 2> /dev/null")
55
+ end
56
+
57
+ comm.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces")
58
+ comm.sudo("rm /tmp/vagrant-network-entry")
59
+
60
+ # Bring back up each network interface, reconfigured
61
+ interfaces.each do |interface|
62
+ comm.sudo("/sbin/ifup #{interface}")
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,12 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestDebian
5
+ class Plugin < Vagrant.plugin("2")
6
+ guest_capability("debian", "configure_vlans") do
7
+ require_relative "configure_vlans"
8
+ Cap::ConfigureVLANs
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ #VAGRANT-VLAN-BEGIN
2
+ # The contents below are automatically generated by Vagrant. Do not modify.
3
+ auto <%= options[:interface] %>
4
+ iface <%= options[:interface] %> inet <%= options[:type] %>
5
+ vlan-raw-device <%= options[:parent] %>
6
+ <%- if options[:type] == "static" -%>
7
+ address <%= options[:ip] %>
8
+ netmask <%= options[:netmask] %>
9
+ <%- else %>
10
+ <%- if !options[:use_dhcp_assigned_default_route] -%>
11
+ post-up route del default dev $IFACE
12
+ <%- else -%>
13
+ # Disable the NAT default route in favour of our own.
14
+ post-up route del default dev eth0
15
+ post-up dhclient $IFACE
16
+ pre-down route add default dev eth0
17
+ <%- end -%>
18
+ <%- end -%>
19
+ #VAGRANT-VLAN-END
@@ -0,0 +1,28 @@
1
+ require "vagrant"
2
+
3
+ require_relative "debian/guest"
4
+
5
+ module VagrantPlugins
6
+ module VLAN
7
+ class Plugin < Vagrant.plugin("2")
8
+ name "VLAN configuration"
9
+ description "Configure VLANs"
10
+
11
+ action_hook(:configure_vlans) do |hook|
12
+ require_relative "action"
13
+ # We're injecting ourselves before the Vagrant standard network
14
+ # configuration step because we (as well as the standard network
15
+ # configuration middleware) do the actual network configuration on the
16
+ # way up the middleware stack. Therefore, this ensures that we will
17
+ # configure the vlans after the rest of the interfaces.
18
+ hook.before(VagrantPlugins::ProviderVirtualBox::Action::Network,
19
+ Action)
20
+ end
21
+
22
+ config "vlan" do
23
+ require_relative "config"
24
+ VagrantPlugins::VLAN::Config
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module VLAN
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "vagrant-vlan/plugin"
2
+ require "pathname"
3
+
4
+ module VagrantPlugins
5
+ module VLAN
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-vlan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-vlan"
8
+ spec.version = VagrantPlugins::VLAN::VERSION
9
+ spec.authors = ["Arctic Wolf Networks"]
10
+ spec.email = ["dev@arcticwolf.com"]
11
+ spec.summary = %q{Configure a VLAN inside a guest.}
12
+ spec.description = %q{Configure a VLAN inside a guest.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-vlan
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Arctic Wolf Networks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Configure a VLAN inside a guest.
42
+ email:
43
+ - dev@arcticwolf.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/vagrant-vlan.rb
54
+ - lib/vagrant-vlan/action.rb
55
+ - lib/vagrant-vlan/config.rb
56
+ - lib/vagrant-vlan/debian/configure_vlans.rb
57
+ - lib/vagrant-vlan/debian/guest.rb
58
+ - lib/vagrant-vlan/debian/vlan.erb
59
+ - lib/vagrant-vlan/plugin.rb
60
+ - lib/vagrant-vlan/version.rb
61
+ - vagrant-vlan.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.14
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Configure a VLAN inside a guest.
86
+ test_files: []