vagrant-global-status 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 604a21bf1c9c118e332c445290442c369b877c47
4
+ data.tar.gz: a921da366043462f06f8b863888e5aa0e8b62969
5
+ SHA512:
6
+ metadata.gz: 818a8857af249396e6a12a16051f1db3858fbe8358abee80b7012cd726419c433ecf562335748883b9a77669854846e00e00af7aa74935b65730240b17f45135
7
+ data.tar.gz: 3ca978c30988061a728b8378090647d820279676d2eb7f4faef4869a25143b39ea80ab0418c29d731109f28cd3496a809b5c27f20f810bf57ca6c38d822b81f9
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-global-status.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'vagrant', github: 'mitchellh/vagrant'
8
+ gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
9
+ gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
10
+ gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
11
+ end
@@ -0,0 +1,60 @@
1
+ GIT
2
+ remote: git://github.com/fgrehm/vagrant-cachier.git
3
+ revision: 5f30e3c9da53b25fa239b28871f0007a6de64221
4
+ specs:
5
+ vagrant-cachier (0.3.0.dev)
6
+
7
+ GIT
8
+ remote: git://github.com/fgrehm/vagrant-lxc.git
9
+ revision: 5ae82681cdedaf2a6f778e005dd65014fc7c2cec
10
+ specs:
11
+ vagrant-lxc (0.5.1.dev)
12
+
13
+ GIT
14
+ remote: git://github.com/fgrehm/vagrant-pristine.git
15
+ revision: 5c400d7850fc5f98d9601b59f4c3bd74818650de
16
+ specs:
17
+ vagrant-pristine (0.2.0)
18
+
19
+ GIT
20
+ remote: git://github.com/mitchellh/vagrant.git
21
+ revision: 16002d03c07f842a23497543129fa99f40f2bbc0
22
+ specs:
23
+ vagrant (1.2.8.dev)
24
+ childprocess (~> 0.3.7)
25
+ erubis (~> 2.7.0)
26
+ i18n (~> 0.6.0)
27
+ log4r (~> 1.1.9)
28
+ net-scp (~> 1.1.0)
29
+ net-ssh (~> 2.6.6)
30
+
31
+ PATH
32
+ remote: .
33
+ specs:
34
+ vagrant-global-status (0.1.0)
35
+
36
+ GEM
37
+ remote: https://rubygems.org/
38
+ specs:
39
+ childprocess (0.3.9)
40
+ ffi (~> 1.0, >= 1.0.11)
41
+ erubis (2.7.0)
42
+ ffi (1.9.0)
43
+ i18n (0.6.4)
44
+ log4r (1.1.10)
45
+ net-scp (1.1.2)
46
+ net-ssh (>= 2.6.5)
47
+ net-ssh (2.6.8)
48
+ rake (10.1.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 1.3)
55
+ rake
56
+ vagrant!
57
+ vagrant-cachier!
58
+ vagrant-global-status!
59
+ vagrant-lxc!
60
+ vagrant-pristine!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fabio Rehm
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.
@@ -0,0 +1,51 @@
1
+ # vagrant-global-status
2
+
3
+ A proof of concept [Vagrant](http://www.vagrantup.com/) plugin that keeps
4
+ track of vagrant machines and provides a command for listing the status of all
5
+ known machines.
6
+
7
+ ## Installation
8
+
9
+ Make sure you have Vagrant 1.1+ and run:
10
+
11
+ ```
12
+ vagrant plugin install vagrant-global-status
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```
18
+ vagrant global-status [--all]
19
+
20
+ -a, --all Displays information about all machines (instead of just the active ones)
21
+ -h, --help Print this help
22
+ ```
23
+
24
+ ## How does it work?
25
+
26
+ Whenever you `vagrant up` a VM, the plugin will register the machine name and
27
+ path to its `Vagrantfile` on a global state file under `~/.vagrant.d`. That
28
+ is enough information for the `global-status` command to do its job and parse
29
+ machine's statuses.
30
+
31
+ After a `vagrant destroy`, the VM will get removed from the global state file
32
+ and will no longer show up by default on `vagrant global-status` unless you pass
33
+ in `-a` to it.
34
+
35
+ Besides that, the plugin is smart enough to detect [multiple combinations](lib/vagrant-global-status/global_environment.rb)
36
+ of Vagrant environments and is able to get the status for a machine that is
37
+ used for development of a Vagrant plugin using Bundler.
38
+
39
+ ## Current limitations / ideas for contributions
40
+
41
+ * Keeps track of active vagrant-lxc and VirtualBox VMs only
42
+ * Blows up if the `Vagrantfile` gets removed from the registered path
43
+ * Detect orphaned machines
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require_relative "vagrant-global-status/plugin"
@@ -0,0 +1,24 @@
1
+ require_relative '../global_registry'
2
+
3
+ module VagrantPlugins
4
+ module GlobalStatus
5
+ module Action
6
+ class DeregisterMachine
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @app.call(env)
13
+ if env[:machine].provider.state.id == :not_created
14
+ GlobalRegistry.deregister(
15
+ home_path: env[:home_path],
16
+ machine_name: env[:machine].name,
17
+ root_path: env[:root_path]
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../global_registry'
2
+
3
+ module VagrantPlugins
4
+ module GlobalStatus
5
+ module Action
6
+ class RegisterMachine
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @app.call(env)
13
+ if env[:machine].provider.state.id == :running
14
+ GlobalRegistry.register(
15
+ home_path: env[:home_path],
16
+ machine_name: env[:machine].name,
17
+ root_path: env[:root_path]
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'global_registry'
2
+
3
+ module VagrantPlugins
4
+ module GlobalStatus
5
+ class Command < Vagrant.plugin("2", :command)
6
+ def execute
7
+ options = {}
8
+
9
+ opts = OptionParser.new do |o|
10
+ o.banner = "Usage: vagrant global-status [--all]"
11
+
12
+ o.on("-a", "--all", "Displays information about all machines (instead of just the active ones)") do |f|
13
+ options[:all] = true
14
+ end
15
+ end
16
+
17
+ @argv = parse_options(opts)
18
+ return if !@argv
19
+
20
+ registry = GlobalRegistry.new(@env.home_path.join('machine-environments.json'))
21
+ registry.environments.each do |env|
22
+ @env.ui.info "\n#{env.path}"
23
+ @env.ui.info "#{env.status(options[:all])}"
24
+ end
25
+
26
+ 0
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,107 @@
1
+ module VagrantPlugins
2
+ module GlobalStatus
3
+ class GlobalEnvironment
4
+ attr_reader :path
5
+
6
+ RUBY_VERSION_MANAGERS = [ /\/\.rbenv\//, /\/\.rvm\// ]
7
+
8
+ def initialize(path, data)
9
+ @path = Pathname(path)
10
+ @machine_names = Array(data['machines']).map{|machine| machine['name']}
11
+ end
12
+
13
+ # REFACTOR: Extract a machine class
14
+ def status(all = false)
15
+ matches = vagrant_status.scan(/(\w[\w-]+)\s+(\w[\w\s]+)\s+\((\w+)\)/)
16
+ matches.map do |vm, status, provider|
17
+ if all || @machine_names.include?(vm)
18
+ " #{vm.ljust(15)} #{status} (#{provider})"
19
+ end
20
+ end.compact.join("\n")
21
+ end
22
+
23
+ def vagrant_status
24
+ return @vagrant_status if @vagrant_status
25
+
26
+ # Plugins development
27
+ if defined?(::Bundler)
28
+ if plugin_sources?
29
+ Bundler.with_clean_env do
30
+ @vagrant_status = run_vagrant_status
31
+ end
32
+ else
33
+ Bundler.with_clean_env do
34
+ with_clean_ruby_env(RUBY_VERSION_MANAGERS) do
35
+ @vagrant_status = run_vagrant_status
36
+ end
37
+ end
38
+ end
39
+
40
+ # Vagrant installer
41
+ else
42
+ if plugin_sources?
43
+ with_clean_vagrant_env do
44
+ @vagrant_status = run_vagrant_status
45
+ end
46
+ else
47
+ @vagrant_status = run_vagrant_status
48
+ end
49
+ end
50
+ end
51
+
52
+ ORIGINAL_ENV = ENV.to_hash
53
+ def with_original_env
54
+ yield
55
+ ensure
56
+ ENV.replace(ORIGINAL_ENV)
57
+ end
58
+
59
+ def with_clean_vagrant_env
60
+ with_clean_ruby_env(/\/vagrant\//) do
61
+ yield
62
+ end
63
+ end
64
+
65
+ def with_clean_ruby_env(regex)
66
+ with_original_env do
67
+ Array(regex).each do |reg|
68
+ ENV['PATH'] = remove_from_path(reg)
69
+ end
70
+ ENV.delete('GEM_HOME')
71
+ ENV.delete('GEM_PATH')
72
+ yield
73
+ end
74
+ end
75
+
76
+ def remove_from_path(regex)
77
+ ENV['PATH'].split(':').
78
+ reject{ |p| p =~ regex }.
79
+ join(':')
80
+ end
81
+
82
+ def run_vagrant_status
83
+ cmd = "cd #{@path} && "
84
+ if plugin_sources?
85
+ cmd << "bundle exec "
86
+ end
87
+ cmd << "vagrant status"
88
+ `#{cmd}`
89
+ end
90
+
91
+ def plugin_sources?
92
+ return @plugin_sources if defined?(@plugin_sources)
93
+
94
+ gemfile_dir = @path
95
+ gemfile = gemfile_dir.join('Gemfile')
96
+
97
+ # If the parent is the same dir, we reached the root dir
98
+ while !gemfile.file? && gemfile_dir.parent != gemfile_dir
99
+ gemfile_dir = gemfile_dir.parent
100
+ gemfile = gemfile_dir.join('Gemfile')
101
+ end
102
+
103
+ @plugin_sources = gemfile.file? ? gemfile.read =~ /gem\s+['"]vagrant['"]/ : false
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,69 @@
1
+ require_relative 'global_environment'
2
+
3
+ module VagrantPlugins
4
+ module GlobalStatus
5
+ class GlobalRegistry
6
+ def self.register(params)
7
+ statefile = params.fetch(:home_path).join('machine-environments.json')
8
+ new(statefile).register(
9
+ params.fetch(:machine_name).to_s,
10
+ params.fetch(:root_path).to_s
11
+ )
12
+ end
13
+
14
+ def self.deregister(params)
15
+ statefile = params.fetch(:home_path).join('machine-environments.json')
16
+ new(statefile).deregister(
17
+ params.fetch(:machine_name).to_s,
18
+ params.fetch(:root_path).to_s
19
+ )
20
+ end
21
+
22
+ def initialize(statefile)
23
+ @statefile = statefile
24
+ @current_state = if @statefile.file?
25
+ JSON.parse(@statefile.read)
26
+ else
27
+ { 'environments' => {} }
28
+ end
29
+ end
30
+
31
+ def environments
32
+ @environments ||= @current_state['environments'].each_with_object({}) do |(env, data), hash|
33
+ hash[env] = GlobalEnvironment.new(env, data)
34
+ end
35
+
36
+ @environments.values
37
+ end
38
+
39
+ def register(machine_name, root_path)
40
+ @current_state['environments'][root_path] ||= { 'machines' => [] }
41
+
42
+ global_environment = @current_state['environments'][root_path]
43
+ machine = { 'name' => machine_name }
44
+ unless global_environment['machines'].include?(machine)
45
+ global_environment['machines'] << {'name' => machine_name}
46
+ end
47
+
48
+ write_statefile
49
+ end
50
+
51
+ def deregister(machine_name, root_path)
52
+ @current_state['environments'][root_path] ||= { 'machines' => [] }
53
+
54
+ global_environment = @current_state['environments'][root_path]
55
+ global_environment['machines'].delete({'name' => machine_name})
56
+
57
+ write_statefile
58
+ end
59
+
60
+ private
61
+
62
+ def write_statefile
63
+ @statefile.open("w+") do |f|
64
+ f.write(JSON.dump(@current_state))
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,44 @@
1
+ require "vagrant"
2
+
3
+ require_relative "version"
4
+
5
+ module VagrantPlugins
6
+ module GlobalStatus
7
+ class Plugin < Vagrant.plugin("2")
8
+ name "Vagrant Global Status"
9
+ description 'Find out the status of all of the Vagrant VMs you manage'
10
+
11
+ # TODO: This should be generic, we don't want to hard code every single
12
+ # possible provider action class that Vagrant might have
13
+ register_machine = lambda do |hook|
14
+ require_relative "action/register_machine"
15
+ hook.before VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::RegisterMachine
16
+
17
+ if defined?(Vagrant::LXC)
18
+ # TODO: Require just the boot action file once its "require dependencies" are sorted out
19
+ require 'vagrant-lxc/action'
20
+ hook.before Vagrant::LXC::Action::Boot, Action::RegisterMachine
21
+ end
22
+ end
23
+ action_hook 'register-machine-on-up', :machine_action_up, &register_machine
24
+ action_hook 'register-machine-on-reload', :machine_action_reload, &register_machine
25
+
26
+ deregister_machine = lambda do |hook|
27
+ require_relative "action/deregister_machine"
28
+ hook.before VagrantPlugins::ProviderVirtualBox::Action::Destroy, Action::DeregisterMachine
29
+
30
+ if defined?(Vagrant::LXC)
31
+ # TODO: Require just the boot action file once its "require dependencies" are sorted out
32
+ require 'vagrant-lxc/action'
33
+ hook.before Vagrant::LXC::Action::Destroy, Action::DeregisterMachine
34
+ end
35
+ end
36
+ action_hook 'deregister-machine-on-destroy', :machine_action_destroy, &deregister_machine
37
+
38
+ command('global-status') do
39
+ require_relative 'command'
40
+ Command
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module GlobalStatus
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-global-status/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-global-status"
8
+ spec.version = VagrantPlugins::GlobalStatus::VERSION
9
+ spec.authors = ["Fabio Rehm"]
10
+ spec.email = ["fgrehm@gmail.com"]
11
+ spec.description = %q{Find out the status of all of the Vagrant VMs you manage}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/fgrehm/vagrant-global-status"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-global-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Rehm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-12 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ description: Find out the status of all of the Vagrant VMs you manage
42
+ email:
43
+ - fgrehm@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/vagrant-global-status.rb
55
+ - lib/vagrant-global-status/action/deregister_machine.rb
56
+ - lib/vagrant-global-status/action/register_machine.rb
57
+ - lib/vagrant-global-status/command.rb
58
+ - lib/vagrant-global-status/global_environment.rb
59
+ - lib/vagrant-global-status/global_registry.rb
60
+ - lib/vagrant-global-status/plugin.rb
61
+ - lib/vagrant-global-status/version.rb
62
+ - vagrant-global-status.gemspec
63
+ homepage: https://github.com/fgrehm/vagrant-global-status
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.0
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Find out the status of all of the Vagrant VMs you manage
87
+ test_files: []