vagrant-dotvm 0.14.0 → 0.15.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: 48da5ae40935aab0b20cb682da883e4a47789297
4
- data.tar.gz: f35a30c07db80def6746151e3402fe8e7ee97167
3
+ metadata.gz: 5f0cf0b9fa0ed709ac916220979c7ef5d83252a2
4
+ data.tar.gz: 09c15695b3db78795e53e1adc2e06e57731b29a1
5
5
  SHA512:
6
- metadata.gz: 60644d8db7e1ebd44ebd79108fc24f62743e421e42f616fd7da65d27e867771195fd6bc5216ecbcdf986b54c1a433085016d6cf3a00fb4939cd8be00e10baa64
7
- data.tar.gz: 925b895413c55f0322c12d67548860a04a6fd688991e9abe9a1f80867f6fa873b95571dac234deb0fa132d0af15e81285bd07d3ff068e7f5ce6987ca0e600c61
6
+ metadata.gz: d08bff1d15b8f04d0d1cf0dfc2cc9907d719cbc3806846756782e0ba6d83fdcbfde504a8e394bec7b43c82e473049f2162a8d229c4c7eb21053f93f681036302
7
+ data.tar.gz: d56381df9d695c16d7f09d24e76770b875f12617ea9163459c99640ca0084fb349104d68adff69b2a84f7e7a7d5b3e536efe0b6ab8b38c12250c3a64ab92fa78
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.15.0
2
+ * Ability to set run option on provision
3
+ * Fix privileged option in provision
4
+ * Ability to setup static routes
5
+
1
6
  # 0.14.0
2
7
  * Ability to configure autostart option
3
8
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## What is that?
4
4
  DotVm is vagrant plugin for easier maintenance of multi machine configurations.
5
- It allows you to plugin multiple directories, where each one can hold multiple YAML files, where each one can define multiple machines.
5
+ DotVm joins easy syntax of YAML files with flexibility offered by configuration exploded into several small files.
6
6
 
7
7
  ## How to start using DotVm
8
8
  First you need to install DotVm plugin:
@@ -37,6 +37,7 @@ machines:
37
37
  destination: "~/config.ini"
38
38
  - type: shell
39
39
  path: "%project.host%/bootstrap.sh"
40
+ privileged: true
40
41
  args:
41
42
  - "%project.guest%"
42
43
  - type: puppet
data/lib/vagrant-dotvm.rb CHANGED
@@ -4,5 +4,6 @@ require 'yaml'
4
4
  require 'vagrant-dotvm/plugin'
5
5
  require 'vagrant-dotvm/version'
6
6
  require 'vagrant-dotvm/dotvm'
7
+ require 'vagrant-dotvm/defaults'
7
8
  require 'vagrant-dotvm/configparser'
8
9
  require 'vagrant-dotvm/configinjecter'
@@ -2,6 +2,7 @@ module VagrantPlugins
2
2
  module Dotvm
3
3
  class ConfigInjecter
4
4
 
5
+ public
5
6
  def self.inject(config, vc)
6
7
  # General settings
7
8
  vc.ssh.forward_x11 = true
@@ -10,20 +11,20 @@ module VagrantPlugins
10
11
  vc.vm.define machine_cfg[:nick],
11
12
  primary: machine_cfg[:primary],
12
13
  autostart: machine_cfg[:autostart] do |machine|
13
- machine.vm.box = machine_cfg[:box]
14
- machine.vm.hostname = machine_cfg[:name]
15
- machine.vm.boot_timeout = machine_cfg[:boot_timeout]
16
- machine.vm.box_check_update = machine_cfg[:box_check_update]
17
- machine.vm.box_version = machine_cfg[:box_version]
14
+ machine.vm.box = machine_cfg[:box]
15
+ machine.vm.hostname = machine_cfg[:name]
16
+ machine.vm.boot_timeout = machine_cfg[:boot_timeout]
17
+ machine.vm.box_check_update = machine_cfg[:box_check_update]
18
+ machine.vm.box_version = machine_cfg[:box_version]
18
19
  machine.vm.graceful_halt_timeout = machine_cfg[:graceful_halt_timeout]
