landrush-ip 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjViY2VmMDhiMTViZjkyNWI4NGYxNjU2YjQ3MWU2ZGIzN2UwOTViZA==
5
+ data.tar.gz: !binary |-
6
+ ZmY0M2RhODM2ZjA2NTA0N2ZmMGM2MjVhNDIwYTU4N2ZiNDhmMDU0Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGNkNWFkZGEzYWJkY2FjNGRlY2E1ZGVjOTIwMjczMGUyODZjZDA5OGI2ZDJj
10
+ NTI2ZDg1NTE5MzdkMDhhZGVhMzE4MTljNTRmZmUxMTljZGFhMjdiZTk4N2Qw
11
+ MWViNjBmMWNlMjA3MTA0YWZkOTI0ZWJhZDdiNmMxYjI3ZjZhZWM=
12
+ data.tar.gz: !binary |-
13
+ MGUyYzRlOGM5MGJkNGM5OTkxOTIwMDhlMTdhMDE1ZTM0ZTNjN2NmMDc4ODA1
14
+ OGZmNWM2MDhkZjM3M2VhNDdkZGVmOTg2OTkyMGFmZDQ4MGE3Nzk4ODAxZGQ0
15
+ YzUzMzI0ZDkwNWFmYzNjMTBjOWFmYmQyODI1ZjI1MWQ4OGYyY2I=
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at paul@neverbland.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Paul Werelds
4
+
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:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
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 ADDED
@@ -0,0 +1,161 @@
1
+ # LandrushIp
2
+
3
+ [![Build Status](https://travis-ci.org/Werelds/landrush-ip.svg?branch=master)](https://travis-ci.org/Werelds/landrush-ip)
4
+
5
+ This gem is a capability plugin for Vagrant, used in Landrush (but perfectly usable outside Landrush).
6
+
7
+ Its sole purpose is to provide a unified interface for grabbing a machine's IP addresses, independent of the OS.
8
+
9
+ While most operating systems do have multiple tools available to do this, they all work differently and none are standard across OS families.
10
+ On Linux one might have `ip` or `ifconfig` for example.
11
+ Neither is the de facto standard and in most cases, neither is installed by default in a minimal install.
12
+
13
+ To get around this, this plugin includes a tiny binary written in Go, that produces identical output on every OS.
14
+ Therefore, any OS that is supported by Go can be supported by this plugin.
15
+
16
+ ## Operating System Support
17
+
18
+ Currently, only Linux is supported.
19
+ Once we're happy with the functionality and mechanics, this will be expanded to BSD, Windows and whatever else we can support.
20
+
21
+ ## Usage
22
+
23
+ When used with Landrush, it will automatically be activated and install itself.
24
+
25
+ Without Landrush, one has to enable it explicitly via `landrush_ip.override` if auto-installation is desired.
26
+
27
+ Other plugins can use the provided capabilities to check if it is installed and/or install it.
28
+
29
+ Example config with VirtualBox to force installation:
30
+
31
+ ```ruby
32
+ Vagrant.configure('2') do |config|
33
+ config.vm.define 'mybox' do |machine|
34
+ machine.vm.box = 'debian/jessie64'
35
+ machine.vm.network 'private_network', type: 'dhcp'
36
+
37
+ machine.landrush_ip.override = true
38
+
39
+ machine.vm.provider :virtualbox do |provider, _|
40
+ provider.memory = 512
41
+ provider.cpus = 2
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+ ## Capabilities
48
+
49
+ This plugin exposes the following _Guest_ capabilities:
50
+
51
+ - `landrush_ip_installed` returns a boolean to indicate whether Landrush is installed and up to date with the installed version of the plugin.
52
+ - `landrush_ip_install` installs the binary.
53
+ - `landrush_ip_get` returns all IP addresses of the machine in an array of hashes. Each hash has the following structure: `{ 'name' => 'lo', 'ipv4' => '127.0.0.1', 'ipv6' => '::1' }`.
54
+
55
+ Do note that the IP addresses are returned as strings; they are not yet cast to `IPAddr` or any other form, this is left entirely up to the consumer.
56
+
57
+ ## Binary
58
+
59
+ The binary will be installed in various locations:
60
+
61
+ - Linux: `/usr/local/sbin/landrush-ip`
62
+
63
+ It has the following options:
64
+
65
+ - `-h` displays the usage/help
66
+ - `-v` displays the version
67
+ - `-json` returns the output in JSON format
68
+ - `-yaml` returns the output in YAML format
69
+
70
+ By default, it returns the output in TSV (Tab Separated Values) format.
71
+ First column is interface name, second is IPv4 address and third is IPv6 address.
72
+
73
+ The JSON and YAML formats output objects and hashes respectively, that have a `name`, `ipv4` and `ipv6` key.
74
+
75
+ No filtering is done with any of the formats, so any interface that has no assigned IP will still show up.
76
+ It's left up to consumer to filter that out.
77
+ Same goes for the order in which they are returned, they are returned as returned by the OS.
78
+
79
+ The following examples are all from OS X (Darwin)
80
+
81
+ Plain text (`landrush-ip`):
82
+ ```
83
+ lo0 127.0.0.1 fe80::1
84
+ gif0
85
+ stf0
86
+ en0 192.168.0.102
87
+ en1
88
+ en2
89
+ fw0
90
+ p2p0
91
+ awdl0
92
+ bridge0
93
+ ```
94
+
95
+ YAML (`landrush-ip -yaml`):
96
+ ```yaml
97
+ - name: lo0
98
+ ipv4: 127.0.0.1
99
+ ipv6: fe80::1
100
+ - name: gif0
101
+ ipv4: ""
102
+ ipv6: ""
103
+ - name: stf0
104
+ ipv4: ""
105
+ ipv6: ""
106
+ - name: en0
107
+ ipv4: 192.168.0.102
108
+ ipv6: ""
109
+ - name: en1
110
+ ipv4: ""
111
+ ipv6: ""
112
+ - name: en2
113
+ ipv4: ""
114
+ ipv6: ""
115
+ - name: fw0
116
+ ipv4: ""
117
+ ipv6: ""
118
+ - name: p2p0
119
+ ipv4: ""
120
+ ipv6: ""
121
+ - name: awdl0
122
+ ipv4: ""
123
+ ipv6: ""
124
+ - name: bridge0
125
+ ipv4: ""
126
+ ipv6: ""
127
+ ```
128
+
129
+ JSON (`landrush-ip -json`):
130
+ ```json
131
+ [
132
+ {"name":"lo0","ipv4":"127.0.0.1","ipv6":"fe80::1"},
133
+ {"name":"gif0","ipv4":"","ipv6":""},
134
+ {"name":"stf0","ipv4":"","ipv6":""},
135
+ {"name":"en0","ipv4":"192.168.0.102","ipv6":""},
136
+ {"name":"en1","ipv4":"","ipv6":""},
137
+ {"name":"en2","ipv4":"","ipv6":""},
138
+ {"name":"fw0","ipv4":"","ipv6":""},
139
+ {"name":"p2p0","ipv4":"","ipv6":""},
140
+ {"name":"awdl0","ipv4":"","ipv6":""},
141
+ {"name":"bridge0","ipv4":"","ipv6":""}
142
+ ]
143
+ ```
144
+
145
+ ## Development
146
+
147
+ After checking out the repo, run `bundle install` to install dependencies.
148
+ Run `rake test` to run the tests.
149
+
150
+ A `Vagrantfile` is present to run the plugin in if you so desire.
151
+ Make sure to execute in context of the Gem bundle: `bundle exec vagrant <command>`.
152
+
153
+ ## Contributing
154
+
155
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Werelds/landrush-ip.
156
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
157
+
158
+ ## License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
161
+
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'Landrush IP must be run within Vagrant'
5
+ end
6
+
7
+ require 'landrush-ip/plugin'
8
+ require 'landrush-ip/errors'
9
+
10
+ require 'pathname'
11
+
12
+ module LandrushIp
13
+ def self.source_root
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
15
+ end
16
+
17
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
18
+ I18n.reload!
19
+ end
@@ -0,0 +1,42 @@
1
+ module LandrushIp
2
+ module Action
3
+ class Install
4
+ def initialize(app, env, hook)
5
+ @app = app
6
+ @env = env
7
+ @hook = hook
8
+ end
9
+
10
+ def installed?
11
+ @machine.guest.capability(:landrush_ip_installed)
12
+ end
13
+
14
+ def override?
15
+ @machine.config.landrush_ip.override
16
+ end
17
+
18
+ def enabled?
19
+ override? || (@machine.config.key('landrush') && @machine.config.landrush.enabled)
20
+ end
21
+
22
+ def install
23
+ @env[:ui].warn I18n.t('vagrant.config.landrush_ip.not_installed')
24
+
25
+ raise Vagrant::LandrushIp::Error, :cannot_install unless @machine.guest.capability(:landrush_ip_install)
26
+ end
27
+
28
+ def call(env)
29
+ @app.call(env)
30
+ @env = env
31
+ @machine = env[:machine]
32
+
33
+ # Auto install in one of 2 cases:
34
+ # - landrush-ip is forcibly enabled via the override setting
35
+ # - Landrush is installed and enabled
36
+ install if enabled? && !installed?
37
+
38
+ @env[:ui].info I18n.t('vagrant.config.landrush_ip.not_enabled') unless enabled?
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+ module LandrushIp
4
+ module Cap
5
+ module Linux
6
+ module LandrushIpGet
7
+ def self.landrush_ip_get(machine)
8
+ result = ''
9
+ machine.communicate.execute(command) do |type, data|
10
+ result << data if type == :stdout
11
+ end
12
+
13
+ YAML.load(result)
14
+ end
15
+
16
+ def self.command
17
+ '/usr/local/bin/landrush-ip -yaml'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ module LandrushIp
2
+ module Cap
3
+ module Linux
4
+ module LandrushIpInstall
5
+ def self.determine_binary(uname)
6
+ if uname =~ /(x86_64|ia64|amd64)/i
7
+ 'landrush-ip-linux_amd64'
8
+ elsif uname =~ /(arm)/i
9
+ 'landrush-ip-linux_arm'
10
+ elsif uname =~ /(i386|i686)/i
11
+ 'landrush-ip-linux_386'
12
+ else
13
+ raise LandrushIp::Error, :unsupported_arch
14
+ end
15
+ end
16
+
17
+ def self.landrush_ip_install(machine)
18
+ result = ''
19
+ machine.communicate.execute('uname -mrs') do |type, data|
20
+ result << data if type == :stdout
21
+ end
22
+
23
+ binary = determine_binary result
24
+
25
+ machine.communicate.tap do |comm|
26
+ guest_path = '/usr/local/bin/landrush-ip'
27
+ host_path = File.expand_path("util/dist/#{binary}", LandrushIp.source_root)
28
+
29
+ comm.upload(host_path, '/tmp/landrush-ip')
30
+ comm.sudo("mv /tmp/landrush-ip #{guest_path}")
31
+ comm.sudo("chmod +x #{guest_path}", error_check: false)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ module LandrushIp
2
+ module Cap
3
+ module Linux
4
+ module LandrushIpInstalled
5
+ def self.landrush_ip_installed(machine)
6
+ result = ''
7
+ machine.communicate.execute(command) do |type, data|
8
+ result << data if type == :stdout
9
+ end
10
+
11
+ result.strip! == LandrushIp::VERSION
12
+ end
13
+
14
+ def self.command
15
+ '/usr/local/bin/landrush-ip -v || echo 0'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'vagrant'
2
+ require 'vagrant/errors'
3
+ require 'vagrant/util/template_renderer'
4
+
5
+ module LandrushIp
6
+ class Config < Vagrant.plugin('2', :config)
7
+ attr_accessor :override
8
+
9
+ DEFAULTS = {
10
+ override: false
11
+ }.freeze
12
+
13
+ def initialize
14
+ @override = UNSET_VALUE
15
+ @logger = Log4r::Logger.new('vagrantplugins::landruship::config')
16
+ end
17
+
18
+ def default_options(new_values = {})
19
+ @default_options = {} if @default_options == UNSET_VALUE
20
+ @default_options.merge! new_values
21
+ end
22
+
23
+ def override?
24
+ @override
25
+ end
26
+
27
+ def finalize!
28
+ @default_options = {} if @default_options == UNSET_VALUE
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module LandrushIp
2
+ class Error < Vagrant::Errors::VagrantError
3
+ error_namespace('vagrant.config.landrush_ip.errors')
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module LandrushIp
2
+ class Plugin < Vagrant.plugin('2')
3
+ name 'LandrushIp'
4
+
5
+ description <<-DESC
6
+ This plugin allows for finer grained control over which IP to use as external address.
7
+ Particularly when you use DHCP and have multiple interfaces (virtual or otherwise) this often is a problem.
8
+ DESC
9
+
10
+ config(:landrush_ip) do
11
+ require 'landrush-ip/config'
12
+ Config
13
+ end
14
+
15
+ guest_capability('linux', 'landrush_ip_installed') do
16
+ require 'landrush-ip/cap/linux/landrush_ip_installed'
17
+ Cap::Linux::LandrushIpInstalled
18
+ end
19
+
20
+ guest_capability('linux', 'landrush_ip_install') do
21
+ require 'landrush-ip/cap/linux/landrush_ip_install'
22
+ Cap::Linux::LandrushIpInstall
23
+ end
24
+
25
+ guest_capability('linux', 'landrush_ip_get') do
26
+ require 'landrush-ip/cap/linux/landrush_ip_get'
27
+ Cap::Linux::LandrushIpGet
28
+ end
29
+
30
+ require 'landrush-ip/action/install'
31
+
32
+ %w(up reload).each do |action|
33
+ action_hook(:landrush_ip, "machine_action_#{action}".to_sym) do |hook|
34
+ hook.before(Landrush::Action::RedirectDns, Action::Install, :provision)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module LandrushIp
2
+ VERSION = '0.2.0'.freeze
3
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,9 @@
1
+ en:
2
+ vagrant:
3
+ config:
4
+ landrush_ip:
5
+ not_enabled: "Landrush IP override not enabled and Landrush was not found, nothing to do."
6
+ not_installed: "Landrush IP not installed in guest yet (or it's an outdated version). Installing now."
7
+ errors:
8
+ unsupported_arch: "Unsupported architecture"
9
+ cannot_install: "Unable to install landrush-ip"
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: landrush-ip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Werelds
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ description:
28
+ email:
29
+ - paul@neverbland.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CODE_OF_CONDUCT.md
35
+ - LICENSE.txt
36
+ - README.md
37
+ - lib/landrush-ip.rb
38
+ - lib/landrush-ip/action/install.rb
39
+ - lib/landrush-ip/cap/linux/landrush_ip_get.rb
40
+ - lib/landrush-ip/cap/linux/landrush_ip_install.rb
41
+ - lib/landrush-ip/cap/linux/landrush_ip_installed.rb
42
+ - lib/landrush-ip/config.rb
43
+ - lib/landrush-ip/errors.rb
44
+ - lib/landrush-ip/plugin.rb
45
+ - lib/landrush-ip/version.rb
46
+ - locales/en.yml
47
+ - util/dist/landrush-ip-linux_386
48
+ - util/dist/landrush-ip-linux_amd64
49
+ - util/dist/landrush-ip-linux_arm
50
+ homepage: https://github.com/Werelds/landrush-ip
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.4.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Capability plugin for Vagrant that allows more fine grained control over
74
+ selecting IP addresses
75
+ test_files: []