vbinfo 0.0.2

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: aa63d72c7dd0e92e60828d316f84ebbd49a06095
4
+ data.tar.gz: ca373653e57bf715435a663339fba1b9129f57a3
5
+ SHA512:
6
+ metadata.gz: 13feb9a10106736431b66eb5dc3b103a0267a9d21fe8c0d5b29f32cf62630688e67ca556e877da1eb1fde8a39b1f76c2c52d8fae1cc9155b3f03c0d5df22b163
7
+ data.tar.gz: 5b1e4d1703ac509c7b95242a10e4bedc4e879ad3d3eddb73c0a863a100615f64c20ebecec9b2dcd4cf8ff370aa6af960df7cd2fc49b3fb898facc69e196d1587
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .vagrant*
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'mixlib-shellout'
5
+ gem 'rspec'
6
+
7
+
8
+ group :development do
9
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
10
+ end
11
+
12
+ group :plugins do
13
+ gem 'vbinfo', path: Dir.pwd
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Demitri Swan
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,325 @@
1
+ # Vbinfo
2
+
3
+ Vagrant plugin for outputing detailed VirtualBox information
4
+
5
+ ## Example
6
+
7
+ ```
8
+ vagrant vbinfo
9
+
10
+ {
11
+ "one": {
12
+ "guest_info": {
13
+ "/VirtualBox/GuestInfo/OS/Product": "Linux",
14
+ "/VirtualBox/GuestInfo/Net/0/V4/IP": "10.0.2.15",
15
+ "/VirtualBox/HostInfo/GUI/LanguageID": "en_US",
16
+ "/VirtualBox/GuestInfo/Net/0/MAC": "080027880CA6",
17
+ "/VirtualBox/GuestInfo/OS/ServicePack": "",
18
+ "/VirtualBox/HostInfo/VBoxVerExt": "4.3.28",
19
+ "/VirtualBox/GuestInfo/Net/0/V4/Netmask": "255.255.255.0",
20
+ "/VirtualBox/GuestInfo/OS/Version": "#36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012",
21
+ "/VirtualBox/GuestAdd/VersionExt": "4.2.0",
22
+ "/VirtualBox/GuestAdd/Revision": "80737",
23
+ "/VirtualBox/HostGuest/SysprepExec": "",
24
+ "/VirtualBox/GuestInfo/OS/LoggedInUsers": "0",
25
+ "/VirtualBox/GuestInfo/Net/0/Status": "Up",
26
+ "/VirtualBox/HostGuest/SysprepArgs": "",
27
+ "/VirtualBox/GuestAdd/Version": "4.2.0",
28
+ "/VirtualBox/HostInfo/VBoxRev": "100309",
29
+ "/VirtualBox/GuestInfo/Net/0/V4/Broadcast": "10.0.2.255",
30
+ "/VirtualBox/HostInfo/VBoxVer": "4.3.28",
31
+ "/VirtualBox/GuestInfo/OS/LoggedInUsersList": "",
32
+ "/VirtualBox/GuestInfo/Net/Count": "1",
33
+ "/VirtualBox/GuestInfo/OS/Release": "3.2.0-23-generic",
34
+ "/VirtualBox/GuestInfo/OS/NoLoggedInUsers": "true"
35
+ },
36
+ "vm_info": {
37
+ "name": "vbinfo_one_1434365694270_58415",
38
+ "groups": "/",
39
+ "ostype": "Ubuntu (64 bit)",
40
+ "UUID": "98e3ea7e-738f-43ca-a40d-a2c98c5d4a3b",
41
+ "CfgFile": "/Users/demitri/VirtualBox VMs/vbinfo_one_1434365694270_58415/vbinfo_one_1434365694270_58415.vbox",
42
+ "SnapFldr": "/Users/demitri/VirtualBox VMs/vbinfo_one_1434365694270_58415/Snapshots",
43
+ "LogFldr": "/Users/demitri/VirtualBox VMs/vbinfo_one_1434365694270_58415/Logs",
44
+ "hardwareuuid": "98e3ea7e-738f-43ca-a40d-a2c98c5d4a3b",
45
+ "memory": "512",
46
+ "pagefusion": "off",
47
+ "vram": "8",
48
+ "cpuexecutioncap": "100",
49
+ "hpet": "off",
50
+ "chipset": "piix3",
51
+ "firmware": "BIOS",
52
+ "cpus": "2",
53
+ "pae": "on",
54
+ "longmode": "on",
55
+ "synthcpu": "off",
56
+ "bootmenu": "messageandmenu",
57
+ "boot1": "disk",
58
+ "boot2": "dvd",
59
+ "boot3": "none",
60
+ "boot4": "none",
61
+ "acpi": "on",
62
+ "ioapic": "on",
63
+ "biossystemtimeoffset": "0",
64
+ "rtcuseutc": "on",
65
+ "hwvirtex": "on",
66
+ "nestedpaging": "on",
67
+ "largepages": "on",
68
+ "vtxvpid": "on",
69
+ "vtxux": "on",
70
+ "VMState": "running",
71
+ "VMStateChangeTime": "2015-06-15T10:54:55.909000000",
72
+ "monitorcount": "1",
73
+ "accelerate3d": "off",
74
+ "accelerate2dvideo": "off",
75
+ "teleporterenabled": "off",
76
+ "teleporterport": "0",
77
+ "teleporteraddress": "",
78
+ "teleporterpassword": "",
79
+ "tracing-enabled": "off",
80
+ "tracing-allow-vm-access": "off",
81
+ "tracing-config": "",
82
+ "autostart-enabled": "off",
83
+ "autostart-delay": "0",
84
+ "defaultfrontend": "",
85
+ "storagecontrollername0": "IDE Controller",
86
+ "storagecontrollertype0": "PIIX4",
87
+ "storagecontrollerinstance0": "0",
88
+ "storagecontrollermaxportcount0": "2",
89
+ "storagecontrollerportcount0": "2",
90
+ "storagecontrollerbootable0": "on",
91
+ "storagecontrollername1": "SATA Controller",
92
+ "storagecontrollertype1": "IntelAhci",
93
+ "storagecontrollerinstance1": "0",
94
+ "storagecontrollermaxportcount1": "30",
95
+ "storagecontrollerportcount1": "1",
96
+ "storagecontrollerbootable1": "on",
97
+ "IDE Controller-0-0": "emptydrive",
98
+ "IDE Controller-IsEjected": "off",
99
+ "IDE Controller-0-1": "none",
100
+ "IDE Controller-1-0": "emptydrive",
101
+ "IDE Controller-1-1": "none",
102
+ "SATA Controller-0-0": "/Users/demitri/VirtualBox VMs/vbinfo_one_1434365694270_58415/box-disk1.vmdk",
103
+ "SATA Controller-ImageUUID-0-0": "7a8132f6-1ae6-4415-8e05-0994b71f5a5e",
104
+ "natnet1": "nat",
105
+ "macaddress1": "080027880CA6",
106
+ "cableconnected1": "on",
107
+ "nic1": "nat",
108
+ "nictype1": "82540EM",
109
+ "nicspeed1": "0",
110
+ "mtu": "0",
111
+ "sockSnd": "64",
112
+ "sockRcv": "64",
113
+ "tcpWndSnd": "64",
114
+ "tcpWndRcv": "64",
115
+ "Forwarding(0)": "ssh,tcp,127.0.0.1,2201,,22",
116
+ "nic2": "none",
117
+ "nic3": "none",
118
+ "nic4": "none",
119
+ "nic5": "none",
120
+ "nic6": "none",
121
+ "nic7": "none",
122
+ "nic8": "none",
123
+ "hidpointing": "ps2mouse",
124
+ "hidkeyboard": "ps2kbd",
125
+ "uart1": "off",
126
+ "uart2": "off",
127
+ "lpt1": "off",
128
+ "lpt2": "off",
129
+ "audio": "none",
130
+ "clipboard": "disabled",
131
+ "draganddrop": "disabled",
132
+ "SessionType": "headless",
133
+ "VideoMode": "640,480,32@0,0",
134
+ "vrde": "off",
135
+ "usb": "off",
136
+ "ehci": "off",
137
+ "SharedFolderNameMachineMapping1": "vagrant",
138
+ "SharedFolderPathMachineMapping1": "/Users/demitri/Ruby/vbinfo",
139
+ "VRDEActiveConnection": "off",
140
+ "VRDEClients": "0",
141
+ "vcpenabled": "off",
142
+ "vcpscreens": "0",
143
+ "vcpfile": "/Users/demitri/VirtualBox VMs/vbinfo_one_1434365694270_58415/vbinfo_one_1434365694270_58415.webm",
144
+ "vcpwidth": "1024",
145
+ "vcpheight": "768",
146
+ "vcprate": "512",
147
+ "vcpfps": "25",
148
+ "GuestMemoryBalloon": "0",
149
+ "GuestOSType": "Linux26_64",
150
+ "GuestAdditionsRunLevel": "2",
151
+ "GuestAdditionsVersion": "4.2.0 r80737",
152
+ "GuestAdditionsFacility_VirtualBox Base Driver": "50,1434365701764",
153
+ "GuestAdditionsFacility_VirtualBox System Service": "50,1434365702775",
154
+ "GuestAdditionsFacility_Seamless Mode": "0,1434365701764",
155
+ "GuestAdditionsFacility_Graphics Mode": "0,1434365701764"
156
+ }
157
+ },
158
+ "two": {
159
+ "guest_info": {
160
+ "/VirtualBox/GuestInfo/OS/Product": "Linux",
161
+ "/VirtualBox/GuestInfo/Net/0/V4/IP": "10.0.2.15",
162
+ "/VirtualBox/HostInfo/GUI/LanguageID": "en_US",
163
+ "/VirtualBox/GuestInfo/Net/0/MAC": "080027880CA6",
164
+ "/VirtualBox/GuestInfo/OS/ServicePack": "",
165
+ "/VirtualBox/HostInfo/VBoxVerExt": "4.3.28",
166
+ "/VirtualBox/GuestInfo/Net/0/V4/Netmask": "255.255.255.0",
167
+ "/VirtualBox/GuestInfo/OS/Version": "#36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012",
168
+ "/VirtualBox/GuestAdd/VersionExt": "4.2.0",
169
+ "/VirtualBox/GuestAdd/Revision": "80737",
170
+ "/VirtualBox/HostGuest/SysprepExec": "",
171
+ "/VirtualBox/GuestInfo/OS/LoggedInUsers": "0",
172
+ "/VirtualBox/GuestInfo/Net/0/Status": "Up",
173
+ "/VirtualBox/HostGuest/SysprepArgs": "",
174
+ "/VirtualBox/GuestAdd/Version": "4.2.0",
175
+ "/VirtualBox/HostInfo/VBoxRev": "100309",
176
+ "/VirtualBox/GuestInfo/Net/0/V4/Broadcast": "10.0.2.255",
177
+ "/VirtualBox/HostInfo/VBoxVer": "4.3.28",
178
+ "/VirtualBox/GuestInfo/OS/LoggedInUsersList": "",
179
+ "/VirtualBox/GuestInfo/Net/Count": "1",
180
+ "/VirtualBox/GuestInfo/OS/Release": "3.2.0-23-generic",
181
+ "/VirtualBox/GuestInfo/OS/NoLoggedInUsers": "true"
182
+ },
183
+ "vm_info": {
184
+ "name": "vbinfo_two_1434365710829_69997",
185
+ "groups": "/",
186
+ "ostype": "Ubuntu (64 bit)",
187
+ "UUID": "717227d2-bd01-4d24-8aa1-4c588f98159a",
188
+ "CfgFile": "/Users/demitri/VirtualBox VMs/vbinfo_two_1434365710829_69997/vbinfo_two_1434365710829_69997.vbox",
189
+ "SnapFldr": "/Users/demitri/VirtualBox VMs/vbinfo_two_1434365710829_69997/Snapshots",
190
+ "LogFldr": "/Users/demitri/VirtualBox VMs/vbinfo_two_1434365710829_69997/Logs",
191
+ "hardwareuuid": "717227d2-bd01-4d24-8aa1-4c588f98159a",
192
+ "memory": "1024",
193
+ "pagefusion": "off",
194
+ "vram": "8",
195
+ "cpuexecutioncap": "100",
196
+ "hpet": "off",
197
+ "chipset": "piix3",
198
+ "firmware": "BIOS",
199
+ "cpus": "2",
200
+ "pae": "on",
201
+ "longmode": "on",
202
+ "synthcpu": "off",
203
+ "bootmenu": "messageandmenu",
204
+ "boot1": "disk",
205
+ "boot2": "dvd",
206
+ "boot3": "none",
207
+ "boot4": "none",
208
+ "acpi": "on",
209
+ "ioapic": "on",
210
+ "biossystemtimeoffset": "0",
211
+ "rtcuseutc": "on",
212
+ "hwvirtex": "on",
213
+ "nestedpaging": "on",
214
+ "largepages": "on",
215
+ "vtxvpid": "on",
216
+ "vtxux": "on",
217
+ "VMState": "running",
218
+ "VMStateChangeTime": "2015-06-15T10:55:12.554000000",
219
+ "monitorcount": "1",
220
+ "accelerate3d": "off",
221
+ "accelerate2dvideo": "off",
222
+ "teleporterenabled": "off",
223
+ "teleporterport": "0",
224
+ "teleporteraddress": "",
225
+ "teleporterpassword": "",
226
+ "tracing-enabled": "off",
227
+ "tracing-allow-vm-access": "off",
228
+ "tracing-config": "",
229
+ "autostart-enabled": "off",
230
+ "autostart-delay": "0",
231
+ "defaultfrontend": "",
232
+ "storagecontrollername0": "IDE Controller",
233
+ "storagecontrollertype0": "PIIX4",
234
+ "storagecontrollerinstance0": "0",
235
+ "storagecontrollermaxportcount0": "2",
236
+ "storagecontrollerportcount0": "2",
237
+ "storagecontrollerbootable0": "on",
238
+ "storagecontrollername1": "SATA Controller",
239
+ "storagecontrollertype1": "IntelAhci",
240
+ "storagecontrollerinstance1": "0",
241
+ "storagecontrollermaxportcount1": "30",
242
+ "storagecontrollerportcount1": "1",
243
+ "storagecontrollerbootable1": "on",
244
+ "IDE Controller-0-0": "emptydrive",
245
+ "IDE Controller-IsEjected": "off",
246
+ "IDE Controller-0-1": "none",
247
+ "IDE Controller-1-0": "emptydrive",
248
+ "IDE Controller-1-1": "none",
249
+ "SATA Controller-0-0": "/Users/demitri/VirtualBox VMs/vbinfo_two_1434365710829_69997/box-disk1.vmdk",
250
+ "SATA Controller-ImageUUID-0-0": "aadcc7db-d597-44bb-8d28-d5573168a9f0",
251
+ "natnet1": "nat",
252
+ "macaddress1": "080027880CA6",
253
+ "cableconnected1": "on",
254
+ "nic1": "nat",
255
+ "nictype1": "82540EM",
256
+ "nicspeed1": "0",
257
+ "mtu": "0",
258
+ "sockSnd": "64",
259
+ "sockRcv": "64",
260
+ "tcpWndSnd": "64",
261
+ "tcpWndRcv": "64",
262
+ "Forwarding(0)": "ssh,tcp,127.0.0.1,2202,,22",
263
+ "nic2": "none",
264
+ "nic3": "none",
265
+ "nic4": "none",
266
+ "nic5": "none",
267
+ "nic6": "none",
268
+ "nic7": "none",
269
+ "nic8": "none",
270
+ "hidpointing": "ps2mouse",
271
+ "hidkeyboard": "ps2kbd",
272
+ "uart1": "off",
273
+ "uart2": "off",
274
+ "lpt1": "off",
275
+ "lpt2": "off",
276
+ "audio": "none",
277
+ "clipboard": "disabled",
278
+ "draganddrop": "disabled",
279
+ "SessionType": "headless",
280
+ "VideoMode": "640,480,32@0,0",
281
+ "vrde": "off",
282
+ "usb": "off",
283
+ "ehci": "off",
284
+ "SharedFolderNameMachineMapping1": "vagrant",
285
+ "SharedFolderPathMachineMapping1": "/Users/demitri/Ruby/vbinfo",
286
+ "VRDEActiveConnection": "off",
287
+ "VRDEClients": "0",
288
+ "vcpenabled": "off",
289
+ "vcpscreens": "0",
290
+ "vcpfile": "/Users/demitri/VirtualBox VMs/vbinfo_two_1434365710829_69997/vbinfo_two_1434365710829_69997.webm",
291
+ "vcpwidth": "1024",
292
+ "vcpheight": "768",
293
+ "vcprate": "512",
294
+ "vcpfps": "25",
295
+ "GuestMemoryBalloon": "0",
296
+ "GuestOSType": "Linux26_64",
297
+ "GuestAdditionsRunLevel": "2",
298
+ "GuestAdditionsVersion": "4.2.0 r80737",
299
+ "GuestAdditionsFacility_VirtualBox Base Driver": "50,1434365717807",
300
+ "GuestAdditionsFacility_VirtualBox System Service": "50,1434365718605",
301
+ "GuestAdditionsFacility_Seamless Mode": "0,1434365717807",
302
+ "GuestAdditionsFacility_Graphics Mode": "0,1434365717807"
303
+ }
304
+ }
305
+ }
306
+ ```
307
+
308
+ ## Development
309
+ * Fork project
310
+ * Create topic branch in your fork for a given patch/feature
311
+ * vagrant init && vagrant up # this will give you data to work with
312
+ * Install RVM (if not installed)
313
+ * Create gemset for the patch/feature
314
+ * Activate rvm/gemset
315
+ * Install bundler (gem install --version 1.7.15 bundler) # It has to be before version 1.8 which is a vagrant dependency
316
+ * bundle install
317
+ * rake
318
+ * bundle exec vagrant vbinfo
319
+
320
+ If this works, you'll see json output for each configured VM in the Vagrantfile. When
321
+ you're done with your patch/feature, submit a pull request, comparing your topic branch to
322
+ the vbinfo develop branch. Simply run rake to run the integration tests.
323
+
324
+ ## To Do
325
+ * Try on windows
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'bundler/setup'
4
+ require_relative 'tests/integration/spec/spec_helper'
5
+ require 'rspec/core/rake_task'
6
+
7
+ # Immediately sync
8
+ $stdout.sync = true
9
+ $stderr.sync = true
10
+
11
+ begin
12
+ desc "Run RSpec tests for a single vm"
13
+ RSpec::Core::RakeTask.new(:single) do |spec|
14
+ spec.pattern = 'tests/integration/spec/single_spec.rb'
15
+ spec.rspec_opts = '--color'
16
+ spec.rspec_opts = '-fd'
17
+ end
18
+
19
+ desc "Run RSpec tests for two vms"
20
+ RSpec::Core::RakeTask.new(:double) do |spec|
21
+ spec.pattern = 'tests/integration/spec/double_spec.rb'
22
+ spec.rspec_opts = '--color'
23
+ spec.rspec_opts = '-fd'
24
+ end
25
+
26
+ desc "Cleanup VMs"
27
+ task :clean do
28
+ Helper.destroy_existing_vms
29
+ end
30
+
31
+ # Declare test dependencies
32
+ task :test => [:single, :double, :clean]
33
+
34
+ # Set default to test
35
+ task :default => :test
36
+
37
+ ensure
38
+ Helper.destroy_existing_vms
39
+ end
40
+
41
+ # This gives us exposure to some rasks related
42
+ # to packaging, installing, and releasing the
43
+ # gem. Run rake -T to see the list of available
44
+ # tasks
45
+ Dir.chdir(File.expand_path("../", __FILE__))
46
+ Bundler::GemHelper.install_tasks
data/lib/command.rb ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'find'
4
+ require 'mixlib/shellout'
5
+ require 'vagrant'
6
+ require 'optparse'
7
+ require 'json'
8
+
9
+ module Vbinfo
10
+ class Command < Vagrant.plugin("2", :command)
11
+
12
+ def self.synopsis
13
+ "outputs information for each Virtualbox VM"
14
+ end
15
+
16
+ # return an array of hashes, each hash containing the
17
+ # name and id. Single VM configurations typically are
18
+ # named default, while multiple VM configurations
19
+ # are named individually.
20
+ def ids
21
+ a = Array.new
22
+ Find.find("#{ENV['PWD']}/.vagrant") do |item|
23
+ if File.file?(item) and File.basename(item) == 'id'
24
+ h = Hash.new
25
+ # Id will be found in the id file
26
+ file = File.open(item)
27
+ h["id"] = file.read
28
+ # the name will be in /<name>/virtualbox/id of path
29
+ regex_obj = Regexp.new('[^\/]*(?=/virtualbox)')
30
+ h["name"] = item[regex_obj]
31
+ a << h
32
+ file.close
33
+ end
34
+ end
35
+ return a
36
+ end
37
+
38
+ # Check for vboxmanage and exit 1 if not available
39
+ def vboxmanage?
40
+ # Fail if vboxmanage does not exist in the path
41
+ if not Vagrant::Util::Which.which('vboxmanage')
42
+ raise Vagrant::Errors::CommandUnavailable, file: 'vboxmanage'
43
+ exit 1
44
+ else
45
+ true
46
+ end
47
+ end
48
+
49
+ # Print detailed info for the given VM ID
50
+ def show_vm_info(id)
51
+ if vboxmanage?
52
+ # Return the output
53
+ command = Mixlib::ShellOut.new("vboxmanage showvminfo --machinereadable #{id}")
54
+ command.run_command
55
+ return command.stdout
56
+ end
57
+ end
58
+
59
+ # Get hash
60
+ def get_vm_hash(str)
61
+ h = Hash.new
62
+ lines = str.split("\n")
63
+ lines.each do |line|
64
+ key, val = line.split("=")
65
+ [key, val].each do |item|
66
+ item.tr!('"', '')
67
+ end
68
+ h[key.to_s] = val.to_s
69
+ end
70
+ return h
71
+ end
72
+
73
+ def enumerate_guest_info(id)
74
+ if vboxmanage?
75
+ command = Mixlib::ShellOut.new("vboxmanage guestproperty enumerate #{id}")
76
+ command.run_command
77
+ return command.stdout
78
+ end
79
+ end
80
+
81
+ def get_guest_hash(str)
82
+ h = Hash.new
83
+ lines = str.split("\n")
84
+ lines.each do |line|
85
+ name_match = Regexp.new("(?<=Name: )[^,]*")
86
+ value_match = Regexp.new("(?<=value: )[^,]*")
87
+ name = line[name_match]
88
+ value = line[value_match]
89
+ h[name] = value
90
+ end
91
+ return h
92
+ end
93
+
94
+ # Print detailed information for each Virtualbox VM associated with
95
+ # the project in the current directory
96
+ def execute
97
+ total_hash = Hash.new
98
+ ids.each do |id|
99
+ mini_hash = Hash.new
100
+ name = id['name']
101
+ i = id['id']
102
+ guest_str = enumerate_guest_info(i).to_s
103
+ guest_hash = get_guest_hash(guest_str)
104
+ mini_hash['guest_info'] = guest_hash
105
+ vm_str = show_vm_info(i).to_s
106
+ vm_hash = get_vm_hash(vm_str)
107
+ mini_hash['vm_info'] = vm_hash
108
+ total_hash[name] = mini_hash
109
+ end
110
+ if total_hash.empty?
111
+ @env.ui.info("No Virtualbox data was found")
112
+ else
113
+ @env.ui.info(JSON.pretty_generate(total_hash))
114
+ end
115
+ exit 0
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Vbinfo
4
+ VERSION = "0.0.2"
5
+ end
data/lib/vbinfo.rb ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vagrant'
4
+
5
+ module Vbinfo
6
+ class Plugin < Vagrant.plugin("2")
7
+ name "vbinfo"
8
+ description <<-DESC
9
+ The `vbinfo` command gives you detailed information for
10
+ configured virtualbox vms
11
+ DESC
12
+
13
+ command("vbinfo") do
14
+ require_relative "command"
15
+ Command
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe 'vbinfo' do
6
+ before(:all) do
7
+ Helper.setup
8
+ end
9
+
10
+ describe 'when configured with two VMs' do
11
+ vfile = <<-VFILE
12
+ Vagrant.configure(2) do |config|
13
+ config.vm.box = 'hashicorp/precise64'
14
+ config.vm.define 'one' do |one|
15
+ one.vm.hostname = 'one'
16
+ one.vm.provider 'virtualbox' do |v|
17
+ v.memory = '256'
18
+ end
19
+ end
20
+ config.vm.define 'two' do |two|
21
+ two.vm.hostname = 'two'
22
+ two.vm.provider 'virtualbox' do |v|
23
+ v.memory = '256'
24
+ end
25
+ end
26
+ end
27
+ VFILE
28
+
29
+ hash = Helper.prep_test(vfile)
30
+
31
+ it 'output should be a hash' do
32
+ expect(hash.class).to eql(Hash)
33
+ end
34
+
35
+ it 'hash should have two root objects' do
36
+ expect(hash.size).to eql(2)
37
+ end
38
+
39
+ it 'first vm should have vm_info: memory' do
40
+ expect(hash['one']['vm_info']['memory']).to eql('256')
41
+ end
42
+
43
+ it 'second vm should have vm_info: memory' do
44
+ expect(hash['two']['vm_info']['memory']).to eql('256')
45
+ end
46
+
47
+ it 'first vm should contain guest key: /VirtualBox/GuestInfo/Net/0/V4/IP' do
48
+ expect(hash['one']['guest_info'].has_key?('/VirtualBox/GuestInfo/Net/0/V4/IP')).to be true
49
+ end
50
+
51
+ it 'second vm should contain guest key: /VirtualBox/GuestInfo/Net/0/V4/IP' do
52
+ expect(hash['two']['guest_info'].has_key?('/VirtualBox/GuestInfo/Net/0/V4/IP')).to be true
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe 'vbinfo' do
6
+
7
+ before(:all) do
8
+ Helper.setup
9
+ end
10
+
11
+ describe 'when configured with one VM' do
12
+
13
+ vfile = <<-VFILE
14
+ Vagrant.configure(2) do |config|
15
+ config.vm.box = "hashicorp/precise64"
16
+ config.vm.hostname = 'testbox'
17
+ config.vm.provider 'virtualbox' do |v|
18
+ v.memory = 512
19
+ end
20
+ end
21
+ VFILE
22
+
23
+ hash = Helper.prep_test(vfile)
24
+
25
+ it 'output should be a hash' do
26
+ expect(hash.class).to eq(Hash)
27
+ end
28
+
29
+ it 'hash should have one root value' do
30
+ expect(hash.size).to eq(1)
31
+ end
32
+
33
+ it 'hash should contain vm_info: memory' do
34
+ expect(hash['default']['vm_info']['memory']).to eq('512')
35
+ end
36
+
37
+ it 'hash should contain guest key: /VirtualBox/GuestInfo/Net/0/V4/IP' do
38
+ expect(hash['default']['guest_info'].has_key?('/VirtualBox/GuestInfo/Net/0/V4/IP')).to be true
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,74 @@
1
+ #/usr/bin/env ruby
2
+
3
+ require 'rspec'
4
+ require 'json'
5
+ require 'fileutils'
6
+
7
+ # Helper methods for tests and rake activities.
8
+ module Helper
9
+
10
+ # For destroying all vms that match vbinfo.
11
+ def self.destroy_existing_vms
12
+
13
+ sleep 2
14
+
15
+ output = `vboxmanage list vms`
16
+ vms = output.scan(/vbinfo[^\"]*/)
17
+ vms.each do |vm|
18
+ `vboxmanage controlvm #{vm} poweroff 2> /dev/null`
19
+ sleep 2
20
+ `vboxmanage unregistervm #{vm} --delete 2> /dev/null`
21
+ sleep 2
22
+ end
23
+ end
24
+
25
+ # To be executed in a before rspec hook
26
+ def self.setup
27
+ # Destroy previous vms
28
+ destroy_existing_vms
29
+
30
+ # Remove data dir if present
31
+ if File.directory?('.vagrant')
32
+ FileUtils.rm_rf('.vagrant')
33
+ end
34
+
35
+ # Remove Vagrantfile if present
36
+ if File.exist?('Vagrantfile')
37
+ File.delete('Vagrantfile')
38
+ end
39
+
40
+ # initialize vagrant in project dir
41
+ `bundler exec vagrant init`
42
+ end
43
+
44
+ # Normally, there would just be one block of
45
+ # code passed to the before rspec hook to execute
46
+ # code before the examples. However, there is a
47
+ # need to pass in values and before doesn't take
48
+ # an arbitrary list. We'll just execute this method
49
+ # in each test and pass the Vagrantfile as a raw
50
+ # string to further prepare the directory for testing.
51
+ def self.prep_test(vfile)
52
+ begin
53
+ f = File.open('Vagrantfile', 'w')
54
+ f.write(vfile)
55
+ ensure
56
+ f.close
57
+ end
58
+
59
+ # Execute plugin
60
+ `bundler exec vagrant up`
61
+ json = `bundler exec vagrant vbinfo`
62
+ # Strip warning string that we are executing in a
63
+ # non-standard environment (dev env)
64
+ json.sub!(/[^{]*?(?={)/,'')
65
+ hash = JSON.parse(json)
66
+ end
67
+
68
+ end
69
+
70
+
71
+
72
+
73
+
74
+
data/vbinfo.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'command/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vbinfo"
8
+ spec.version = Vbinfo::VERSION
9
+ spec.authors = ["Demitri Swan"]
10
+ spec.email = ["demitriswan@gmail.com"]
11
+ spec.summary = %q{Print detailed information for virtualbox VMs managed by Vagrant}
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_runtime_dependency "mixlib-shellout", "~> 2.1"
22
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vbinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Demitri Swan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-26 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ - !ruby/object:Gem::Dependency
42
+ name: mixlib-shellout
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ description:
56
+ email:
57
+ - demitriswan@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/command.rb
68
+ - lib/command/version.rb
69
+ - lib/vbinfo.rb
70
+ - tests/integration/spec/double_spec.rb
71
+ - tests/integration/spec/single_spec.rb
72
+ - tests/integration/spec/spec_helper.rb
73
+ - vbinfo.gemspec
74
+ homepage:
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Print detailed information for virtualbox VMs managed by Vagrant
98
+ test_files: []