19
- machine.vm.post_up_message = machine_cfg[:post_up_message]
20
+ machine.vm.post_up_message = machine_cfg[:post_up_message]
20
21
 
21
22
  machine.vm.provider "virtualbox" do |vb|
22
- vb.customize ['modifyvm', :id, '--memory', machine_cfg['memory'] ||= 1024]
23
- vb.customize ['modifyvm', :id, '--cpus', machine_cfg['cpus'] ||= 1]
24
- vb.customize ['modifyvm', :id, '--cpuexecutioncap', machine_cfg['cpucap'] ||= 100]
25
- vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
26
- vb.customize ['modifyvm', :id, '--natnet1', machine_cfg['natnet'] ||= '192.168.88.0/24']
23
+ vb.customize ["modifyvm", :id, "--memory", machine_cfg[:memory]]
24
+ vb.customize ["modifyvm", :id, "--cpus", machine_cfg[:cpus]]
25
+ vb.customize ["modifyvm", :id, "--cpuexecutioncap", machine_cfg[:cpucap]]
26
+ vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
27
+ vb.customize ["modifyvm", :id, "--natnet1", machine_cfg["natnet"]]
27
28
  end
28
29
 
29
30
  machine_cfg[:networks].each do |net|
@@ -43,20 +44,28 @@ module VagrantPlugins
43
44
  machine.vm.network net[:net],
44
45
  guest: net[:guest],
45
46
  host: net[:host],
46
- protocol: net[:protocol]
47
+ protocol: net[:protocol]
48
+ end
49
+ end
50
+
51
+ machine_cfg[:routes].each do |route|
52
+ machine.vm.provision "shell", run: "always" do |s|
53
+ s.path = File.dirname(__FILE__) + "/../../utils/setup_route.sh"
54
+ s.args = [route[:destination], route[:gateway]]
55
+ s.privileged = true
47
56
  end
48
57
  end
49
58
 
50
59
  machine_cfg[:provision].each do |provision|
51
- machine.vm.provision provision[:type] do |p|
52
- if provision[:type] == 'shell'
60
+ machine.vm.provision provision[:type], run: provision[:run] do |p|
61
+ if provision[:type] == "shell"
53
62
  p.path = provision[:path]
54
63
  p.args = provision[:args]
55
- p.privileged = provision[:privileged] ||= true
56
- elsif provision[:type] == 'file'
64
+ p.privileged = provision[:privileged]
65
+ elsif provision[:type] == "file"
57
66
  p.source = provision[:source]
58
67
  p.destination = provision[:destination]
59
- elsif provision[:type] == 'puppet'
68
+ elsif provision[:type] == "puppet"
60
69
  p.module_path = provision[:module_path]
61
70
  p.manifest_file = provision[:manifest_file]
62
71
  p.manifests_path = provision[:manifests_path]
@@ -73,20 +82,20 @@ module VagrantPlugins
73
82
  end
74
83
 
75
84
  machine_cfg[:authorized_keys].each do |key|
76
- if key[:type] == 'file'
85
+ if key[:type] == "file"
77
86
  pubkey = File.readlines(File.expand_path(key[:path])).first.strip
78
- elsif key[:type] == 'static'
87
+ elsif key[:type] == "static"
79
88
  pubkey = key[:key]
80
89
  end
81
90
 
82
- machine.vm.provision 'shell' do |s|
91
+ machine.vm.provision "shell" do |s|
83
92
  s.path = File.dirname(__FILE__) + "/../../utils/authorize_key.sh"
84
93
  s.args = [pubkey]
85
94
  s.privileged = false
86
95
  end
87
96
  end
88
97
 
89
- if Vagrant.has_plugin?('vagrant-group')
98
+ if Vagrant.has_plugin?("vagrant-group")
90
99
  vc.group.groups = {} unless vc.group.groups.kind_of?(Hash)
91
100
 
92
101
  machine_cfg[:groups].each do |group|
@@ -2,35 +2,26 @@ module VagrantPlugins
2
2
  module Dotvm
3
3
  class ConfigParser
4
4
 
