vagrant-tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +1 -0
- data/bin/vgctl +85 -0
- data/bin/vgls +72 -0
- data/lib/vagrant/tools/cache.rb +43 -0
- data/lib/vagrant/tools/config.rb +38 -0
- data/lib/vagrant/tools/helper.rb +25 -0
- data/lib/vagrant/tools/orm/config.rb +48 -0
- data/lib/vagrant/tools/orm/machine.rb +33 -0
- data/lib/vagrant/tools/orm/provider.rb +49 -0
- data/lib/vagrant/tools/root.rb +94 -0
- data/lib/vagrant/tools/version.rb +5 -0
- data/lib/vagrant/tools.rb +30 -0
- data/vagrant-tools.gemspec +25 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d2898850a57d6033da0766d357602395ba69b1d
|
4
|
+
data.tar.gz: 65271bbbca73801f2223bfebdd95965181be4ad6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da9a691708420a95151da7c89cc5c588c3aadac1f596215766cf19217df319a12cac5302049efee3b2448af0036df4f47f46c901b244cac99845efcdd9a78f57
|
7
|
+
data.tar.gz: c1325e21edf6785ca70e9ebe54c14018afb805b910f9eff437e653f9cd5a44acb5be7ab38a1dba4c0de2953deaec21743b89e63e0d4563e3d99be1eb732cb163
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Dennis Blommesteijn
|
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 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,
|
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Vagrant::Tools
|
2
|
+
|
3
|
+
Vagrant configuration management tool (via cli).
|
4
|
+
|
5
|
+
By using cli commands: `vgls` you can list all .vagrant configs on your system.
|
6
|
+
Use `vgctl -t config -c (vagrant command)` to run vagrant commands from any path (working dir) on your system.
|
7
|
+
|
8
|
+
|
9
|
+
## Roadmap
|
10
|
+
|
11
|
+
* Version (0.0.1)
|
12
|
+
|
13
|
+
* Initial project
|
14
|
+
* List all vagrant configurations
|
15
|
+
* Add basic controls for up/ halt/ destroy etc.
|
16
|
+
|
17
|
+
* Version (0.1.0) Current
|
18
|
+
|
19
|
+
* Enable `vagrant ssh` interactive shell
|
20
|
+
|
21
|
+
* Version (0.1.1)
|
22
|
+
|
23
|
+
* Filter only active/ inactive
|
24
|
+
* Add option to switch to .config path `vgctl -t target-box -c cd`
|
25
|
+
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
**Clone the git repository to your local machine.**
|
30
|
+
|
31
|
+
```bash
|
32
|
+
git clone https://github.com/dblommesteijn/vagrant-tools
|
33
|
+
```
|
34
|
+
|
35
|
+
**Install binaries to your system**
|
36
|
+
|
37
|
+
```bash
|
38
|
+
cd vagrant-tools
|
39
|
+
rake install
|
40
|
+
# vgls and vgctl will be available system wide
|
41
|
+
```
|
42
|
+
|
43
|
+
**Run commands**
|
44
|
+
|
45
|
+
```bash
|
46
|
+
# list all vagrant configs
|
47
|
+
vgls
|
48
|
+
# control vagrant
|
49
|
+
vgctl
|
50
|
+
```
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
Verbose, this will output operations to STDOUT
|
55
|
+
|
56
|
+
```bash
|
57
|
+
vgls -v
|
58
|
+
vgctl -v
|
59
|
+
```
|
60
|
+
|
61
|
+
Change target configuration (find operation), base from where .vagrant configs are discovered:
|
62
|
+
|
63
|
+
`find "/home/user/path/to/your/repos" -type d -name ".vagrant"`
|
64
|
+
|
65
|
+
*NOTE: this will force cache refresh*
|
66
|
+
|
67
|
+
```bash
|
68
|
+
vgls -p `$HOME`/path/to/your/repos
|
69
|
+
vgctl -p `$HOME`/path/to/your/repos
|
70
|
+
```
|
71
|
+
|
72
|
+
Target or list vagrant config relative to a given config
|
73
|
+
|
74
|
+
*NOTE: duplicate config names will get a _n offset*
|
75
|
+
|
76
|
+
```bash
|
77
|
+
vgls -t my-test-box
|
78
|
+
vgctl -t my-test-box
|
79
|
+
```
|
80
|
+
|
81
|
+
Refresh cache, by default cache is stored at `$HOME/.vagrant-tools/settings.json`
|
82
|
+
|
83
|
+
```bash
|
84
|
+
# vgls and vgctl are equivalent
|
85
|
+
vgls -x
|
86
|
+
vgctl -x
|
87
|
+
```
|
88
|
+
|
89
|
+
Run a vagrant command (-c prepends `vagrant ` to all commands)
|
90
|
+
|
91
|
+
```bash
|
92
|
+
vgctl -t my-test-box -c list-commands
|
93
|
+
# runs `vagrant list-commands` in the path of `my-test-box`
|
94
|
+
# ... etc
|
95
|
+
```
|
96
|
+
|
97
|
+
Print help file
|
98
|
+
|
99
|
+
```bash
|
100
|
+
vgls -h
|
101
|
+
vgctl -h
|
102
|
+
```
|
103
|
+
|
104
|
+
### Workflow
|
105
|
+
|
106
|
+
Listing all vagrant configs, and starting VM
|
107
|
+
|
108
|
+
```bash
|
109
|
+
# list all configs
|
110
|
+
vgls
|
111
|
+
# execute `vagrant up` on path of `my-test-box`
|
112
|
+
vgctl -t my-test-box -c up
|
113
|
+
vgctl -t my-test-box -c ssh
|
114
|
+
```
|
115
|
+
|
116
|
+
Destroy a running VM
|
117
|
+
|
118
|
+
```bash
|
119
|
+
# list all configs
|
120
|
+
vgls
|
121
|
+
# execute `vagrant destroy` on path of `my-test-box`
|
122
|
+
vgctl -t my-test-box -c destory
|
123
|
+
```
|
124
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/vgctl
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/vagrant/tools")
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
|
7
|
+
def main(argv)
|
8
|
+
# set configuration
|
9
|
+
vgtools_cfg = Vagrant::Tools.config do |c|
|
10
|
+
# defaults
|
11
|
+
c.prefix = ENV["HOME"]
|
12
|
+
c.verbose = false
|
13
|
+
# getopts
|
14
|
+
opt_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Vagrant control, Usage: vgctl [options]"
|
16
|
+
|
17
|
+
opts.on("-p", "--prefix DIR", String, "Define prefix (default $HOME)") do |v|
|
18
|
+
c.prefix = v
|
19
|
+
c.refresh_cache = true
|
20
|
+
end
|
21
|
+
opts.on("-v", "--verbose", "Verbose output") do |v|
|
22
|
+
c.verbose = true
|
23
|
+
end
|
24
|
+
opts.on("-t", "--target TARGET", String, "Target specific Vagrantfile directory") do |v|
|
25
|
+
c.target = v
|
26
|
+
end
|
27
|
+
opts.on("-c", "--cmd COMMAND", String, "Run vagrant command relative to -t TARGET (-c \"up\")") do |v|
|
28
|
+
c.cmd = v
|
29
|
+
end
|
30
|
+
opts.on("-x", "--refresh-cache", "Refresh cached results") do |v|
|
31
|
+
c.refresh_cache = v
|
32
|
+
end
|
33
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
34
|
+
puts opts
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
begin
|
39
|
+
opt_parser.parse!
|
40
|
+
rescue OptionParser::MissingArgument => e
|
41
|
+
puts e.message
|
42
|
+
exit 1
|
43
|
+
rescue OptionParser::InvalidOption => e
|
44
|
+
puts e.message
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
cfg = Vagrant::Tools.get_config
|
49
|
+
verify = vgtools_cfg.verify? do |errors|
|
50
|
+
# if cfg.target.nil? || cfg.target == "
|
51
|
+
errors[:target] = "target does not exist" if cfg.target.nil?
|
52
|
+
errors[:cmd] = "invalid" if cfg.cmd.nil? || cfg.cmd == ""
|
53
|
+
# errors[:]
|
54
|
+
end
|
55
|
+
unless verify
|
56
|
+
puts vgtools_cfg.error_messages
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
# print verbose message
|
61
|
+
if cfg.verbose
|
62
|
+
puts "Running `#{File.basename(__FILE__)}` in verbose mode (disable by removing -v [options])"
|
63
|
+
end
|
64
|
+
|
65
|
+
# find config root by target name (project root name)
|
66
|
+
root = Vagrant::Tools::Root.new
|
67
|
+
config = root.find_by_project_root(cfg.target)
|
68
|
+
if config.nil?
|
69
|
+
puts "target config not found"
|
70
|
+
exit
|
71
|
+
else
|
72
|
+
puts "executing: #{cfg.cmd}" if cfg.verbose
|
73
|
+
end
|
74
|
+
# execute command relative to config
|
75
|
+
config.exec_vagrant_command(cfg.cmd)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
if File.basename(__FILE__) == File.basename($0)
|
80
|
+
begin
|
81
|
+
main(ARGV)
|
82
|
+
rescue Interrupt
|
83
|
+
exit 0
|
84
|
+
end
|
85
|
+
end
|
data/bin/vgls
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/vagrant/tools")
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
|
7
|
+
def main(argv)
|
8
|
+
# set configuration
|
9
|
+
vgtools_cfg = Vagrant::Tools.config do |c|
|
10
|
+
# defaults
|
11
|
+
c.prefix = ENV["HOME"]
|
12
|
+
c.verbose = false
|
13
|
+
# getopts
|
14
|
+
opt_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Vagrant list, Usage: vgls [options]"
|
16
|
+
opts.on("-p", "--prefix DIR", String, "Define prefix (default $HOME)") do |v|
|
17
|
+
c.prefix = v
|
18
|
+
c.refresh_cache = true
|
19
|
+
end
|
20
|
+
opts.on("-v", "--verbose", "Verbose output") do |v|
|
21
|
+
c.verbose = true
|
22
|
+
end
|
23
|
+
opts.on("-t", "--target TARGET", String, "Target specific config (Vagrantfile dir)") do |v|
|
24
|
+
c.target = v
|
25
|
+
end
|
26
|
+
opts.on("-x", "--refresh-cache", "Refresh cached results") do |v|
|
27
|
+
c.refresh_cache = v
|
28
|
+
end
|
29
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
30
|
+
puts opts
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
begin
|
36
|
+
opt_parser.parse!
|
37
|
+
rescue OptionParser::InvalidOption => e
|
38
|
+
puts e.message
|
39
|
+
exit 1
|
40
|
+
rescue OptionParser::MissingArgument => e
|
41
|
+
puts e.message
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
verify = vgtools_cfg.verify? do |errors|
|
47
|
+
# if
|
48
|
+
# errors[:]
|
49
|
+
end
|
50
|
+
unless verify
|
51
|
+
puts vgtools_cfg.error_messages
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
|
55
|
+
cfg = Vagrant::Tools.get_config
|
56
|
+
if cfg.verbose
|
57
|
+
puts "Running `#{File.basename(__FILE__)}` in verbose mode (disable by removing -v [options])"
|
58
|
+
end
|
59
|
+
|
60
|
+
# output lists
|
61
|
+
root = Vagrant::Tools::Root.new
|
62
|
+
puts root.to_outputs
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
if File.basename(__FILE__) == File.basename($0)
|
67
|
+
begin
|
68
|
+
main(ARGV)
|
69
|
+
rescue Interrupt
|
70
|
+
exit 0
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Tools
|
3
|
+
|
4
|
+
class Cache
|
5
|
+
|
6
|
+
# attr_accessor :prefix, :verbose, :output, :options, :target, :cmd
|
7
|
+
PATH = "#{ENV["HOME"]}/.vagrant-tools"
|
8
|
+
|
9
|
+
def initialize(path = PATH)
|
10
|
+
@path = path
|
11
|
+
@cfg = Vagrant::Tools.get_config
|
12
|
+
unless File.exists?(@path)
|
13
|
+
puts "Creating `#{path}`" if @cfg.verbose
|
14
|
+
FileUtils.mkpath(@path)
|
15
|
+
end
|
16
|
+
@filename = "#{@path}/settings.json"
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_config
|
20
|
+
return {} unless File.exists?(@filename)
|
21
|
+
#TODO: read from file
|
22
|
+
begin
|
23
|
+
json = JSON.parse(File.read(@filename), {symbolize_names: true})
|
24
|
+
json[:configs]
|
25
|
+
rescue
|
26
|
+
return {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_config(dirs)
|
31
|
+
puts "Writing to `#{@filename}`" if @cfg.verbose
|
32
|
+
config_paths = { configs: dirs.flat_map{|k,v| v.map(&:config_path)} }
|
33
|
+
flat_json = JSON.pretty_generate(config_paths)
|
34
|
+
puts flat_json if @cfg.verbose
|
35
|
+
File.open(@filename,"w") do |f|
|
36
|
+
f.write(flat_json)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Tools
|
3
|
+
|
4
|
+
class Config
|
5
|
+
|
6
|
+
attr_accessor :prefix, :verbose, :output, :options, :target, :cmd, :refresh_cache
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@errors = {}
|
10
|
+
self.prefix = ENV["HOME"]
|
11
|
+
self.verbose = false
|
12
|
+
self.output = {machine: false, long: false}
|
13
|
+
self.target = nil
|
14
|
+
self.cmd = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify?(&block)
|
18
|
+
# general checks
|
19
|
+
@errors[:prefix] = "file does not exist" unless File.exists?(self.prefix)
|
20
|
+
unless self.cmd.nil?
|
21
|
+
if self.cmd.start_with?("vagrant")
|
22
|
+
@errors[:cmd] = "all commands are prepended with `vagrant`"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# file specific checks
|
26
|
+
block.call(@errors)
|
27
|
+
# @errors[:target] = "unknown target" if self.target.present? &&
|
28
|
+
@errors.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def error_messages
|
32
|
+
@errors.map{|k,v| "Error `#{k}`: #{v}"}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Tools
|
3
|
+
|
4
|
+
class Helper
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# collecting user input, continue if input == y else exit
|
9
|
+
# def collect_input_yn_exit!(action)
|
10
|
+
# STDOUT.write "#{action} are you sure [y/N]? "
|
11
|
+
# STDOUT.flush
|
12
|
+
# a = gets
|
13
|
+
# case a.downcase
|
14
|
+
# when "y\n"
|
15
|
+
# return true
|
16
|
+
# else
|
17
|
+
# exit
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Tools
|
5
|
+
module Orm
|
6
|
+
|
7
|
+
class Config
|
8
|
+
|
9
|
+
attr_accessor :name, :project_root, :offset, :config_path
|
10
|
+
|
11
|
+
def initialize(config_path)
|
12
|
+
@cfg = Vagrant::Tools.get_config
|
13
|
+
self.config_path = config_path
|
14
|
+
self.project_root = File.absolute_path("#{config_path}/../")
|
15
|
+
@machines = Dir["#{self.config_path}/machines/*"].flat_map{|t| Machine.new(t)}
|
16
|
+
self.name = File.basename(File.absolute_path("#{config_path}/../"))
|
17
|
+
self.offset = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def project_root_name
|
21
|
+
File.basename(self.project_root)
|
22
|
+
end
|
23
|
+
|
24
|
+
def project_root_name_with_offset
|
25
|
+
o = (self.offset > 0) ? "_#{self.offset}" : ""
|
26
|
+
"#{self.project_root_name}#{o}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def exec_vagrant_command(cmd)
|
30
|
+
cmd = "(cd #{self.project_root} && vagrant #{cmd})"
|
31
|
+
puts cmd if @cfg.verbose
|
32
|
+
system(cmd)
|
33
|
+
end
|
34
|
+
|
35
|
+
def names
|
36
|
+
@machines.map(&:name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_outputs
|
40
|
+
machines = @machines.map(&:to_outputs).join("")
|
41
|
+
"#{self.project_root_name_with_offset} (#{@project_root})\n#{machines}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Tools
|
3
|
+
module Orm
|
4
|
+
|
5
|
+
class Machine
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
def initialize(machine_path)
|
10
|
+
@machine_path = machine_path
|
11
|
+
self.name = File.basename(machine_path)
|
12
|
+
@provider = Dir["#{@machine_path}/*"].flat_map{|t| Provider.new(t)}
|
13
|
+
end
|
14
|
+
|
15
|
+
def ids
|
16
|
+
@provider.map(&:id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def processes
|
20
|
+
@provider.map(&:process)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_outputs
|
24
|
+
provider = @provider.map(&:to_outputs).join("")
|
25
|
+
return "- #{self.name} (no provider found)\n" if provider.empty?
|
26
|
+
"- #{self.name} (#{provider})\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'sys/proctable'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Tools
|
5
|
+
module Orm
|
6
|
+
|
7
|
+
class Provider
|
8
|
+
|
9
|
+
attr_accessor :id
|
10
|
+
|
11
|
+
def initialize(provider_path)
|
12
|
+
@provider_path = provider_path
|
13
|
+
@id_file = "#{@provider_path}/id"
|
14
|
+
self.id = File.read(@id_file) if self.valid?
|
15
|
+
@process = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
File.exists?(@id_file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def process
|
23
|
+
return @process unless @process.nil?
|
24
|
+
Sys::ProcTable.ps do |p|
|
25
|
+
@process = p if p.cmdline.include?(self.id)
|
26
|
+
end
|
27
|
+
@process
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_outputs
|
31
|
+
ret = []
|
32
|
+
if self.valid?
|
33
|
+
p = self.process
|
34
|
+
if p.nil?
|
35
|
+
ret << "vmid: #{self.id}"
|
36
|
+
else
|
37
|
+
ret << "pid: #{p.pid}"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
ret << "never started"
|
41
|
+
end
|
42
|
+
ret.join
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module Tools
|
6
|
+
|
7
|
+
class Root
|
8
|
+
|
9
|
+
LOOKUP_DIR = ".vagrant"
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@cfg = Vagrant::Tools.get_config
|
13
|
+
@dirs = {}
|
14
|
+
self.find_vagrant_configs
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_by_project_root(project_root_name)
|
18
|
+
self.get_config_without_offset(project_root_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_vagrant_configs
|
22
|
+
unless @dirs.empty?
|
23
|
+
puts "Config already loaded (use -x to force reload)" if @cfg.verbose
|
24
|
+
return @dirs
|
25
|
+
end
|
26
|
+
prefix = @cfg.prefix
|
27
|
+
cache = Cache.new
|
28
|
+
cache_configs = cache.get_config
|
29
|
+
# break if config found (unless refreshing)
|
30
|
+
if !cache_configs.empty? && !@cfg.refresh_cache
|
31
|
+
puts "Reading config from cache" if @cfg.verbose
|
32
|
+
cache_configs.each do |config|
|
33
|
+
# create new config instance
|
34
|
+
self.add_config_dirs(config)
|
35
|
+
end
|
36
|
+
return self
|
37
|
+
end
|
38
|
+
# findin configs via find
|
39
|
+
cmd = "find \"#{prefix}\" -type d -name \"#{LOOKUP_DIR}\""
|
40
|
+
puts "Finding vagrant configs: `#{cmd}`..." if @cfg.verbose
|
41
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr|
|
42
|
+
stdin.close_write
|
43
|
+
stdout.read.split("\n").each do |config|
|
44
|
+
# create new config instance
|
45
|
+
self.add_config_dirs(config)
|
46
|
+
end
|
47
|
+
stderr.close_read
|
48
|
+
end
|
49
|
+
cache.set_config(@dirs)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_outputs
|
54
|
+
ret = []
|
55
|
+
if @cfg.target.nil?
|
56
|
+
# print all
|
57
|
+
ret << @dirs.flat_map{|k,t| t.map(&:to_outputs)}
|
58
|
+
else
|
59
|
+
ret << self.get_config_without_offset(@cfg.target).to_outputs
|
60
|
+
end
|
61
|
+
ret.join
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def add_config_dirs(config)
|
67
|
+
orm_config = Orm::Config.new(config)
|
68
|
+
n = orm_config.project_root_name
|
69
|
+
@dirs[n] ||= []
|
70
|
+
orm_config.offset = @dirs[n].size + 1 if @dirs[n].size > 0
|
71
|
+
@dirs[n] << orm_config
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_config_without_offset(name)
|
76
|
+
tmp = name.split("_")
|
77
|
+
if tmp.size > 1
|
78
|
+
n = tmp.first
|
79
|
+
o = tmp.last.to_i - 1
|
80
|
+
if @dirs.include?(n)
|
81
|
+
return @dirs[n][o]
|
82
|
+
end
|
83
|
+
# elsif @dirs[n].nil?
|
84
|
+
# puts @dirs.inspect
|
85
|
+
else
|
86
|
+
n = name
|
87
|
+
return @dirs[n].first
|
88
|
+
end
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/config")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/cache")
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/root")
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/version")
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/helper")
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/orm/config")
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/orm/machine")
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + "/tools/orm/provider")
|
9
|
+
|
10
|
+
|
11
|
+
module Vagrant
|
12
|
+
module Tools
|
13
|
+
|
14
|
+
@@config = ::Vagrant::Tools::Config.new
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def config(&block)
|
19
|
+
block.call(@@config)
|
20
|
+
@@config
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_config
|
24
|
+
@@config.dup
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant/tools/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-tools"
|
8
|
+
spec.version = Vagrant::Tools::VERSION
|
9
|
+
spec.authors = ["Dennis Blommesteijn"]
|
10
|
+
spec.email = ["dennis@blommesteijn.com"]
|
11
|
+
spec.summary = %q{Tools for Vagrant}
|
12
|
+
spec.description = %q{Tools for Vagrant}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'sys-proctable', "> 0.9"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Blommesteijn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sys-proctable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>'
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>'
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
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: Tools for Vagrant
|
56
|
+
email:
|
57
|
+
- dennis@blommesteijn.com
|
58
|
+
executables:
|
59
|
+
- vgctl
|
60
|
+
- vgls
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/vgctl
|
70
|
+
- bin/vgls
|
71
|
+
- lib/vagrant/tools.rb
|
72
|
+
- lib/vagrant/tools/cache.rb
|
73
|
+
- lib/vagrant/tools/config.rb
|
74
|
+
- lib/vagrant/tools/helper.rb
|
75
|
+
- lib/vagrant/tools/orm/config.rb
|
76
|
+
- lib/vagrant/tools/orm/machine.rb
|
77
|
+
- lib/vagrant/tools/orm/provider.rb
|
78
|
+
- lib/vagrant/tools/root.rb
|
79
|
+
- lib/vagrant/tools/version.rb
|
80
|
+
- vagrant-tools.gemspec
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Tools for Vagrant
|
105
|
+
test_files: []
|