vagrant-blocker 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa005c989ef1d8020a8b1f09325d524ee0194e3b
4
+ data.tar.gz: dcd9b98f1b80bf47a62bfb6fb5643cca44253cd7
5
+ SHA512:
6
+ metadata.gz: 3a3126736539656042f8bd31489abece1fce6560c6c6f6728801e9734d17d4fec6fba7f77bbe45c1cefba7043200649d2f97e25ed6a6e1493a396020d0c4cde0
7
+ data.tar.gz: 823c98d3ccbf62d995e0cd67f7f28b1b5adacfc02a15a5933bcc105001eb425ce751a287feb185921c62046807cf95db9c946a9c17edd9d8731725409f52036b
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Jan Vansteenkiste
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,39 @@
1
+ # Vagrant::Blocker
2
+
3
+ Block certain VMs from running together in a multi-VM vagrant setup.
4
+
5
+ ## Installation
6
+
7
+ vagrant plugin install vagrant-blocker
8
+
9
+ ## Usage
10
+
11
+ @TODO
12
+
13
+ ## Testing
14
+
15
+ 1. Clone it
16
+ 2. Ensure you have the correct bundler version (by using RVM).
17
+
18
+ ```
19
+ echo 'vagrant-blocker' > .ruby-gemset
20
+ echo '2.3.1' > .ruby-version
21
+ rvm --create use `cat .ruby-version`@`cat .ruby-gemset`
22
+ gem update --system
23
+ gem install bundler --version 1.12.5
24
+ ```
25
+
26
+ 2. Run `bundle install`
27
+ 3. @TODO
28
+
29
+ ## Example
30
+
31
+ @TODO
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/vStone/vagrant-blocker )
36
+ 2. Create a new feature branch
37
+ 3. Commit
38
+ 4. Push to your remote
39
+ 5. Create a new Pull Request
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module VagrantPlugins
3
+ module Blocker
4
+ module Action
5
+ # Vagrant action that checks for blocking machines
6
+ class CheckBlock
7
+ def initialize(app, env)
8
+ @app = app
9
+ @machine = env[:machine]
10
+ @global_env = @machine.env
11
+ end
12
+
13
+ def call(env)
14
+ # Only do stuff if we want to bring a machine up.
15
+ return @app.call(env) if !env[:machine_action] == :up
16
+
17
+ # Aquire active machines and check their blockers.
18
+ @machine.env.active_machines.each do |name, provider|
19
+ test_block_by_running(name)
20
+ test_blocks_running(name, provider)
21
+ end
22
+ @app.call(env)
23
+ end
24
+
25
+ private
26
+
27
+ def test_block_by_running(name)
28
+ my_blockers = @machine.config.blocker.blocks
29
+ raise Errors::BoxBlockedByRunningVM, name: name if my_blockers && my_blockers.include?(name)
30
+ end
31
+
32
+ def test_blocks_running(name, provider)
33
+ machine = @machine.env.machine(name, provider)
34
+ machine_blocks = machine.config.blocker.blocks
35
+ raise Errors::BoxBlocksRunningVM, name: machine.name.to_s if machine_blocks.include?(@machine.name)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module VagrantPlugins
3
+ module Blocker
4
+ # Configuration
5
+ class Config < Vagrant.plugin('2', :config)
6
+ attr_accessor :blocks
7
+ attr_accessor :strict_config
8
+
9
+ def initialize
10
+ @blocks = UNSET_VALUE
11
+ @strict_config = UNSET_VALUE
12
+ end
13
+
14
+ def finalize!
15
+ @strict_config = true if @strict_config == UNSET_VALUE
16
+ @blocks = [] if @blocks == UNSET_VALUE
17
+ @blocks = [@blocks].flatten.uniq.map(&:to_sym)
18
+ end
19
+
20
+ def validate(machine)
21
+ errors = []
22
+ @blocks.each do |blocker|
23
+ next if machine.env.machine_names.include?(blocker)
24
+ errors << I18n.t('vagrant_blocker.warnings.blocker_not_found', blocker: blocker.to_s, name: machine.name.to_s)
25
+ end
26
+ report(errors, machine.env.ui)
27
+ end
28
+
29
+ private
30
+
31
+ def report(errors, ui)
32
+ return { 'blocker' => errors } if @strict_config
33
+ errors.each { |m| ui.warn(m) }
34
+ {}
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module VagrantPlugins
3
+ module Blocker
4
+ module Errors
5
+ # The current box blocks a vm that is already running
6
+ class BoxBlocksRunningVM < Vagrant::Errors::VagrantError
7
+ error_namespace('vagrant_blocker.errors')
8
+ error_key(:box_blocks_running_vm)
9
+ end
10
+ # The box is blocked by a vm that is already running
11
+ class BoxBlockedByRunningVM < Vagrant::Errors::VagrantError
12
+ error_namespace('vagrant_blocker.errors')
13
+ error_key(:box_blocked_by_running_vm)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module VagrantPlugins
3
+ module Blocker
4
+ # Vagrant plugin that allows machines to block eachother from running simultaneously
5
+ class Plugin < Vagrant.plugin('2')
6
+ name 'Vagrant Blocker'
7
+ description <<-EOF
8
+ Allow certain VMs to block eachother in a multi-vm setup.
9
+ EOF
10
+
11
+ config 'blocker' do
12
+ require_relative 'config'
13
+ init!
14
+ Config
15
+ end
16
+
17
+ action_hook(:do_before_boot, :machine_action_up) do |hook|
18
+ require_relative 'action/check_block'
19
+ init!
20
+ hook.prepend(VagrantPlugins::Blocker::Action::CheckBlock)
21
+ end
22
+
23
+ def self.init!
24
+ return if defined?(@_init)
25
+ I18n.load_path << File.expand_path(File.dirname(__FILE__) + '/../../locales/en.yml')
26
+ I18n.reload!
27
+ @_init = true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module VagrantPlugins
3
+ module Blocker
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'vagrant_blocker/plugin'
3
+ require 'vagrant_blocker/errors'
4
+
5
+ module VagrantPlugins
6
+ ## Placeholder
7
+ module Blocker
8
+ # nothing here
9
+ end
10
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ en:
3
+ vagrant_blocker:
4
+ errors:
5
+ box_blocked_by_running_vm: |
6
+ Machine '%{name}' has blocked this machine from running.
7
+
8
+ box_blocks_running_vm: |
9
+ This machine is blocking already running machine '%{name}'.
10
+ warnings:
11
+ blocker_not_found:
12
+ Could not find the blocker '%{blocker}' for machine '%{name}'.
data/test/Vagrantfile ADDED
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+ require 'vagrant_blocker'
5
+
6
+ # All Vagrant configuration is done below. The "2" in Vagrant.configure
7
+ # configures the configuration version (we support older styles for
8
+ # backwards compatibility). Please don't change it unless you know what
9
+ # you're doing.
10
+ Vagrant.configure('2') do |config|
11
+ # The most common configuration options are documented and commented below.
12
+ # For a complete reference, please see the online documentation at
13
+ # https://docs.vagrantup.com.
14
+
15
+ # Every Vagrant development environment requires a box. You can search for
16
+ # boxes at https://atlas.hashicorp.com/search.
17
+ config.vm.box = 'ffuenf/debian-8.6.0-amd64'
18
+ config.blocker.strict_config = false
19
+
20
+ config.vm.define 'test' do |vm|
21
+ vm.blocker.blocks = 'nonexistant'
22
+ vm.blocker.strict_config = true
23
+ end
24
+
25
+ config.vm.define 'foo' do |vm|
26
+ vm.blocker.blocks = %w(test moehaha)
27
+ end
28
+
29
+ config.vm.define 'bar' do |vm|
30
+ vm.blocker.blocks = %w(test foo)
31
+ end
32
+
33
+ # Disable automatic box update checking. If you disable this, then
34
+ # boxes will only be checked for updates when the user runs
35
+ # `vagrant box outdated`. This is not recommended.
36
+ # config.vm.box_check_update = false
37
+
38
+ # Create a forwarded port mapping which allows access to a specific port
39
+ # within the machine from a port on the host machine. In the example below,
40
+ # accessing "localhost:8080" will access port 80 on the guest machine.
41
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
42
+
43
+ # Create a private network, which allows host-only access to the machine
44
+ # using a specific IP.
45
+ # config.vm.network "private_network", ip: "192.168.33.10"
46
+
47
+ # Create a public network, which generally matched to bridged network.
48
+ # Bridged networks make the machine appear as another physical device on
49
+ # your network.
50
+ # config.vm.network "public_network"
51
+
52
+ # Share an additional folder to the guest VM. The first argument is
53
+ # the path on the host to the actual folder. The second argument is
54
+ # the path on the guest to mount the folder. And the optional third
55
+ # argument is a set of non-required options.
56
+ # config.vm.synced_folder "../data", "/vagrant_data"
57
+
58
+ # Provider-specific configuration so you can fine-tune various
59
+ # backing providers for Vagrant. These expose provider-specific options.
60
+ # Example for VirtualBox:
61
+ #
62
+ # config.vm.provider "virtualbox" do |vb|
63
+ # # Display the VirtualBox GUI when booting the machine
64
+ # vb.gui = true
65
+ #
66
+ # # Customize the amount of memory on the VM:
67
+ # vb.memory = "1024"
68
+ # end
69
+ #
70
+ # View the documentation for the provider you are using for more
71
+ # information on available options.
72
+
73
+ # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
74
+ # such as FTP and Heroku are also available. See the documentation at
75
+ # https://docs.vagrantup.com/v2/push/atlas.html for more information.
76
+ # config.push.define "atlas" do |push|
77
+ # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
78
+ # end
79
+
80
+ # Enable provisioning with a shell script. Additional provisioners such as
81
+ # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
82
+ # documentation for more information about their specific syntax and use.
83
+ # config.vm.provision "shell", inline: <<-SHELL
84
+ # apt-get update
85
+ # apt-get install -y apache2
86
+ # SHELL
87
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'vagrant_blocker/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'vagrant-blocker'
9
+ spec.version = VagrantPlugins::Blocker::VERSION
10
+ spec.authors = ['Jan Vansteenkiste']
11
+ spec.email = ['jan@vstone.eu']
12
+ spec.summary = 'Allow certain virtual machines to block eachother'
13
+ spec.description = 'Prevents certain machines in a multi-vm setup from running together'
14
+ spec.homepage = 'https://github.com/vStone/vagrant-blocker'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0") - ['.gitignore', '.rubocop.yml', 'Rakefile', 'Gemfile']
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-blocker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jan Vansteenkiste
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Prevents certain machines in a multi-vm setup from running together
14
+ email:
15
+ - jan@vstone.eu
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - lib/vagrant_blocker.rb
23
+ - lib/vagrant_blocker/action/check_block.rb
24
+ - lib/vagrant_blocker/config.rb
25
+ - lib/vagrant_blocker/errors.rb
26
+ - lib/vagrant_blocker/plugin.rb
27
+ - lib/vagrant_blocker/version.rb
28
+ - locales/en.yml
29
+ - test/Vagrantfile
30
+ - vagrant-blocker.gemspec
31
+ homepage: https://github.com/vStone/vagrant-blocker
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.6.7
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Allow certain virtual machines to block eachother
55
+ test_files:
56
+ - test/Vagrantfile