5
- DEFAULT_NET = 'private_network'
6
- DEFAULT_NET_TYPE = 'static'
7
- DEFAULT_NETMASK = '255.255.255.0'
8
- DEFAULT_PROTOCOL = 'tcp'
9
- DEFAULT_BOOT_TIMEOUT = 300
10
- DEFAULT_BOX_CHECK_UPDATE = true
11
- DEFAULT_BOX_VERSION = '>= 0'
12
- DEFAULT_GRACEFUL_HALT_TIMEOUT = 60
13
-
14
5
  def initialize(vars = {})
15
6
  @vars = vars
16
7
  end
17
8
 
18
-
9
+ private
19
10
  def replace_vars(value)
20
11
  if value.kind_of?(Hash)
21
12
  result = {}
22
13
  value.each do |key, val|
23
- result[key] = self.replace_vars(val)
14
+ result[key] = replace_vars(val)
24
15
  end
25
16
  elsif value.kind_of?(Array)
26
17
  result = value.map do |val|
27
- self.replace_vars(val)
18
+ replace_vars(val)
28
19
  end
29
20
  elsif value.kind_of?(String)
30
21
  result = value.dup
31
22
 
32
23
  @vars.each do |k, v|
33
- pattern = '%' + k + '%'
24
+ pattern = "%#{k}%"
34
25
  result.gsub! pattern, v
35
26
  end
36
27
  elsif !value.respond_to?(:duplicable) or !value.duplicable?
@@ -42,142 +33,155 @@ module VagrantPlugins
42
33
  return result
43
34
  end
44
35
 
45
-
36
+ private
46
37
  def parse_machine(machine)
