vagrant-networkd 0.0.8
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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.rst +7 -0
- data/Rakefile +6 -0
- data/Vagrantfile +7 -0
- data/lib/vagrant-networkd.rb +78 -0
- data/templates/network_dhcp.erb +5 -0
- data/templates/network_static.erb +8 -0
- data/vagrant-networkd.gemspec +16 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bcf65450f4c46f51d9821441730962ba68a70772
|
4
|
+
data.tar.gz: 58aa19ae18f2d46271740a8182dba6e10f7fb856
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58c2625f0dbcbe391827708b233647a4f1a2a6254fac3020916f25a1f3c7892f1733e88886104e2b2dce45c7afaeba0e40b8e393d19f22a677dbe3e599ebd818
|
7
|
+
data.tar.gz: 2e5798092cee9d434bc4932316b1f9cea36061b50e199ee5e1e032c6fc3a31c6ca81a3adf91392c887daf1d59f2d7f79ad4df65e452ededf3b56ebf02c9c2a31
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
# We depend on Vagrant for development, but we don't add it as a
|
7
|
+
# gem dependency because we expect to be installed within the
|
8
|
+
# Vagrant environment itself using `vagrant plugin`.
|
9
|
+
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
|
10
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Alberto Murillo <powerbsd@yahoo.com>
|
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.rst
ADDED
data/Rakefile
ADDED
data/Vagrantfile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module GuestNetworkd
|
5
|
+
class Guest < Vagrant.plugin("2", :guest)
|
6
|
+
def detect?(machine)
|
7
|
+
machine.communicate.test("test -x /usr/bin/systemctl") and
|
8
|
+
machine.communicate.test("test -d /etc/systemd/network")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Cap
|
13
|
+
class ChangeHostName
|
14
|
+
def self.change_host_name(machine, name)
|
15
|
+
name = name.split('.')
|
16
|
+
hostname = name.shift
|
17
|
+
domain = name.empty? ? "local" : name.join('.')
|
18
|
+
machine.communicate.tap do |comm|
|
19
|
+
# Only do this if the hostname is not already set
|
20
|
+
if !comm.test("sudo hostname | grep '#{hostname}'")
|
21
|
+
comm.sudo("hostnamectl set-hostname #{hostname}")
|
22
|
+
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{hostname}.#{domain} #{hostname} @' /etc/hosts")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ConfigureNetworks
|
29
|
+
def self.mask_2_ciddr mask
|
30
|
+
"/" + mask.split(".").map { |e| e.to_i.to_s(2).rjust(8, "0") }.join.count("1").to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.configure_networks(machine, networks)
|
34
|
+
interfaces = Array.new
|
35
|
+
cmd = 'ip addr | awk \'/: ./ && !/lo/ { sub(/:/, "", $2); print $2 }\''
|
36
|
+
machine.communicate.sudo(cmd) do |_, result|
|
37
|
+
interfaces = result.split("\n")
|
38
|
+
end
|
39
|
+
machine.communicate.sudo("rm -rf /etc/systemd/network/vagrant_*")
|
40
|
+
# Replace en* (if any) with the first device (usually vbox nat)
|
41
|
+
machine.communicate.sudo("sed -i 's/Name=en\\*$/Name=#{interfaces[0]}/g' /etc/systemd/network/*")
|
42
|
+
networks.each do |network|
|
43
|
+
network[:device] = interfaces[network[:interface]]
|
44
|
+
configFile = "/etc/systemd/network/vagrant_#{network[:device]}.network"
|
45
|
+
templateFile = File.expand_path("../../templates/network_#{network[:type]}.erb", __FILE__)
|
46
|
+
template = File.read(templateFile)
|
47
|
+
temp = Tempfile.new("vagrant")
|
48
|
+
temp.binmode
|
49
|
+
temp.write(Erubis::Eruby.new(template, :trim => true).result(binding))
|
50
|
+
temp.close
|
51
|
+
machine.communicate.upload(temp.path, "/tmp/vagrant_network")
|
52
|
+
machine.communicate.sudo("mv /tmp/vagrant_network #{configFile}")
|
53
|
+
machine.communicate.sudo("chown root:root #{configFile}")
|
54
|
+
machine.communicate.sudo("chmod 644 #{configFile}")
|
55
|
+
end
|
56
|
+
machine.communicate.sudo("systemctl restart systemd-networkd.service")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Plugin < Vagrant.plugin("2")
|
62
|
+
name "networkd based guest"
|
63
|
+
description "networkd based guest support."
|
64
|
+
|
65
|
+
guest("networkd", "linux") do
|
66
|
+
Guest
|
67
|
+
end
|
68
|
+
|
69
|
+
guest_capability("networkd", "change_host_name") do
|
70
|
+
Cap::ChangeHostName
|
71
|
+
end
|
72
|
+
|
73
|
+
guest_capability("networkd", "configure_networks") do
|
74
|
+
Cap::ConfigureNetworks
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "vagrant-networkd"
|
5
|
+
s.version = "0.0.8"
|
6
|
+
s.authors = ["Alberto Murillo"]
|
7
|
+
s.email = ["powerbsd@yahoo.com"]
|
8
|
+
s.homepage = "http://github.com/albertomurillo/vagrant-networkd"
|
9
|
+
s.summary = %q{Vagrant plugin to detect and support networkd based systems}
|
10
|
+
s.description = %q{Vagrant plugin to detect and support networkd based systems}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-networkd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alberto Murillo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Vagrant plugin to detect and support networkd based systems
|
14
|
+
email:
|
15
|
+
- powerbsd@yahoo.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.rst
|
24
|
+
- Rakefile
|
25
|
+
- Vagrantfile
|
26
|
+
- lib/vagrant-networkd.rb
|
27
|
+
- templates/network_dhcp.erb
|
28
|
+
- templates/network_static.erb
|
29
|
+
- vagrant-networkd.gemspec
|
30
|
+
homepage: http://github.com/albertomurillo/vagrant-networkd
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.1.11
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Vagrant plugin to detect and support networkd based systems
|
53
|
+
test_files: []
|