vagrant-vminfo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c194b9b479d86cccae9feefe259f49c159c90e8
4
+ data.tar.gz: a1b02c6989c7e0be5e7fb251367978f5bfe1badb
5
+ SHA512:
6
+ metadata.gz: 251f6d132de0aa47d507b3b1caa6a8cd5a23f0538e15537952ae4c7f28b28fbe859b927dac62a84e3b6e7aff3b0b4841b22bf3ac4d7235aca26021baa38ad857
7
+ data.tar.gz: 10206ab67fced12985a97a2d2fb423eafe920194ab90e3fa3f90deff4e0505da9aab89ffa818b68f2e7efb1515f6a43071985ef4f707d2220691ff94d4fc3682
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ Gemfile.lock
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .vagrant
19
+ Vagrantfile
20
+ .*.swp
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in my_gem.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => 'v1.2.7'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Lin Salisbury
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ vagrant-vminfo
2
+ ==============
3
+
4
+ Vagrant Plugin to get detailed information about a VM.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Change to the directory of this file.
6
+ Dir.chdir(File.expand_path("../", __FILE__))
7
+
8
+ # For gem creation and bundling
9
+ require "bundler/gem_tasks"
10
+
11
+ # Install the `spec` task so that we can run tests.
12
+ RSpec::Core::RakeTask.new
13
+
14
+ # Default task is to build the gem
15
+ task :default => "build"
@@ -0,0 +1,71 @@
1
+ begin
2
+ require "vagrant"
3
+ require Vagrant.source_root.join('plugins/commands/up/start_mixins')
4
+ rescue LoadError
5
+ raise "The vagrant-vminfo vagrant plugin must be run with vagrant."
6
+ end
7
+
8
+ require "yaml"
9
+
10
+ # This is a sanity check to make sure no one is attempting to install
11
+ # this into an early Vagrant version.
12
+ if Vagrant::VERSION < "1.1.0"
13
+ raise "The vagrant-vminfo vagrant plugin is only compatible with Vagrant 1.1+"
14
+ end
15
+
16
+ module VagrantVminfo
17
+ class Plugin < Vagrant.plugin("2")
18
+ name "vagrant-vminfo"
19
+ description <<-DESC
20
+ This plugin provides the 'info' command that will display detailed information about the VM in YAML for easy parsing
21
+ DESC
22
+
23
+ command("info") do
24
+ InfoCommand
25
+ end
26
+ end
27
+
28
+ class InfoCommand < Vagrant.plugin(2, :command)
29
+ include VagrantPlugins::CommandUp::StartMixins
30
+
31
+ def execute
32
+ # Not sure if this is the only way to do this? How else would I get argv?
33
+ argv = parse_options(OptionParser.new)
34
+
35
+ info = {}
36
+
37
+ with_target_vms(argv) do |vm|
38
+ info["name"] = vm.name.id2name
39
+ info["id"] = vm.id
40
+ info["provider"] = vm.provider_name.id2name
41
+ info["networks"] = []
42
+
43
+ @nic_count = Integer(vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/Count")[/Value: (\d)/, 1])
44
+ (0..(@nic_count-1)).each do |i|
45
+ nic = {}
46
+
47
+ @nic_ip = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/IP")[/Value: (.*)/, 1]
48
+ @nic_mac = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/MAC")[/Value: (.*)/, 1]
49
+ @nic_broadcast = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Broadcast")[/Value: (.*)/, 1]
50
+ @nic_netmask = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Netmask")[/Value: (.*)/, 1]
51
+
52
+ # Get the number of this network device based on the mac address
53
+ # TODO: probably just should just get a hash of all of this info somehow, my ruby foo is weak
54
+ @nic_number = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/\w*(\d)=\"#{@nic_mac}\"/, 1]
55
+ @nic_type = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/nic#{@nic_number}=\"(.*)\"/, 1]
56
+
57
+ nic['ip'] = @nic_ip
58
+ nic['mac'] = @nic_mac
59
+ nic['netmask'] = @nic_netmask
60
+ nic['broadcast'] = @nic_broadcast
61
+ nic['type'] = @nic_type
62
+
63
+ # Append to the networks array
64
+ info["networks"] << nic
65
+ end
66
+ end
67
+
68
+ puts info.to_yaml
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantVminfo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ require "pathname"
2
+
3
+ module VagrantVminfo
4
+
5
+ def self.vagrant_vminfo_root
6
+ @vagrant_vminfo_root ||= Pathname.new(File.expand_path("../../", __FILE__))
7
+ end
8
+
9
+ def self.load_script(script_file_name)
10
+ File.read(expand_script_path(script_file_name))
11
+ end
12
+
13
+ def self.load_script_template(script_file_name, options)
14
+ Vagrant::Util::TemplateRenderer.render(expand_script_path(script_file_name), options)
15
+ end
16
+
17
+ end
18
+
19
+ require "vagrant-vminfo/plugin"
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/vagrant-vminfo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Lin Salisbury"]
6
+ gem.email = ["lin.salisbury@gmail.com"]
7
+ gem.description = %q{Plugin to get detailed VM info from Vagrant}
8
+ gem.summary = %q{Gets detailed information about the VM, including network interfaes}
9
+ gem.homepage = "https://github.com/d3vz3r0/vagrant-vminfo"
10
+
11
+ # The following block of code determines the files that should be included
12
+ # in the gem. It does this by reading all the files in the directory where
13
+ # this gemspec is, and parsing out the ignored files from the gitignore.
14
+ # Note that the entire gitignore(5) syntax is not supported, specifically
15
+ # the "!" syntax, but it should mostly work correctly.
16
+ root_path = File.dirname(__FILE__)
17
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
18
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
19
+ gitignore_path = File.join(root_path, ".gitignore")
20
+ gitignore = File.readlines(gitignore_path)
21
+ gitignore.map! { |line| line.chomp.strip }
22
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
23
+
24
+ unignored_files = all_files.reject do |file|
25
+ # Ignore any directories, the gemspec only cares about files
26
+ next true if File.directory?(file)
27
+
28
+ # Ignore any paths that match anything in the gitignore. We do
29
+ # two tests here:
30
+ #
31
+ # - First, test to see if the entire path matches the gitignore.
32
+ # - Second, match if the basename does, this makes it so that things
33
+ # like '.DS_Store' will match sub-directories too (same behavior
34
+ # as git).
35
+ #
36
+ gitignore.any? do |ignore|
37
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
38
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
39
+ end
40
+ end
41
+
42
+ gem.files = unignored_files
43
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
44
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
45
+ gem.name = "vagrant-vminfo"
46
+ gem.require_paths = ["lib"]
47
+ gem.version = VagrantVminfo::VERSION
48
+
49
+ gem.add_development_dependency "rake"
50
+ gem.add_development_dependency "rspec-core", "~> 2.12.2"
51
+ gem.add_development_dependency "rspec-expectations", "~> 2.12.1"
52
+ gem.add_development_dependency "rspec-mocks", "~> 2.12.1"
53
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-vminfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lin Salisbury
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-12 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.12.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-expectations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.12.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.12.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.12.1
69
+ description: Plugin to get detailed VM info from Vagrant
70
+ email:
71
+ - lin.salisbury@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - lib/vagrant-vminfo/plugin.rb
81
+ - lib/vagrant-vminfo/version.rb
82
+ - lib/vagrant-vminfo.rb
83
+ - vagrant-vminfo.gemspec
84
+ - .gitignore
85
+ homepage: https://github.com/d3vz3r0/vagrant-vminfo
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Gets detailed information about the VM, including network interfaes
108
+ test_files: []