vagrant-netinfo 0.0.1

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: 6e24b8a507995078ec593191c809ca07933c4a48
4
+ data.tar.gz: c2a106148cd61d285b9ced1c606fecce7857fae4
5
+ SHA512:
6
+ metadata.gz: 243260109502a822b6eb70bb6e364ef0de40ac0083512cdd47af2e9b838bb2cd3f2d1bf0a5f801c30f7b1adbc52eba8f7d47a3e803ca0458728b1475ebe0f5a0
7
+ data.tar.gz: c762c82e43a47872274fe522343fe767c2c281782b590c8e12e16645e782239abf1db6c9e697f1b10ebd1b680e9f2c6f1c76bb6faef3420462f9b7c2cd4ed4e1
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :plugins do
4
+ gemspec
5
+ end
6
+
7
+ group :development do
8
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.6.5'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jan Vansteenkiste
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,26 @@
1
+ # Vagrant::Netinfo
2
+
3
+ Shows network mapping information on a running vagrant box. In case you forgot.
4
+
5
+ ## Installation
6
+
7
+ vagrant plugin install vagrant-netinfo
8
+
9
+ ## Usage
10
+
11
+ vagrant netinfo BOXNAME
12
+
13
+ ## Testing
14
+
15
+ 1. Clone it
16
+ 2. Run `bundle install`
17
+ 3. Run `bundle exec vagrant up`
18
+ 4. Run `bundle exec vagrant netinfo one two`
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it ( https://github.com/vStone/vagrant-netinfo )
23
+ 2. Create a new feature branch
24
+ 3. Commit
25
+ 4. Push to your remote
26
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/Vagrantfile ADDED
@@ -0,0 +1,136 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ $provision_script = <<SCRIPT
5
+ yum install -y httpd
6
+ systemctl start httpd
7
+ SCRIPT
8
+
9
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
10
+ VAGRANTFILE_API_VERSION = "2"
11
+
12
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
13
+ # All Vagrant configuration is done here. The most common configuration
14
+ # options are documented and commented below. For a complete reference,
15
+ # please see the online documentation at vagrantup.com.
16
+
17
+ # Every Vagrant virtual environment requires a box to build off of.
18
+ config.vm.box = "vStone/centos-7.x-puppet.3.x"
19
+
20
+ config.vm.define 'one' do |one|
21
+ one.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true, host_ip: '127.0.0.2'
22
+ one.vm.network "forwarded_port", guest: 443, host: 8443
23
+ one.vm.network "forwarded_port", guest: 53, host: 8053, protocol: 'udp'
24
+ end
25
+
26
+ config.vm.define 'two' do |two|
27
+ two.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
28
+ end
29
+
30
+ config.vm.provision 'shell', inline: $provision_script
31
+
32
+ # Disable automatic box update checking. If you disable this, then
33
+ # boxes will only be checked for updates when the user runs
34
+ # `vagrant box outdated`. This is not recommended.
35
+ # config.vm.box_check_update = false
36
+
37
+ # Create a forwarded port mapping which allows access to a specific port
38
+ # within the machine from a port on the host machine. In the example below,
39
+ # accessing "localhost:8080" will access port 80 on the guest machine.
40
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
41
+
42
+ # Create a private network, which allows host-only access to the machine
43
+ # using a specific IP.
44
+ # config.vm.network "private_network", ip: "192.168.33.10"
45
+
46
+ # Create a public network, which generally matched to bridged network.
47
+ # Bridged networks make the machine appear as another physical device on
48
+ # your network.
49
+ # config.vm.network "public_network"
50
+
51
+ # If true, then any SSH connections made will enable agent forwarding.
52
+ # Default value: false
53
+ # config.ssh.forward_agent = true
54
+
55
+ # Share an additional folder to the guest VM. The first argument is
56
+ # the path on the host to the actual folder. The second argument is
57
+ # the path on the guest to mount the folder. And the optional third
58
+ # argument is a set of non-required options.
59
+ # config.vm.synced_folder "../data", "/vagrant_data"
60
+
61
+ # Provider-specific configuration so you can fine-tune various
62
+ # backing providers for Vagrant. These expose provider-specific options.
63
+ # Example for VirtualBox:
64
+ #
65
+ config.vm.provider "virtualbox" do |vb|
66
+ # Use VBoxManage to customize the VM. For example to change memory:
67
+ vb.customize ["modifyvm", :id, "--memory", "512"]
68
+ end
69
+ #
70
+ # View the documentation for the provider you're using for more
71
+ # information on available options.
72
+
73
+ # Enable provisioning with CFEngine. CFEngine Community packages are
74
+ # automatically installed. For example, configure the host as a
75
+ # policy server and optionally a policy file to run:
76
+ #
77
+ # config.vm.provision "cfengine" do |cf|
78
+ # cf.am_policy_hub = true
79
+ # # cf.run_file = "motd.cf"
80
+ # end
81
+ #
82
+ # You can also configure and bootstrap a client to an existing
83
+ # policy server:
84
+ #
85
+ # config.vm.provision "cfengine" do |cf|
86
+ # cf.policy_server_address = "10.0.2.15"
87
+ # end
88
+
89
+ # Enable provisioning with Puppet stand alone. Puppet manifests
90
+ # are contained in a directory path relative to this Vagrantfile.
91
+ # You will need to create the manifests directory and a manifest in
92
+ # the file default.pp in the manifests_path directory.
93
+ #
94
+ # config.vm.provision "puppet" do |puppet|
95
+ # puppet.manifests_path = "manifests"
96
+ # puppet.manifest_file = "default.pp"
97
+ # end
98
+
99
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
100
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
101
+ # some recipes and/or roles.
102
+ #
103
+ # config.vm.provision "chef_solo" do |chef|
104
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
105
+ # chef.roles_path = "../my-recipes/roles"
106
+ # chef.data_bags_path = "../my-recipes/data_bags"
107
+ # chef.add_recipe "mysql"
108
+ # chef.add_role "web"
109
+ #
110
+ # # You may also specify custom JSON attributes:
111
+ # chef.json = { mysql_password: "foo" }
112
+ # end
113
+
114
+ # Enable provisioning with chef server, specifying the chef server URL,
115
+ # and the path to the validation key (relative to this Vagrantfile).
116
+ #
117
+ # The Opscode Platform uses HTTPS. Substitute your organization for
118
+ # ORGNAME in the URL and validation key.
119
+ #
120
+ # If you have your own Chef Server, use the appropriate URL, which may be
121
+ # HTTP instead of HTTPS depending on your configuration. Also change the
122
+ # validation key to validation.pem.
123
+ #
124
+ # config.vm.provision "chef_client" do |chef|
125
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
126
+ # chef.validation_key_path = "ORGNAME-validator.pem"
127
+ # end
128
+ #
129
+ # If you're using the Opscode platform, your validator client is
130
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
131
+ #
132
+ # If you have your own Chef Server, the default validation client name is
133
+ # chef-validator, unless you changed the configuration.
134
+ #
135
+ # chef.validation_client_name = "ORGNAME-validator"
136
+ end
@@ -0,0 +1,116 @@
1
+ require 'optparse'
2
+ require 'awesome_print'
3
+
4
+ module VagrantPlugins
5
+ module Netinfo
6
+ class Command < Vagrant.plugin(2, :command)
7
+ def self.synopsis
8
+ 'output network mapping of the vagrant machine'
9
+ end
10
+
11
+ def execute
12
+ opts = OptionParser.new do |o|
13
+ o.banner = "Usage: vagrant netinfo [name]"
14
+ end
15
+
16
+ # Parse the options
17
+ argv = parse_options(opts)
18
+ return if !argv
19
+
20
+ widths = {
21
+ :nic_id => 'nic'.length + 1,
22
+ :protocol => 10,
23
+ :guest_ip => 10,
24
+ :guest_port => 5,
25
+ :host_ip => 10,
26
+ :host_port => 5,
27
+ :name => 10,
28
+ }
29
+
30
+ results = []
31
+ uuid = nil
32
+
33
+ with_target_vms(argv) do |machine|
34
+ current_nic = nil
35
+ uuid = machine.id
36
+ machine_results = []
37
+
38
+ # Only active VMS pls.
39
+ if !machine.communicate.ready?
40
+ raise Vagrant::Errors::VMNotCreatedError
41
+ end
42
+
43
+ ## Looks like this is pretty provider specific.
44
+ case machine.provider_name
45
+ when :virtualbox
46
+ info = machine.provider.driver.execute('showvminfo', uuid, '--machinereadable', retryable: true)
47
+ info.split("\n").each do |line|
48
+ current_nic = $1.to_i if line =~ /^nic(\d+)=".+?"$/
49
+ if line =~ /^Forwarding.+?="(.+?),(.+?),(.*?),(.+?),(.*?),(.+?)"$/
50
+ widths[:nic_id] = "nic: #{current_nic.to_s}".length if "nic: #{current_nic.to_s}".length > widths[:nic_id]
51
+
52
+ widths[:host_ip] = $3.to_s.length if $3.to_s.length > widths[:host_ip]
53
+ widths[:host_port] = $4.to_s.length if $4.to_s.length > widths[:host_port]
54
+
55
+ widths[:guest_ip] = $5.to_s.length if $5.to_s.length > widths[:guest_ip]
56
+ widths[:guest_port] = $6.to_s.length if $6.to_s.length > widths[:guest_port]
57
+
58
+ widths[:name] = $1.to_s.length if $1.to_s.length > widths[:name]
59
+
60
+ machine_results << {
61
+ :nic_id => current_nic,
62
+ :name => $1.to_s,
63
+ :protocol => $2.to_s,
64
+ :host_ip => $3.to_s,
65
+ :host_port => $4.to_s,
66
+ :guest_ip => $5.to_s,
67
+ :guest_port => $6.to_s,
68
+ }
69
+ end
70
+ end
71
+ else
72
+ raise Vagrant::Errors::ProviderNotUsable
73
+ end
74
+
75
+ results << {
76
+ :name => machine.name.to_s,
77
+ :provider => machine.provider_name.to_s,
78
+ :port_forwards => machine_results
79
+ }
80
+ end
81
+
82
+ header = [ ' '.ljust(widths[:nic_id]), 'guest ip'.rjust(widths[:guest_ip]), ':', 'port'.ljust(widths[:guest_port]),
83
+ ' ',
84
+ 'host ip'.rjust(widths[:host_ip]),':', 'port'.ljust(widths[:host_port]),
85
+ 'protocol'.rjust(widths[:protocol]),
86
+ 'name'.rjust(widths[:name])
87
+ ]
88
+
89
+ results.each do |machine|
90
+ @env.ui.info("Machine '#{machine[:name].to_s}' (#{machine[:provider]})")
91
+ @env.ui.info(header.join(""))
92
+ @env.ui.info('-' * header.join("").length)
93
+ machine[:port_forwards].each do |fwd|
94
+ line = []
95
+ line << [ "nic[#{fwd[:nic_id]}]".ljust(widths[:nic_id]) ]
96
+ line << [ fwd[:guest_ip].rjust(widths[:guest_ip]), ':', fwd[:guest_port].ljust(widths[:guest_port]) ]
97
+ line << [ ' -> ' ]
98
+ line << [ fwd[:host_ip].rjust(widths[:host_ip]), ':', fwd[:host_port].ljust(widths[:host_port]) ]
99
+ line << [ fwd[:protocol].rjust(widths[:protocol]) ]
100
+ line << [ fwd[:name].rjust(widths[:name]) ]
101
+ opts = {}
102
+ if fwd[:name] == 'ssh'
103
+ opts[:color] = :yellow
104
+ elsif fwd[:name] != "#{fwd[:protocol]}#{fwd[:host_port]}"
105
+ opts[:color] = :red
106
+ end
107
+
108
+ @env.ui.info(line.join(""), opts)
109
+ end
110
+ @env.ui.info("")
111
+ end
112
+ 0
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The Vagrant Netinfo plugin must be run within vagrant.'
5
+ end
6
+
7
+ if Vagrant::VERSION < '1.6.0'
8
+ raise 'The Vagrant Netinfo plugin has only been tested with vagrant 1.6.x'
9
+ end
10
+
11
+ module VagrantPlugins
12
+ module Netinfo
13
+ class Plugin < Vagrant.plugin('2')
14
+ name 'Netinfo'
15
+ description 'Display network forwardding information on a running VM'
16
+
17
+ command 'netinfo' do
18
+ require_relative 'command'
19
+ Command
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Netinfo
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'vagrant-netinfo/plugin'
2
+
3
+ module VagrantPlugins
4
+ module Netinfo
5
+ #nothing here
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ $:.unshift File.expand_path('../lib', __FILE__)
3
+ require 'vagrant-netinfo/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vagrant-netinfo'
7
+ spec.version = VagrantPlugins::Netinfo::VERSION
8
+ spec.authors = ['Jan Vansteenkiste']
9
+ spec.email = ['jan@vstone.eu']
10
+ spec.summary = %q{Display network information on a running vagrant box}
11
+ spec.description = %q{Shows forwarded ports of a running vagrant box}
12
+ spec.homepage = 'https://github.com/vStone/vagrant-netinfo'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "awesome_print"
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-netinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jan Vansteenkiste
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-08 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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Shows forwarded ports of a running vagrant box
56
+ email:
57
+ - jan@vstone.eu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - Vagrantfile
67
+ - lib/vagrant-netinfo.rb
68
+ - lib/vagrant-netinfo/command.rb
69
+ - lib/vagrant-netinfo/plugin.rb
70
+ - lib/vagrant-netinfo/version.rb
71
+ - vagrant-netinfo.gemspec
72
+ homepage: https://github.com/vStone/vagrant-netinfo
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.14
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Display network information on a running vagrant box
96
+ test_files: []