vagrant-environments 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1cfdb945660ce9eae0ce0ce88bfe3f6d565291b
4
- data.tar.gz: 0680f875bb88da4e318457b67b210a82a223cfd2
3
+ metadata.gz: dcbb1c998025549e2e5cfa6f72552b5e22443102
4
+ data.tar.gz: 058f3d1df3d99e9fb55872f22d96b6e43f56a030
5
5
  SHA512:
6
- metadata.gz: 5d04eae8f840bbe4276953b0364101545c5241d185fb65d2bff031f51b9a006786b63d0d0bac6382bfe34ff3b6681a13e2efb720b70440c9e91e4562fa4430db
7
- data.tar.gz: 92500203c2972e1fa9b34835761a14adc33b21534c0f0856738fd106e6ef563e85a5725c9cde4970a7b7ff09286579bee55ffb375477a8d2938586568f2db420
6
+ metadata.gz: 98f2ddaa612efbd189e749c2ca79a12230851c0f1eec3aaffa908efb7e3a2027ecb966d60300d22eecd3ebc0ab62c7227be65d495eb719b300825927df062a59
7
+ data.tar.gz: c03f1fc3e97f934dadc3df3067c9f4a4d403449628b24daf65ed5352473d433c556cb9dea58b1c088617bcb7c97539bf7a68ca06c854f1dfd5ecc67a244cd4bf
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  /vendor/bundle/
5
5
  Gemfile.lock
6
6
  results.html
7
+ .yaml
8
+ .gem
data/Vagrantfile ADDED
@@ -0,0 +1,13 @@
1
+ Vagrant.configure("2") do |config|
2
+
3
+ config.environment.define config do |machine, options, env_settings|
4
+ machine.vm.network :private_network, ip: options["ip"]
5
+
6
+ machine.vm.provider :virtualbox do |vb, override|
7
+ vb.customize ["modifyvm", :id, "--memory", "2048"]
8
+ vb.customize ["modifyvm", :id, "--cpus", options["cpu"]]
9
+ override.vm.box = "centos6.3_x86_64_500g"
10
+ override.vm.box_url = "http://vbox.sciencescape.org/centos6.3_x86_64_500g.box"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ module Vagrant
2
+ module Plugin
3
+ module V2
4
+ # This is the base class for a CLI command.
5
+ class Command
6
+ protected
7
+ # Parses the options given an OptionParser instance.
8
+ #
9
+ # This is a convenience method that properly handles duping the
10
+ # originally argv array so that it is not destroyed.
11
+ #
12
+ # This method will also automatically detect "-h" and "--help"
13
+ # and print help. And if any invalid options are detected, the help
14
+ # will be printed, as well.
15
+ #
16
+ # If this method returns `nil`, then you should assume that help
17
+ # was printed and parsing failed.
18
+ def parse_options(opts=nil)
19
+ p "Overriden-----------------------------------------"
20
+ # Creating a shallow copy of the arguments so the OptionParser
21
+ # doesn't destroy the originals.
22
+ argv = @argv
23
+ # Default opts to a blank optionparser if none is given
24
+ opts ||= OptionParser.new
25
+ # Add the help option, which must be on every command.
26
+ opts.on_tail("-h", "--help", "Print this help") do
27
+ safe_puts(opts.help)
28
+ return nil
29
+ end
30
+
31
+ opts.on("-e ENVIRONMENT", "--environment ENVIRONMENT", "Define environment") do |environment|
32
+ ENV['VAGRANT_ENVIRONMENT'] = environment if !ENV.has_key?('VAGRANT_ENVIRONMENT') || ENV['VAGRANT_ENVIRONMENT'].nil?
33
+ end
34
+
35
+ opts.parse!(argv)
36
+ return argv
37
+ rescue OptionParser::InvalidOption
38
+ raise Errors::CLIInvalidOptions, help: opts.help.chomp
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ require 'yaml'
2
+
3
+ module VagrantPlugins
4
+ module Environments
5
+ class Config < Vagrant.plugin(2, :config)
6
+ attr_accessor :file, :active
7
+ attr_reader :data
8
+
9
+ DEFAULT_SETTINGS = {
10
+ file: 'environments.yaml'
11
+ }.freeze
12
+
13
+ def initialize
14
+ @file = UNSET_VALUE
15
+ @active = UNSET_VALUE
16
+ end
17
+
18
+ def file=(path)
19
+ @file = path unless path.empty?
20
+ end
21
+
22
+ def active
23
+
24
+ if @active == UNSET_VALUE && !ENV['VAGRANT_ENVIRONMENT'].nil?
25
+ @active = ENV['VAGRANT_ENVIRONMENT']
26
+ end
27
+
28
+ @active
29
+
30
+ end
31
+
32
+ def data
33
+ finalize!
34
+ environments = YAML.load_file(@file)
35
+ environments[@active]
36
+ end
37
+
38
+ def validate(_)
39
+ finalize!
40
+ errors = _detected_errors
41
+
42
+ if File.file?(@file)
43
+
44
+ begin
45
+ environments = YAML.load_file(@file)
46
+ errors.push("There is no #{@active} environment in #{@file}") unless environments.has_key?(@active)
47
+ rescue Exception
48
+ errors.push("file #{@file} have wrong format")
49
+ end
50
+
51
+ else
52
+ errors.push("file #{@file} does not exists")
53
+ end
54
+
55
+ { 'environments' => errors }
56
+ end
57
+
58
+ def finalize!
59
+ @file = DEFAULT_SETTINGS[:file] if @file == UNSET_VALUE
60
+ active
61
+ end
62
+
63
+
64
+ end #Config
65
+ end #Envrionments
66
+ end # VagrantPlugins
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Environments
3
+ class Environment < Vagrant.plugin(2, :config)
4
+
5
+ def define(config, &block)
6
+ settings = config.environments.data
7
+ settings["machines"].each do |name, options|
8
+ config.vm.define [config.environments.active, name].join('__') do |machine|
9
+ block.call(machine, options, settings["configs"])
10
+ end
11
+ end
12
+ end
13
+
14
+ def validate(_)
15
+ errors = _detected_errors
16
+ { 'environment' => errors }
17
+ end
18
+
19
+ end #Environment
20
+ end #Envrionments
21
+ end # VagrantPlugins
@@ -1,7 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module Environments
3
3
 
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
 
6
6
  end # Environments
7
7
  end # VagrantPlugins
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-environments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Rodionov
@@ -23,6 +23,7 @@ files:
23
23
  - LICENSE.md
24
24
  - README.md
25
25
  - Rakefile
26
+ - Vagrantfile
26
27
  - cucumber.yml
27
28
  - features/step_definitions/steps.rb
28
29
  - features/support/env.rb
@@ -33,6 +34,9 @@ files:
33
34
  - features/vagrant-exec/prepend.feature
34
35
  - features/vagrant-exec/validations.feature
35
36
  - lib/vagrant-environments.rb
37
+ - lib/vagrant-environments/command.rb
38
+ - lib/vagrant-environments/config.rb
39
+ - lib/vagrant-environments/environment.rb
36
40
  - lib/vagrant-environments/plugin.rb
37
41
  - lib/vagrant-environments/version.rb
38
42
  - vagrant-environments.gemspec