vagrant-dotvm 0.33.0 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2c4493bbc971762cd78c087bddafd0f65a28e1e
4
- data.tar.gz: 25b550ad3122a86fdba3798ad3837087bda96c52
3
+ metadata.gz: af05a860691da0d88715617d01a46581b0f4c5f7
4
+ data.tar.gz: ac1f7084700a621c080c90f52195246f667292aa
5
5
  SHA512:
6
- metadata.gz: 9c855e57c186204b4b9c7c26db8a64c770eab5a12385a52853f6546491ee6270596890fc5ac26b9ca47e76ef53e0eef7002480c37c4b74d841f8d8c37e53dc0a
7
- data.tar.gz: 129cc8bf0e2cbffa2b5985f33af4fd7e65a5224d53e74d57e40d9c5f8359d72b48d607990b4f9fa72b2ad577f066c95ebb58c9d2bf0744d5d8be28ae837d7c4c
6
+ metadata.gz: 00c8661dc1b6b789bc25c64e900c28e73fd5f3efadb4bcdd8080ed475e1195f01d6d99bff97b3584552718da845b76539bd754e6205fc59185aa0987f0d706a4
7
+ data.tar.gz: 708a029dc4ddea5d30777b2a951fb0eb16d444726a18fd86ee2d6cda00b8418cbbdc100feb583d4b03361948f9575bd50bef7b4e7f7efa9e3baf1d6a72d13c84
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.34.0
2
+ * New configuration directory layout
3
+ * Removed local variables
4
+ * Introduced project variables
5
+ * Removed examples, will be stored in separate repository
6
+ * Technical improvements
7
+
8
+ # 0.33.0
9
+ * Better handling of errors in configuration
10
+ * Fixed ability to set vCPUs in VMWare Fusion
11
+ * Technical improvements
12
+
1
13
  # 0.32.1
2
14
  * Bugfix for situation when configuration file is empty
3
15
  * Bugfix for situation when configuration doesn't have machines
@@ -32,50 +32,6 @@ module VagrantPlugins
32
32
 
33
33
  result
34
34
  end
35
-
36
- # Replaces variables in target object.
37
- #
38
- # @param vars [Hash] Hash of variables to be replaced.
39
- # @param target [Object] Object to operate on.
40
- # @return [Number] Number of performed replaces.
41
- def replace_vars(vars, target)
42
- replaced = 0
43
-
44
- if target.kind_of?(Array)
45
- target.each do |item|
46
- replaced += replace_vars(vars, item)
47
- end
48
- elsif target.kind_of?(Hash)
49
- target.each do |name, item|
50
- replaced += replace_vars(vars, item)
51
- end
52
- elsif target.kind_of?(String)
53
- vars.each do |k, v|
54
- pattern = "%#{k}%"
55
- replaced += 1 unless (target.gsub! pattern, v).kind_of?(NilClass)
56
- end
57
- elsif target.kind_of?(AbstractConfig)
58
- replaced += target.replace_vars!(vars)
59
- end
60
-
61
- replaced
62
- end
63
-
64
- # Search for variables within this object
65
- # and performs replaces of them.
66
- #
67
- # @param vars [Hash] Hash of variables to be replaced.
68
- # @return [Number] Number of performed replaces.
69
- def replace_vars!(vars)
70
- replaced = 0
71
-
72
- instance_variables.each do |var_name|
73
- var = instance_variable_get(var_name)
74
- replaced += replace_vars(vars, var)
75
- end
76
-
77
- replaced
78
- end
79
35
  end
80
36
  end
81
37
  end
@@ -0,0 +1,30 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ # Class represents whole instance of DotVm.
5
+ class Instance < AbstractConfig
6
+ include OptionsSetter
7
+
8
+ OPTIONS_CATEGORIES = [
9
+ :ssh,
10
+ :winrm,
11
+ :vagrant,
12
+ ]
13
+
14
+ attr_reader :projects
15
+ attr_reader :options # mixin
16
+ attr_reader :variables
17
+
18
+ def initialize
19
+ @projects = []
20
+ @variables = Variables.new
21
+ end
22
+
23
+ def new_project
24
+ projects << (project = Project.new self)
25
+ project
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,6 +8,7 @@ module VagrantPlugins
8
8
  :virtualbox,
9
9
  ]
10
10
 
11
+ attr_reader :parent
11
12
  attr_accessor :nick
12
13
  attr_accessor :hostname # name
13
14
  attr_accessor :box
@@ -42,6 +43,10 @@ module VagrantPlugins
42
43
  attr_accessor :guest
43
44
  attr_reader :usable_port_range
44
45
 
46
+ def initialize(parent)
47
+ @parent = parent
48
+ end
49
+
45
50
  def name=(value)
46
51
  @hostname = value
47
52
  end
@@ -91,8 +96,8 @@ module VagrantPlugins
91
96
  @shared_folders = convert_array(shared_folders, SharedFolder.name)
92
97
 
93
98
  settings = {
94
- 'host' => '%project.host%',
95
- 'guest' => '%project.guest%',
99
+ 'host' => @parent.variables['host.project_dir'],
100
+ 'guest' => @parent.variables['guest.project_dir'],
96
101
  'disabled' => false,
97
102
  'create' => false,
98
103
  'type' => nil,
@@ -0,0 +1,23 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ # Class represents one project
5
+ class Project < AbstractConfig
6
+ attr_reader :parent
7
+ attr_reader :variables
8
+ attr_reader :machines
9
+
10
+ def initialize(parent)
11
+ @parent = parent
12
+ @variables = Variables.new
13
+ @machines = Array.new
14
+ end
15
+
16
+ def new_machine
17
+ machines << (machine = Machine.new self)
18
+ machine
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -8,79 +8,81 @@ module VagrantPlugins
8
8
  end
9
9
 
10
10
  private
11
- def get_globals
12
- globals = {}
11
+ def parse_variables(path)
12
+ result = {}
13
13
 
14
- Dir[@path + '/globals/*.yaml'].each do |fname|
14
+ Dir[path].each do |fname|
15
15
  yaml = YAML::load(File.read(fname)) || {}
16
16
  yaml.each do |name, value|
17
- globals[name] = value
17
+ raise "Variable #{name} already exists." if result.has_key? name
18
+ result[name] = value
18
19
  end
19
20
  end
20
21
 
21
- globals
22
+ result
22
23
  end
23
24
 
24
25
  private
25
- def prefix_vars(vars, prefix)
26
- result = {}
26
+ def init_instance
27
+ @instance = Config::Instance.new
28
+ @instance.variables.append_group 'env', ENV
29
+ @instance.variables.append_group 'global', (parse_variables "#{@path}/variables/*.yaml")
30
+ end
27
31
 
28
- vars.each do |name, value|
29
- result[prefix + name] = value
32
+ private
33
+ def load_options
34
+ Dir["#{@path}/options/*.yaml"].each do |file|
35
+ @instance.options = Replacer.new
36
+ .on(YAML::load(File.read(file)) || {})
37
+ .using(@instance.variables)
38
+ .result
30
39
  end
31
-
32
- result
33
40
  end
34
41
 
35
42
  private
36
- def process_config(fname)
37
- yaml = YAML::load(File.read(fname)) || {}
38
-
39
- begin
40
- conf = Config::Root.new
41
- conf.populate yaml
42
-
43
- vars = {}
44
- vars.merge! prefix_vars(ENV, 'env.')
45
- vars.merge! prefix_vars(get_globals, 'global.')
46
- vars.merge! prefix_vars(conf.vars.to_h, 'local.')
47
- vars.merge!(
43
+ def load_projects
44
+ Dir["#{@path}/projects/*"].each do |dir|
45
+ project = @instance.new_project
46
+ project.variables.append_group 'project', (parse_variables "#{dir}/variables/*.yaml")
47
+ project.variables.append_group(
48
+ 'host',
48
49
  {
49
- 'project.host' => File.dirname(fname),
50
- 'project.guest' => '/dotvm/project',
50
+ 'project_dir' => dir,
51
+ 'files_dir' => "#{dir}/files",
52
+ }
53
+ )
54
+ project.variables.append_group(
55
+ 'guest',
56
+ {
57
+ 'project_dir' => DOTVM_PROJECT_PATH,
58
+ 'files_dir' => "#{DOTVM_PROJECT_PATH}/files"
51
59
  }
52
60
  )
53
61
 
54
- for _ in (0..5)
55
- last = conf.replace_vars! vars
56
- break if last == 0
62
+ Dir["#{dir}/machines/*.yaml"].each do |file|
63
+ begin
64
+ yaml = Replacer.new
65
+ .on(YAML::load(File.read(file)) || [])
66
+ .using(@instance.variables.merge(project.variables))
67
+ .result
68
+
69
+ yaml.each do |machine_yaml|
70
+ machine = project.new_machine
71
+ machine.populate machine_yaml
72
+ end
73
+ rescue VagrantPlugins::Dotvm::Config::InvalidConfigError => e
74
+ raise Vagrant::Errors::VagrantError.new, "DotVM: #{file}: #{e.message}"
75
+ end
57
76
  end
58
-
59
- raise 'Too deep variables relations, possible recurrence.' unless last == 0
60
- rescue VagrantPlugins::Dotvm::Config::InvalidConfigError => e
61
- file = fname[(@path.length + '/projects/'.length)..-1]
62
- raise Vagrant::Errors::VagrantError.new, "DotVM: #{file}: #{e.message}"
63
- end
64
-
65
- conf
66
- end
67
-
68
- private
69
- def get_configs
70
- configs = []
71
-
72
- Dir[@path + '/projects/*/*.yaml'].each do |fname|
73
- configs << process_config(fname)
74
77
  end
75
-
76
- return configs
77
78
  end
78
79
 
79
80
  public
80
81
  def inject(vc)
81
- get_configs.each do |config|
82
- Injector::Root.inject config: config, vc: vc
83
- end
82
+ init_instance
83
+ load_options
84
+ load_projects
85
+ Injector::Instance.inject @instance, vc
84
86
  end
85
87
 
86
88
  end # DotVm
@@ -13,6 +13,7 @@ module VagrantPlugins
13
13
  s.path = "#{UTILS_PATH}/authorize_key.sh"
14
14
  s.args = [pubkey]
15
15
  s.privileged = false
16
+ s.name = "authorized ssh key #{pubkey.split[2]}"
16
17
  end
17
18
  end
18
19
  end
@@ -7,6 +7,7 @@ module VagrantPlugins
7
7
  s.path = "#{UTILS_PATH}/add_host.sh"
8
8
  s.args = [host.ip, host.host]
9
9
  s.privileged = true
10
+ s.name = "host #{host.host} -> #{host.ip}"
10
11
  end
11
12
  end
12
13
  end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Injector
4
+ class Instance < AbstractInjector
5
+ def self.inject(instance, vc)
6
+ instance.options.to_h.each do |category, options|
7
+ options.to_a.each do |option|
8
+ vc.send(category).send("#{option.name}=", option.value)
9
+ end
10
+ end
11
+
12
+ instance.projects.each do |project|
13
+ Injector::Project.inject project, vc
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Injector
4
+ class Project < AbstractInjector
5
+ def self.inject(project, vc)
6
+ project.machines.to_a.each do |machine_cfg|
7
+ Machine.inject machine_cfg: machine_cfg, vc: vc
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,6 +7,7 @@ module VagrantPlugins
7
7
  s.path = "#{UTILS_PATH}/setup_route.sh"
8
8
  s.args = [route.destination, route.gateway]
9
9
  s.privileged = true
10
+ s.name = "route to #{route.destination} via #{route.gateway}"
10
11
  end
11
12
  end
12
13
  end
@@ -1,5 +1,6 @@
1
1
  module VagrantPlugins
2
2
  module Dotvm
3
3
  UTILS_PATH = File.dirname(__FILE__) + '/../../utils'
4
+ DOTVM_PROJECT_PATH = '/dotvm/project'
4
5
  end
5
6
  end
@@ -0,0 +1,76 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ class Replacer
4
+ def initialize
5
+ @limit = 10
6
+ end
7
+
8
+ def on(target)
9
+ @target = target
10
+ self
11
+ end
12
+
13
+ def using(vars)
14
+ @vars = vars
15
+ self
16
+ end
17
+
18
+ def limit(limit)
19
+ @limit = limit
20
+ self
21
+ end
22
+
23
+ def result
24
+ 0.upto(@limit).each do |_|
25
+ @replaced = 0
26
+ target = _replace_vars @target
27
+ return target if @replaced == 0
28
+ end
29
+
30
+ raise 'Too deep variables relations, possible recurrence.'
31
+ end
32
+
33
+ private
34
+ def process_string(target)
35
+ @vars.each do |k, v|
36
+ pattern = "%#{k}%"
37
+
38
+ if target.include? pattern
39
+ @replaced += 1
40
+
41
+ if target == pattern
42
+ target = v
43
+ break unless v.is_a? String # value is no longer string, so replace cannot be performed
44
+ else
45
+ unless v.respond_to? :to_s
46
+ raise 'Non-string values cannot be joined together.'
47
+ end
48
+
49
+ target = target.gsub pattern, v.to_s
50
+ end
51
+ end
52
+ end
53
+
54
+ target
55
+ end
56
+
57
+ private
58
+ def _replace_vars(target)
59
+ case target
60
+ when Hash
61
+ target.each do |k, v|
62
+ target[k] = _replace_vars v
63
+ end
64
+ when Array
65
+ target.map! do |v|
66
+ _replace_vars v
67
+ end
68
+ when String
69
+ target = process_string target
70
+ end
71
+
72
+ target
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ class Variables < Hash
4
+ def append_group(group, items)
5
+ items.each do |name, value|
6
+ self["#{group}.#{name}"] = value
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Dotvm
3
- VERSION = '0.33.0'
3
+ VERSION = '0.34.0'
4
4
  end
5
5
  end
data/lib/vagrant-dotvm.rb CHANGED
@@ -6,8 +6,12 @@ require 'vagrant-dotvm/version'
6
6
  require 'vagrant-dotvm/paths'
7
7
  require 'vagrant-dotvm/dotvm'
8
8
 
9
+ require 'vagrant-dotvm/variables'
10
+ require 'vagrant-dotvm/replacer'
11
+
9
12
  require 'vagrant-dotvm/injector/abstractinjector'
10
- require 'vagrant-dotvm/injector/root'
13
+ require 'vagrant-dotvm/injector/instance'
14
+ require 'vagrant-dotvm/injector/project'
11
15
  require 'vagrant-dotvm/injector/machine'
12
16
  require 'vagrant-dotvm/injector/provision'
13
17
  require 'vagrant-dotvm/injector/authorizedkey'
@@ -19,7 +23,8 @@ require 'vagrant-dotvm/injector/network'
19
23
  require 'vagrant-dotvm/config/optionssetter'
20
24
  require 'vagrant-dotvm/config/invalidconfigerror'
21
25
  require 'vagrant-dotvm/config/abstractconfig'
22
- require 'vagrant-dotvm/config/root'
26
+ require 'vagrant-dotvm/config/instance'
27
+ require 'vagrant-dotvm/config/project'
23
28
  require 'vagrant-dotvm/config/machine'
24
29
  require 'vagrant-dotvm/config/provision'
25
30
  require 'vagrant-dotvm/config/authorizedkey'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dotvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Magosa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,26 +51,19 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
- - examples/.gitignore
55
- - examples/Vagrantfile
56
- - examples/config/projects/playground/Puppetfile
57
- - examples/config/projects/playground/bootstrap.sh
58
- - examples/config/projects/playground/config.ini
59
- - examples/config/projects/playground/default.pp
60
- - examples/config/projects/playground/main.yaml
61
- - examples/config/projects/playground/modules/.gitkeep
62
54
  - lib/vagrant-dotvm.rb
63
55
  - lib/vagrant-dotvm/config/abstractconfig.rb
64
56
  - lib/vagrant-dotvm/config/authorizedkey.rb
65
57
  - lib/vagrant-dotvm/config/buildimage.rb
66
58
  - lib/vagrant-dotvm/config/host.rb
59
+ - lib/vagrant-dotvm/config/instance.rb
67
60
  - lib/vagrant-dotvm/config/invalidconfigerror.rb
68
61
  - lib/vagrant-dotvm/config/machine.rb
69
62
  - lib/vagrant-dotvm/config/network.rb
70
63
  - lib/vagrant-dotvm/config/option.rb
71
64
  - lib/vagrant-dotvm/config/optionssetter.rb
65
+ - lib/vagrant-dotvm/config/project.rb
72
66
  - lib/vagrant-dotvm/config/provision.rb
73
- - lib/vagrant-dotvm/config/root.rb
74
67
  - lib/vagrant-dotvm/config/route.rb
75
68
  - lib/vagrant-dotvm/config/run.rb
76
69
  - lib/vagrant-dotvm/config/sharedfolder.rb
@@ -78,14 +71,17 @@ files:
78
71
  - lib/vagrant-dotvm/injector/abstractinjector.rb
79
72
  - lib/vagrant-dotvm/injector/authorizedkey.rb
80
73
  - lib/vagrant-dotvm/injector/host.rb
74
+ - lib/vagrant-dotvm/injector/instance.rb
81
75
  - lib/vagrant-dotvm/injector/machine.rb
82
76
  - lib/vagrant-dotvm/injector/network.rb
77
+ - lib/vagrant-dotvm/injector/project.rb
83
78
  - lib/vagrant-dotvm/injector/provision.rb
84
- - lib/vagrant-dotvm/injector/root.rb
85
79
  - lib/vagrant-dotvm/injector/route.rb
86
80
  - lib/vagrant-dotvm/injector/sharedfolder.rb
87
81
  - lib/vagrant-dotvm/paths.rb
88
82
  - lib/vagrant-dotvm/plugin.rb
83
+ - lib/vagrant-dotvm/replacer.rb
84
+ - lib/vagrant-dotvm/variables.rb
89
85
  - lib/vagrant-dotvm/version.rb
90
86
  - utils/add_host.sh
91
87
  - utils/authorize_key.sh
data/examples/.gitignore DELETED
@@ -1 +0,0 @@
1
- .vagrant/
data/examples/Vagrantfile DELETED
@@ -1,10 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- require 'vagrant-dotvm'
5
-
6
- Vagrant.configure(2) do |config|
7
- config_path = File.dirname(File.expand_path(__FILE__)) + "/config"
8
- dotvm = VagrantPlugins::Dotvm::Dotvm.new config_path
9
- dotvm.inject(config)
10
- end
@@ -1,6 +0,0 @@
1
- moduledir '/etc/puppet/modules'
2
-
3
- mod 'puppetlabs/apt', '2.1.0'
4
- mod 'puppetlabs/concat', '1.2.3'
5
- mod 'puppetlabs/stdlib', '4.6.0'
6
- mod 'puppetlabs/nodejs', '0.8.0'
@@ -1,15 +0,0 @@
1
- # Go to %project.guest% directory, so relative paths will work here.
2
- cd "$1"
3
-
4
- # Ruby gems binaries go there.
5
- PATH="/usr/local/bin:$PATH"
6
-
7
- # Install puppet from EPEL repository
8
- rpm --force -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
9
- yum install -y puppet
10
-
11
- # Install r10k - puppet module manager
12
- gem install r10k
13
-
14
- # Install required puppet modules
15
- r10k puppetfile install
File without changes
@@ -1,9 +0,0 @@
1
- package { 'npm':
2
- ensure => installed,
3
- }
4
-
5
- package { 'grunt-cli':
6
- ensure => installed,
7
- provider => npm,
8
- require => Package['npm'],
9
- }
@@ -1,52 +0,0 @@
1
- machines:
2
- - nick: machine1
3
- name: machine1.example.com
4
- box: chef/centos-7.0
5
- memory: 1024
6
- cpus: 1
7
- cpucap: 100
8
- primary: true
9
- natnet: 192.168.22.0/24
10
- boot_timeout: 300
11
- box_check_update: true
12
- box_version: ">= 0"
13
- graceful_halt_timeout: 60
14
- post_up_message: "hello!"
15
- autostart: true
16
- networks:
17
- - net: private_network
18
- type: static
19
- ip: 192.168.56.100
20
- mask: 255.255.255.0
21
- interface: "intnet0"
22
- - net: public_network
23
- type: dhcp
24
- bridge: "en0: Wi-Fi (AirPort)"
25
- - net: forwarded_port
26
- guest: 80
27
- host: 54321
28
- protocol: tcp
29
- authorized_keys:
30
- - type: file
31
- path: "~/.ssh/id_rsa.pub"
32
- - type: static
33
- key: "ssh-rsa fakeSSHpubKEY km@laptop"
34
- provision:
35
- - type: file
36
- source: "%project.host%/config.ini"
37
- destination: "~/config.ini"
38
- - type: shell
39
- path: "%project.host%/bootstrap.sh"
40
- privileged: true
41
- args:
42
- - "%project.guest%"
43
- - type: puppet
44
- manifests_path: "%project.host%"
45
- manifest_file: "default.pp"
46
- module_path: "%project.host%/modules"
47
- shared_folders:
48
- - host: ~/projects
49
- guest: /srv/www
50
- disabled: false
51
- create: false
52
- type: null
File without changes
@@ -1,29 +0,0 @@
1
- module VagrantPlugins
2
- module Dotvm
3
- module Config
4
- class Root < AbstractConfig
5
- OPTIONS_CATEGORIES = [
6
- :ssh,
7
- :winrm,
8
- :vagrant,
9
- ]
10
-
11
- include OptionsSetter
12
-
13
- attr_reader :machines
14
- attr_reader :options # mixin
15
- attr_reader :vars
16
-
17
- def machines=(machines)
18
- ensure_type machines, Array, 'machines'
19
- @machines = convert_array(machines, Machine.name)
20
- end
21
-
22
- def vars=(vars)
23
- ensure_type vars, Hash, 'vars'
24
- @vars = vars
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- module VagrantPlugins
2
- module Dotvm
3
- module Injector
4
- class Root < AbstractInjector
5
- def self.inject(config: nil, vc: nil)
6
- config.options.to_h.each do |category, options|
7
- options.to_a.each do |option|
8
- vc.send(category).send("#{option.name}=", option.value)
9
- end
10
- end
11
-
12
- config.machines.to_a.each do |machine_cfg|
13
- Machine.inject machine_cfg: machine_cfg, vc: vc
14
- end
15
- end
16
- end # Root
17
- end # Injector
18
- end # Dotvm
19
- end # VagrantPlugins