47
- return {
48
- :nick => machine['nick'],
49
- :name => machine['name'],
50
- :box => machine['box'],
51
- :memory => machine['memory'],
52
- :cpus => machine['cpus'],
53
- :cpucap => machine['cpucap'],
54
- :primary => self.coalesce(machine['primary'], false),
55
- :natnet => machine['natnet'],
56
- :networks => [],
57
- :provision => [],
58
- :folders => [
38
+ {
39
+ :nick => machine["nick"],
40
+ :name => machine["name"],
41
+ :box => machine["box"],
42
+ :memory => coalesce(machine["memory"], Defaults::MEMORY),
43
+ :cpus => coalesce(machine["cpus"], Defaults::CPUS),
44
+ :cpucap => coalesce(machine["cpucap"], Defaults::CPUCAP),
45
+ :primary => coalesce(machine["primary"], false),
46
+ :natnet => coalesce(machine["natnet"], Defaults::NATNET),
47
+ :networks => [],
48
+ :routes => [],
49
+ :provision => [],
50
+ :groups => [],
51
+ :authorized_keys => [],
52
+ :boot_timeout => coalesce(machine["boot_timeout"], Defaults::BOOT_TIMEOUT),
53
+ :box_check_update => coalesce(machine["box_check_update"], Defaults::BOX_CHECK_UPDATE),
54
+ :box_version => coalesce(machine["box_version"], Defaults::BOX_VERSION),
55
+ :graceful_halt_timeout => coalesce(machine["graceful_halt_timeout"], Defaults::GRACEFUL_HALT_TIMEOUT),
56
+ :post_up_message => machine["post_up_message"],
57
+ :autostart => coalesce(machine["autostart"], true),
58
+ :folders => [
59
59
  {
60
- :host => '%project.host%',
61
- :guest => '%project.guest%',
60
+ :host => "%project.host%",
61
+ :guest => "%project.guest%",
62
62
  :disabled => false,
63
- :create => false,
64
- :type => nil,
63
+ :create => false,
64
+ :type => nil,
65
65
  }
66
66
  ],
67
- :groups => [],
68
- :authorized_keys => [],
69
- :boot_timeout => self.coalesce(machine['boot_timeout'], DEFAULT_BOOT_TIMEOUT),
70
- :box_check_update => self.coalesce(machine['box_check_update'], DEFAULT_BOX_CHECK_UPDATE),
71
- :box_version => self.coalesce(machine['box_version'], DEFAULT_BOX_VERSION),
72
- :graceful_halt_timeout => self.coalesce(machine['graceful_halt_timeout'], DEFAULT_GRACEFUL_HALT_TIMEOUT),
73
- :post_up_message => machine['post_up_message'],
74
- :autostart => self.coalesce(machine['autostart'], true),
75
67
  }
76
68
  end
77
69
 
78
-
70
+ private
79
71
  def parse_net(net)
80
- case net['net']
81
- when 'private_network', 'private'
82
- nettype = :private_network
83
- when 'forwarded_port', 'port'
84
- nettype = :forwarded_port
85
- when 'public_network', 'public', 'bridged'
86
- nettype = :public_network
87
- else
88
- nettype = DEFAULT_NET
89
- end
90
-
91
- return {
92
- :net => nettype,
93
- :type => self.coalesce(net['type'], DEFAULT_NET_TYPE),
94
- :ip => net['ip'],
95
- :mask => self.coalesce(net['mask'], net['netmask'], DEFAULT_NETMASK),
96
- :interface => net['interface'],
97
- :guest => net['guest'],
98
- :host => net['host'],
99
- :protocol => self.coalesce(net['protocol'], DEFAULT_PROTOCOL),
100
- :bridge => net['bridge'],
72
+ nets = {
73
+ "private_network" => :private_network,
74
+ "private" => :private_network,
75
+ "public_network" => :public_network,
76
+ "public" => :public_network,
77
+ "forwarded_port" => :forwarded_port,
78
+ "port" => :forwarded_port,
79
+ }
80
+
81
+ {
82
+ :net => nets.has_key?(net["net"]) ? nets[net["net"]] : Defaults::NET,
83
+ :type => coalesce(net["type"], Defaults::NET_TYPE),
84
+ :ip => net["ip"],
85
+ :mask => coalesce(net["mask"], net["netmask"], Defaults::NETMASK),
86
+ :interface => net["interface"],
87
+ :guest => net["guest"],
88
+ :host => net["host"],
89
+ :protocol => coalesce(net["protocol"], Defaults::PROTOCOL),
90
+ :bridge => net["bridge"],
101
91
  }
102
92
  end
103
93
 
104
-
105
- def parse_provision(prv)
106
- return {
107
- :type => prv['type'],
108
- :source => prv['source'],
109
- :destination => prv['destination'],
110
- :path => prv['path'],
111
- :args => prv['args'],
112
- :module_path => prv['module_path'],
113
- :manifests_path => prv['manifests_path'],
114
- :manifest_file => prv['manifest_file'],
94
+ private
95
+ def parse_route(route)
96
+ {
97
+ :destination => route["destination"],
98
+ :gateway => route["gateway"],
115
99
  }
116
100
  end
117
101
 
102
+ private
103
+ def parse_provision(prv)
104
+ {
105
+ :type => prv["type"],
106
+ :source => prv["source"],
107
+ :destination => prv["destination"],
108
+ :path => prv["path"],
109
+ :args => prv["args"],
110
+ :module_path => prv["module_path"],
111
+ :manifests_path => prv["manifests_path"],
112
+ :manifest_file => prv["manifest_file"],
113
+ :privileged => prv["privileged"].nil? ? true : prv["privileged"],
114
+ :run => prv["run"],
115
+ }
116
+ end
118
117
 
118
+ private
119
119
  def parse_folder(folder)
120
- return {
121
- :host => folder['host'],
122
- :guest => folder['guest'],
123
- :disabled => self.coalesce(folder['disabled'], false),
124
- :create => self.coalesce(folder['create'], false),
125
- :type => folder['type'],
120
+ {
121
+ :host => folder["host"],
122
+ :guest => folder["guest"],
123
+ :disabled => coalesce(folder["disabled"], false),
124
+ :create => coalesce(folder["create"], false),
125
+ :type => folder["type"],
126
126
  }
127
127
  end
128
128
 
129
-
129
+ private
130
130
  def parse_authorized_key(key)
131
- return {
132
- :type => key['type'],
133
- :path => key['path'],
134
- :key => key['key'],
131
+ {
132
+ :type => key["type"],
133
+ :path => key["path"],
134
+ :key => key["key"],
135
135
  }
136
136
  end
137
137
 
138
-
138
+ public
139
139
  def parse(yaml)
140
140
  config = {
141
141
  :machines => []
142
142
  }
143
143
 
144
- yaml['machines'].each do |machine|
144
+ yaml["machines"].each do |machine|
145
145
  item = parse_machine(machine)
146
146
 
147
- machine['networks'] and machine['networks'].each do |net|
148
- item[:networks] << self.parse_net(net)
147
+ machine["networks"].to_a.each do |net|
148
+ item[:networks] << parse_net(net)
149
149
  end
150
150
 
151
- machine['provision'] and machine['provision'].each do |prv|
152
- item[:provision] << self.parse_provision(prv)
151
+ machine["routes"].to_a.each do |route|
152
+ item[:routes] << parse_route(route)
153
153
  end
154
154
 
155
- machine['shared_folders'] and machine['shared_folders'].each do |folder|
156
- item[:folders] << self.parse_folder(folder)
155
+ machine["provision"].to_a.each do |prv|
156
+ item[:provision] << parse_provision(prv)
157
157
  end
158
158
 
159
- machine['groups'] and machine['groups'].each do |group|
159
+ machine["shared_folders"].to_a.each do |folder|
160
+ item[:folders] << parse_folder(folder)
161
+ end
162
+
163
+ machine["groups"].to_a.each do |group|
160
164
  item[:groups] << group
161
165
  end
162
166
 
163
- machine['authorized_keys'].to_a.each do |key|
164
- item[:authorized_keys] << self.parse_authorized_key(key)
167
+ machine["authorized_keys"].to_a.each do |key|
168
+ item[:authorized_keys] << parse_authorized_key(key)
165
169
  end
166
170
 
167
171
  config[:machines] << item
168
172
  end
169
173
 
170
- return self.replace_vars(config)
174
+ replace_vars(config)
171
175
  end
172
176
 
173
-
177
+ private
174
178
  def coalesce(*args)
175
179
  args.each do |val|
176
180
  next if val.nil?
177
181
  return val
178
182
  end
179
183
  end
180
-
184
+
181
185
  end
182
186
  end
183
187
  end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ class Defaults
4
+ MEMORY = 1024
5
+ CPUS = 1
6
+ CPUCAP = 100
7
+ NATNET = "192.168.88.0/24"
8
+ NET = :private_network
9
+ NET_TYPE = "static"
10
+ NETMASK = "255.255.255.0"
11
+ PROTOCOL = "tcp"
12
+ BOOT_TIMEOUT = 300
13
+ BOX_CHECK_UPDATE = true
14
+ BOX_VERSION = ">= 0"
15
+ GRACEFUL_HALT_TIMEOUT = 60
16
+ end # Defaults
17
+ end # Dotvm
18
+ end # VagrantPlugins
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
  @path = path
11
11
  end
12
12
 
13
-
13
+ private
14
14
  def get_configs()
15
15
  configs = []
16
16
 
@@ -33,9 +33,9 @@ module VagrantPlugins
33
33
  return configs
34
34
  end
35
35
 
36
-
36
+ public
37
37
  def inject(vc)
38
- configs = self.get_configs()
38
+ configs = get_configs()
39
39
 
40
40
  configs.each do |config|
41
41
  ConfigInjecter.inject(config, vc)
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Dotvm
3
- VERSION = "0.14.0"
3
+ VERSION = "0.15.0"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ DESTINATION="$1"
2
+ GATEWAY="$2"
3
+
4
+ while ip route delete "$DESTINATION" ; do :; done >/dev/null 2>&1
5
+ ip route replace "$DESTINATION" via "$GATEWAY"
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.14.0
4
+ version: 0.15.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-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,10 +62,12 @@ files:
62
62
  - lib/vagrant-dotvm.rb
63
63
  - lib/vagrant-dotvm/configinjecter.rb
64
64
  - lib/vagrant-dotvm/configparser.rb
65
+ - lib/vagrant-dotvm/defaults.rb
65
66
  - lib/vagrant-dotvm/dotvm.rb
66
67
  - lib/vagrant-dotvm/plugin.rb
67
68
  - lib/vagrant-dotvm/version.rb
68
69
  - utils/authorize_key.sh
70
+ - utils/setup_route.sh
69
71
  - vagrant-dotvm.gemspec
70
72
  homepage: http://github.com/krzysztof-magosa/vagrant-dotvm
71
73
  licenses: