vgrnt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +4 -0
- data/README.md +112 -0
- data/Rakefile +2 -0
- data/Vagrantfile +25 -0
- data/bin/vgrnt +10 -0
- data/docs/DEVNOTES.md +35 -0
- data/docs/vboxmanage-irregular-commands.txt +167 -0
- data/lib/vgrnt.rb +1 -0
- data/lib/vgrnt/base.rb +172 -0
- data/lib/vgrnt/version.rb +3 -0
- data/vgrnt.gemspec +22 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 815a34d3ad9933b38be14aac97d5114a34a47982
|
4
|
+
data.tar.gz: 4705335e2f3422f6752606d2b19945bd6d0c7074
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 744e40c28684d12c691b4dd519852455003a69c26a26fd73dfdd9cf0071f0c6e3093933539f3bee5f341809a83442564298fce734d397780996cfd661199e962
|
7
|
+
data.tar.gz: 6ed46dbdd0bc8d15ef0883491e9b69535ee2b27c178dcbc3ad2560626c6c55d163937eb7083317b25121e00b351f04b9cfd9df75a1b92b1492989ec4766aea5b
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## [0.0.2](https://github.com/dergachev/vagrant/compare/v0.0.1...v0.0.2) (Oct 30, 2013)
|
2
|
+
|
3
|
+
IMPROVEMENTS:
|
4
|
+
|
5
|
+
- ..
|
6
|
+
|
7
|
+
## [0.0.1](https://github.com/dergachev/vgrnt/commits/v0.0.1) (Oct 30, 2013)
|
8
|
+
|
9
|
+
BACKWARDS INCOMPATIBILITIES:
|
10
|
+
|
11
|
+
- none
|
12
|
+
|
13
|
+
FEATURES:
|
14
|
+
|
15
|
+
- Initial release
|
16
|
+
|
17
|
+
IMPROVEMENTS:
|
18
|
+
|
19
|
+
- none
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
vgrnt
|
2
|
+
=====
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/vgrnt.png)](http://badge.fury.io/rb/vgrnt)
|
5
|
+
|
6
|
+
`vgrnt` is a partial reimplementation of a few `vagrant` operations that I
|
7
|
+
found to be unbearably slow. For example:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
time vagrant ssh -- '/bin/true'
|
11
|
+
# real 0m1.969s
|
12
|
+
|
13
|
+
time vgrnt ssh -- '/bin/true'
|
14
|
+
# real 0m0.538s
|
15
|
+
```
|
16
|
+
|
17
|
+
It achieves this by naively reimplementing these commands, without requiring
|
18
|
+
superfluous gems (not even vagrant) or parsing the Vagrantfile. Given how
|
19
|
+
ashamed I am of such ugly hacks, the name `vgrnt` was chosen to be deliberately
|
20
|
+
unpronouncable. If you must use it, probably best to keep it to yourself.
|
21
|
+
|
22
|
+
|
23
|
+
## vgrnt ssh
|
24
|
+
|
25
|
+
Same as `vagrant ssh` but faster. Will read `.vgrnt-sshconfig` file for SSH options, or try to
|
26
|
+
guess the options by shelling out to VBoxManage.
|
27
|
+
|
28
|
+
```
|
29
|
+
vgrnt ssh
|
30
|
+
vgrnt ssh vm-name # supports multi-vm environments
|
31
|
+
vgrnt ssh -- ls /tmp # extra ssh args after --
|
32
|
+
```
|
33
|
+
|
34
|
+
## vgrnt ssh-config
|
35
|
+
|
36
|
+
Runs `vgrnt ssh-config > .vgrnt-sshconfig`. Use this if `vgrnt ssh` doesn't
|
37
|
+
seem to work, because you have a non-standard setup.
|
38
|
+
|
39
|
+
```
|
40
|
+
vgrnt ssh-config
|
41
|
+
# => creates .vgrnt-sshconfig; will get picked up by 'vgrnt ssh'
|
42
|
+
|
43
|
+
vgrnt ssh-config vm-name # supports multi-vm environments
|
44
|
+
```
|
45
|
+
|
46
|
+
## vgrnt vboxmanage
|
47
|
+
|
48
|
+
Simplifies calling `VBoxManage` on the already created VM. Injects
|
49
|
+
the VM ID (eg 0398e43a-d35f-4c84-bc81-6807f5d11262) in the right spot.
|
50
|
+
|
51
|
+
```
|
52
|
+
vgrnt vboxmanage showvminfo --details
|
53
|
+
# => equivalent to: VBoxManage showvminfo 0398e43a-d35f-4c84-bc81-6807f5d11262 --details
|
54
|
+
|
55
|
+
vgrnt vboxmanage vm-name showvminfo # supports multi-vm environments
|
56
|
+
```
|
57
|
+
|
58
|
+
Certain [VBoxManage subcommands](https://github.com/dergachev/vgrnt/blob/master/docs/vboxmanage-irregular-commands.txt)
|
59
|
+
have irregular syntax, so you need to specify where
|
60
|
+
to inject the VM_ID token:
|
61
|
+
|
62
|
+
```
|
63
|
+
vgrnt vboxmanage metrics query VM_ID
|
64
|
+
# => VBoxManage metrics query 0398e43a-d35f-4c84-bc81-6807f5d11262
|
65
|
+
```
|
66
|
+
|
67
|
+
## TODO
|
68
|
+
|
69
|
+
* vgrnt status (can pull it out from vboxmanage)
|
70
|
+
* vgrnt reprovision (equivalent to running `vagrant ssh -- chef-solo /tmp...`
|
71
|
+
* vgrnt destroy (how hard is it to kill a VM??)
|
72
|
+
* vgrnt snapshot (it's currently implemented as a vagrant plugin, but who needs decoupling?)
|
73
|
+
|
74
|
+
## Caveats
|
75
|
+
|
76
|
+
|
77
|
+
* At the moment, it requires OSX/Linux and Virtualbox.
|
78
|
+
* Only works from vagrant project root, not in a subfolder
|
79
|
+
* Tests, what tests?
|
80
|
+
|
81
|
+
## Installation
|
82
|
+
|
83
|
+
vgrnt *should not* be installed as a vagrant plugin. Instead, simply
|
84
|
+
Ensure you have Vagrant 1.1+ installed, then run:
|
85
|
+
|
86
|
+
gem install vgrnt --no-rdoc --no-ri
|
87
|
+
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
To develop on this plugin, do the following:
|
92
|
+
|
93
|
+
```
|
94
|
+
# get the repo, and then make a feature branch (REPLACE WITH YOUR FORK)
|
95
|
+
git clone https://github.com/dergachev/vagrant-vboxmanage.git
|
96
|
+
cd vagrant-vboxmanage
|
97
|
+
git checkout -b MY-NEW-FEATURE
|
98
|
+
|
99
|
+
# installs the vagrant gem, which is a dev dependency
|
100
|
+
bundle install
|
101
|
+
|
102
|
+
# hack on the plugin
|
103
|
+
vim lib/vagrant-vboxmanage.rb # or any other file
|
104
|
+
|
105
|
+
# test out your changes, in the context provided by the development vagrant gem, and the local Vagrantfile.
|
106
|
+
bundle exec vagrant snapshot ...
|
107
|
+
|
108
|
+
# commit, push, and do a pull-request
|
109
|
+
```
|
110
|
+
|
111
|
+
See [DEVNOTES.md](https://github.com/dergachev/vagrant-vboxmanage/blob/master/DEVNOTES.md)
|
112
|
+
for the notes I compiled while developing this plugin.
|
data/Rakefile
ADDED
data/Vagrantfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# vi: set ft=ruby :
|
4
|
+
|
5
|
+
# this Vagrantfile is including for testing purposes
|
6
|
+
|
7
|
+
Vagrant.configure("2") do |config|
|
8
|
+
|
9
|
+
TEST_MULTI_VM = false
|
10
|
+
|
11
|
+
if TEST_MULTI_VM
|
12
|
+
config.vm.define :web do |web|
|
13
|
+
web.vm.box = "precise64"
|
14
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
15
|
+
end
|
16
|
+
config.vm.define :db do |web|
|
17
|
+
web.vm.box = "precise64"
|
18
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
config.vm.box = "precise64"
|
22
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/bin/vgrnt
ADDED
data/docs/DEVNOTES.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Developer notes for vgrnt
|
2
|
+
|
3
|
+
## Packaging a gem
|
4
|
+
|
5
|
+
See https://github.com/dergachev/vagrant-vbox-snapshot/blob/master/DEVNOTES.md#pushing-out-a-new-release-of-the-gem
|
6
|
+
|
7
|
+
In the future, also consider this workflow:
|
8
|
+
|
9
|
+
```
|
10
|
+
git clone https://github.com/dergachev/vgrnt.git ~/code/vgrnt
|
11
|
+
cd ~/code/vgrnt
|
12
|
+
|
13
|
+
# after making code changes, increment version number, build the gem locally
|
14
|
+
vim lib/vgrnt/version.rb +/VERSION # increment version counter, eg to 0.0.3
|
15
|
+
rake build # package the gem into ./pkg/vgrnt-0.0.3.gem
|
16
|
+
|
17
|
+
# install and test the gem locally
|
18
|
+
gem uninstall vgrnt
|
19
|
+
gem install pkg/vgrnt-0.0.3.gem
|
20
|
+
cd ~/code/screengif
|
21
|
+
vgrnt ssh -- ls /
|
22
|
+
|
23
|
+
# commit and publish the gem
|
24
|
+
vim CHANGELOG.md # add v0.0.3 details
|
25
|
+
git commit -m "Publishing v0.0.3" CHANGELOG.md lib/vgrnt/version.rb
|
26
|
+
|
27
|
+
rake release
|
28
|
+
git push --tags
|
29
|
+
```
|
30
|
+
|
31
|
+
## Creating a gem
|
32
|
+
|
33
|
+
* http://timelessrepo.com/making-ruby-gems
|
34
|
+
* http://asciicasts.com/episodes/245-new-gem-with-bundler
|
35
|
+
|
@@ -0,0 +1,167 @@
|
|
1
|
+
list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies|
|
2
|
+
bridgedifs|hostonlyifs|dhcpservers|hostinfo|
|
3
|
+
hostcpuids|hddbackends|hdds|dvds|floppies|
|
4
|
+
usbhost|usbfilters|systemproperties|extpacks|
|
5
|
+
groups
|
6
|
+
|
7
|
+
registervm <filename>
|
8
|
+
|
9
|
+
createvm --name <name>
|
10
|
+
[--groups <group>, ...]
|
11
|
+
[--ostype <ostype>]
|
12
|
+
[--register]
|
13
|
+
[--basefolder <path>]
|
14
|
+
[--uuid <uuid>]
|
15
|
+
|
16
|
+
import <ovf/ova>
|
17
|
+
[--dry-run|-n]
|
18
|
+
[--options keepallmacs|keepnatmacs]
|
19
|
+
[more options]
|
20
|
+
(run with -n to have options displayed
|
21
|
+
for a particular OVF)
|
22
|
+
|
23
|
+
export <machines> --output|-o <name>.<ovf/ova>
|
24
|
+
[--legacy09|--ovf09|--ovf10|--ovf20]
|
25
|
+
[--manifest]
|
26
|
+
[--vsys <number of virtual system>]
|
27
|
+
[--product <product name>]
|
28
|
+
[--producturl <product url>]
|
29
|
+
[--vendor <vendor name>]
|
30
|
+
[--vendorurl <vendor url>]
|
31
|
+
[--version <version info>]
|
32
|
+
[--eula <license text>]
|
33
|
+
[--eulafile <filename>]
|
34
|
+
|
35
|
+
closemedium disk|dvd|floppy <uuid>|<filename>
|
36
|
+
[--delete]
|
37
|
+
|
38
|
+
createhd --filename <filename>
|
39
|
+
[--size <megabytes>|--sizebyte <bytes>]
|
40
|
+
[--diffparent <uuid>|<filename>
|
41
|
+
[--format VDI|VMDK|VHD] (default: VDI)
|
42
|
+
[--variant Standard,Fixed,Split2G,Stream,ESX]
|
43
|
+
clonehd <uuid>|<filename> <uuid>|<outputfile>
|
44
|
+
[--format VDI|VMDK|VHD|RAW|<other>]
|
45
|
+
[--variant Standard,Fixed,Split2G,Stream,ESX]
|
46
|
+
[--existing]
|
47
|
+
|
48
|
+
convertfromraw <filename> <outputfile>
|
49
|
+
[--format VDI|VMDK|VHD]
|
50
|
+
[--variant Standard,Fixed,Split2G,Stream,ESX]
|
51
|
+
[--uuid <uuid>]
|
52
|
+
convertfromraw stdin <outputfile> <bytes>
|
53
|
+
[--format VDI|VMDK|VHD]
|
54
|
+
[--variant Standard,Fixed,Split2G,Stream,ESX]
|
55
|
+
[--uuid <uuid>]
|
56
|
+
|
57
|
+
getextradata global|<uuid>|<name>
|
58
|
+
<key>|enumerate
|
59
|
+
|
60
|
+
setextradata global|<uuid>|<name>
|
61
|
+
<key>
|
62
|
+
[<value>] (no value deletes key)
|
63
|
+
|
64
|
+
setproperty machinefolder default|<folder> |
|
65
|
+
vrdeauthlibrary default|<library> |
|
66
|
+
websrvauthlibrary default|null|<library> |
|
67
|
+
vrdeextpack null|<library> |
|
68
|
+
autostartdbpath null|<folder> |
|
69
|
+
loghistorycount <value>
|
70
|
+
|
71
|
+
usbfilter add <index,0-N>
|
72
|
+
--target <uuid>|<name>|global
|
73
|
+
--name <string>
|
74
|
+
--action ignore|hold (global filters only)
|
75
|
+
[--active yes|no] (yes)
|
76
|
+
[--vendorid <XXXX>] (null)
|
77
|
+
[--productid <XXXX>] (null)
|
78
|
+
[--revision <IIFF>] (null)
|
79
|
+
[--manufacturer <string>] (null)
|
80
|
+
[--product <string>] (null)
|
81
|
+
[--remote yes|no] (null, VM filters only)
|
82
|
+
[--serialnumber <string>] (null)
|
83
|
+
[--maskedinterfaces <XXXXXXXX>]
|
84
|
+
|
85
|
+
usbfilter modify <index,0-N>
|
86
|
+
--target <uuid>|<name>|global
|
87
|
+
[--name <string>]
|
88
|
+
[--action ignore|hold] (global filters only)
|
89
|
+
[--active yes|no]
|
90
|
+
[--vendorid <XXXX>|""]
|
91
|
+
[--productid <XXXX>|""]
|
92
|
+
[--revision <IIFF>|""]
|
93
|
+
[--manufacturer <string>|""]
|
94
|
+
[--product <string>|""]
|
95
|
+
[--remote yes|no] (null, VM filters only)
|
96
|
+
[--serialnumber <string>|""]
|
97
|
+
[--maskedinterfaces <XXXXXXXX>]
|
98
|
+
|
99
|
+
usbfilter remove <index,0-N>
|
100
|
+
--target <uuid>|<name>|global
|
101
|
+
|
102
|
+
sharedfolder add <vmname>|<uuid>
|
103
|
+
--name <name> --hostpath <hostpath>
|
104
|
+
[--transient] [--readonly] [--automount]
|
105
|
+
|
106
|
+
sharedfolder remove <vmname>|<uuid>
|
107
|
+
--name <name> [--transient]
|
108
|
+
|
109
|
+
guestproperty get <vmname>|<uuid>
|
110
|
+
<property> [--verbose]
|
111
|
+
|
112
|
+
guestproperty set <vmname>|<uuid>
|
113
|
+
<property> [<value> [--flags <flags>]]
|
114
|
+
|
115
|
+
guestproperty enumerate <vmname>|<uuid>
|
116
|
+
[--patterns <patterns>]
|
117
|
+
|
118
|
+
guestproperty wait <vmname>|<uuid> <patterns>
|
119
|
+
[--timeout <msec>] [--fail-on-timeout]
|
120
|
+
|
121
|
+
metrics list [*|host|<vmname> [<metric_list>]]
|
122
|
+
(comma-separated)
|
123
|
+
|
124
|
+
metrics setup
|
125
|
+
[--period <seconds>] (default: 1)
|
126
|
+
[--samples <count>] (default: 1)
|
127
|
+
[--list]
|
128
|
+
[*|host|<vmname> [<metric_list>]]
|
129
|
+
|
130
|
+
metrics query [*|host|<vmname> [<metric_list>]]
|
131
|
+
|
132
|
+
metrics enable
|
133
|
+
[--list]
|
134
|
+
[*|host|<vmname> [<metric_list>]]
|
135
|
+
|
136
|
+
metrics disable
|
137
|
+
[--list]
|
138
|
+
[*|host|<vmname> [<metric_list>]]
|
139
|
+
|
140
|
+
metrics collect
|
141
|
+
[--period <seconds>] (default: 1)
|
142
|
+
[--samples <count>] (default: 1)
|
143
|
+
[--list]
|
144
|
+
[--detach]
|
145
|
+
[*|host|<vmname> [<metric_list>]]
|
146
|
+
|
147
|
+
hostonlyif ipconfig <name>
|
148
|
+
[--dhcp |
|
149
|
+
--ip<ipv4> [--netmask<ipv4> (def: 255.255.255.0)] |
|
150
|
+
--ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]]
|
151
|
+
create |
|
152
|
+
remove <name>
|
153
|
+
|
154
|
+
dhcpserver add|modify --netname <network_name> |
|
155
|
+
--ifname <hostonly_if_name>
|
156
|
+
[--ip <ip_address>
|
157
|
+
--netmask <network_mask>
|
158
|
+
--lowerip <lower_ip>
|
159
|
+
--upperip <upper_ip>]
|
160
|
+
[--enable | --disable]
|
161
|
+
|
162
|
+
dhcpserver remove --netname <network_name> |
|
163
|
+
--ifname <hostonly_if_name>
|
164
|
+
|
165
|
+
extpack install [--replace] <tarball> |
|
166
|
+
uninstall [--force] <name> |
|
167
|
+
cleanup
|
data/lib/vgrnt.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'vgrnt/base'
|
data/lib/vgrnt/base.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Vgrnt
|
4
|
+
class Logger
|
5
|
+
|
6
|
+
def notice(str)
|
7
|
+
$stderr.puts str
|
8
|
+
end
|
9
|
+
|
10
|
+
def debug(str)
|
11
|
+
$stderr.puts str if ENV['VAGRANT_LOG'] == 'debug'
|
12
|
+
end
|
13
|
+
|
14
|
+
def error(str)
|
15
|
+
$stderr.puts "\e[31m" + str + "\e[0m" # terminal codes for red
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Undoes the automatic removal of -- in Thor::Options.peek. Otherwise "vgrnt ssh precise -- ls /"
|
20
|
+
# is parsed as "precise ls /". TODO: is there a less hacky way to handle this?
|
21
|
+
class ::Thor::Options
|
22
|
+
def peek
|
23
|
+
return super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Util
|
28
|
+
def self.getRunningMachines
|
29
|
+
machines = {}
|
30
|
+
|
31
|
+
ids = Dir.glob(".vagrant/machines/*/*/id")
|
32
|
+
ids.each do |id_file|
|
33
|
+
machine_name = id_file[ /^.vagrant\/machines\/(\w+)\/\w+\/id$/ ,1]
|
34
|
+
machine_id = IO.read(id_file)
|
35
|
+
machine_status = `VBoxManage showvminfo #{machine_id} --machinereadable`
|
36
|
+
|
37
|
+
# Forwarding(0)="ssh,tcp,127.0.0.1,2222,,22"
|
38
|
+
ssh_info = machine_status.scan( /^Forwarding\(\d+\)="ssh,tcp,([0-9.]+),([0-9]+),/ ).first
|
39
|
+
|
40
|
+
machines[machine_name] = {
|
41
|
+
:id => machine_id,
|
42
|
+
:ssh_ip => ssh_info[0],
|
43
|
+
:ssh_port => ssh_info[1],
|
44
|
+
:state => machine_status.scan( /^VMState="(.*)"$/ ).first.first # VMState="running"
|
45
|
+
}
|
46
|
+
end
|
47
|
+
# puts machines.inspect
|
48
|
+
return machines
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
class App < Thor
|
55
|
+
|
56
|
+
def initialize(*args)
|
57
|
+
super(*args)
|
58
|
+
@logger = Logger.new
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "ssh [vm-name] [-- extra ssh args]", "Runs vagrant ssh without bootstrapping vagrant."
|
62
|
+
def ssh(target_vm = 'default', *args)
|
63
|
+
|
64
|
+
# removes --, since it's just a separator
|
65
|
+
target_vm = 'default' if (target_vm == '--')
|
66
|
+
args.shift if args.first == '--'
|
67
|
+
|
68
|
+
# @logger.debug [target_vm, args].inspect ; exit 0
|
69
|
+
|
70
|
+
if File.exists?(".vgrnt-sshconfig")
|
71
|
+
@logger.debug "Using .vgrnt-sshconf"
|
72
|
+
ssh_command = "ssh -F .vgrnt-sshconfig #{target_vm} #{args.join(' ')}"
|
73
|
+
else
|
74
|
+
@logger.debug ".vgrnt-sshconfig file not found; using VBoxManage to get connection info."
|
75
|
+
machine = Util::getRunningMachines()[target_vm]
|
76
|
+
|
77
|
+
if machine && machine[:state] == 'running'
|
78
|
+
# found by running "VAGRANT_LOG=debug vagrant ssh"
|
79
|
+
default_ssh_args = [
|
80
|
+
"vagrant@#{machine[:ssh_ip]}",
|
81
|
+
"-p", machine[:ssh_port],
|
82
|
+
"-o", "DSAAuthentication=yes", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no",
|
83
|
+
"-o", "UserKnownHostsFile=/dev/null", "-o", "IdentitiesOnly=yes",
|
84
|
+
"-i", "~/.vagrant.d/insecure_private_key"
|
85
|
+
]
|
86
|
+
|
87
|
+
ssh_command = "ssh #{default_ssh_args.join(" ")} #{args.join(' ')}"
|
88
|
+
else
|
89
|
+
@logger.error "Specified target vm (#{target_vm}) not running."
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
exec ssh_command
|
95
|
+
end
|
96
|
+
|
97
|
+
desc "ssh-config [vm-name]", "Store output of 'vagrant ssh-config' to .vgrnt-sshconfig"
|
98
|
+
def ssh_config(target="default")
|
99
|
+
output = `vagrant ssh-config #{target}`
|
100
|
+
if $? && !output.empty?
|
101
|
+
IO.write('.vgrnt-sshconfig', output)
|
102
|
+
@logger.notice "Created ./.vgrnt-sshconfig with the following:", output
|
103
|
+
else
|
104
|
+
@logger.error "Call to 'vagrant ssh-config' failed."
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# desc "provision", "Run vagrant provision like last time"
|
110
|
+
# def provision
|
111
|
+
# raise "Not implemented yet. Likely requires creating vagrant-vgrnt."
|
112
|
+
# end
|
113
|
+
|
114
|
+
desc "vboxmanage [vm-name] -- <vboxmanage-command> [vboxmanage-args]", "Wrapper on VBoxManage that inserts VM id for you."
|
115
|
+
def vboxmanage(target_vm = 'default', *args)
|
116
|
+
|
117
|
+
# removes --, since it's just a separator
|
118
|
+
target_vm = 'default' if (target_vm == '--')
|
119
|
+
args.shift if args.first == '--'
|
120
|
+
|
121
|
+
# derived as follows: `VBoxManage | sed '1,/Commands/d' | grep '^ [a-z]' | awk '{ print $1; }' | sort -u`
|
122
|
+
vboxmanage_commands_all = %w{
|
123
|
+
adoptstate bandwidthctl clonehd clonevm closemedium controlvm
|
124
|
+
convertfromraw createhd createvm debugvm dhcpserver discardstate
|
125
|
+
export extpack getextradata guestcontrol guestproperty hostonlyif
|
126
|
+
import list metrics modifyhd modifyvm registervm setextradata
|
127
|
+
setproperty sharedfolder showhdinfo showvminfo snapshot startvm
|
128
|
+
storageattach storagectl unregistervm usbfilter}
|
129
|
+
|
130
|
+
# not of form `VBoxManage showvminfo uuid|name ...`
|
131
|
+
vboxmanage_commands_special = %w{
|
132
|
+
list registervm createvm import export closemedium createhd clonehd
|
133
|
+
convertfromraw getextradata setextradata setproperty usbfilter
|
134
|
+
sharedfolder guestproperty metrics hostonlyif dhcpserver extpack}
|
135
|
+
|
136
|
+
# of form `VBoxManage showvminfo uuid|name ...`
|
137
|
+
vboxmanage_commands_standard = vboxmanage_commands_all - vboxmanage_commands_special
|
138
|
+
machine = Util::getRunningMachines()[target_vm]
|
139
|
+
if !machine
|
140
|
+
@logger.error "The specified target vm (#{target_vm}) has not been started."
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
|
144
|
+
vboxmanage_subcommand = args.shift
|
145
|
+
|
146
|
+
if vboxmanage_commands_standard.include?(vboxmanage_subcommand)
|
147
|
+
@logger.debug("Performing UUID insertion for standard vboxmanage command: #{vboxmanage_subcommand}")
|
148
|
+
command = (["VBoxManage", vboxmanage_subcommand, machine[:id]] + args).join(" ")
|
149
|
+
else
|
150
|
+
# TODO: handle substitution for commands like `usbfilter add 0 --target <uuid|name>`
|
151
|
+
|
152
|
+
# @logger.error "Support for non-standard vboxmanage commands (such as #{vboxmanage_subcommand}) is not implemented yet."
|
153
|
+
# exit 1
|
154
|
+
|
155
|
+
@logger.debug "Non-standard vboxmanage command detected (#{vboxmanage_subcommand}). Substituting 'VM_ID' for VM id."
|
156
|
+
|
157
|
+
# [VM_ID] is an optional literal token which will be replaced by the UUID of the VM referenced by Vagrant
|
158
|
+
args.map! { |a| a == 'VM_UUID' ? machine[:id] : a }
|
159
|
+
command = (["VBoxManage", vboxmanage_subcommand] + args).join(" ")
|
160
|
+
end
|
161
|
+
|
162
|
+
@logger.debug "Executing: #{command}"
|
163
|
+
#TODO: windows support (path to VBoxManage.exe")
|
164
|
+
exec command
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# if __FILE__ == $0
|
170
|
+
# raise "vgrnt: must be run from vagrant project root" unless File.exists? 'Vagrantfile'
|
171
|
+
# Vgrnt::App.start
|
172
|
+
# end
|
data/vgrnt.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'vgrnt/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "vgrnt"
|
6
|
+
spec.version = Vgrnt::VERSION
|
7
|
+
spec.authors = "Alex Dergachev"
|
8
|
+
spec.email = "alex@evolvingweb.ca"
|
9
|
+
spec.summary = 'Speeds up a few common vagrant operations through dirty hacks.'
|
10
|
+
spec.homepage = 'https://github.com/dergachev/vgrnt'
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_path = 'lib'
|
17
|
+
|
18
|
+
spec.add_runtime_dependency "thor"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vgrnt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Dergachev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: bundler
|
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: rake
|
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:
|
56
|
+
email: alex@evolvingweb.ca
|
57
|
+
executables:
|
58
|
+
- vgrnt
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- Vagrantfile
|
68
|
+
- bin/vgrnt
|
69
|
+
- docs/DEVNOTES.md
|
70
|
+
- docs/vboxmanage-irregular-commands.txt
|
71
|
+
- lib/vgrnt.rb
|
72
|
+
- lib/vgrnt/base.rb
|
73
|
+
- lib/vgrnt/version.rb
|
74
|
+
- vgrnt.gemspec
|
75
|
+
homepage: https://github.com/dergachev/vgrnt
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Speeds up a few common vagrant operations through dirty hacks.
|
99
|
+
test_files: []
|