vagrant-dotvm 0.19.0 → 0.20.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: fb0f0dec3b986a99a6364ff0b138895e37a8384b
4
- data.tar.gz: 1c0fa33c1480785cad75d416c72a0eff5af6e491
3
+ metadata.gz: 545c505f26efb5f6cb1c5942a50ef7527c43d475
4
+ data.tar.gz: 0fb0700ae56254b6c3ce17f00994183687c8e201
5
5
  SHA512:
6
- metadata.gz: 93dc3a6c824124bde2e44fd97f5611b0853f6c0e41295701e92a9d88eec0d7f08f63e2f4ce2cf9e907d5860e6d39a54d1531c74a57cdfc29fb7b10ff18905678
7
- data.tar.gz: 78de418f4f68b06549c4f5669c1eac316bba0204f38f67dc9b81f44a98eb699179b5ec75c795ad3fbd674731d615d3e3c1f3b3d2e9e2f6e228f39742ecf962e6
6
+ metadata.gz: 945f73762362513e6ea469102603b3ef0de865405891173dcafa5b84b3102f1c6bb421b9c91fae0d17deba840f3d7cb56e9b30de90822e6198d59c7cde1d8d8a
7
+ data.tar.gz: 8682d1684a8eeca8023117d7a36bc939588669e9337fca88357c3d71257ebe6d6b9c536d0aeb32edd2e59c43d8adf608d2538ff70326fce34cd19f60a3315c7b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.20.0
2
+ * Now error is displayed when you specify unsupported option
3
+ * Removal of next bunch of default parameters
4
+
1
5
  # 0.19.0
2
6
  * Ability to use inline shell provision
3
7
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # DotVm
2
2
 
3
+ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/krzysztof-magosa/vagrant-dotvm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/krzysztof-magosa/vagrant-dotvm/?branch=master)
4
+
3
5
  ## What is that?
4
6
  DotVm is vagrant plugin for easier maintenance of multi machine configurations.
5
7
  DotVm joins easy syntax of YAML files with flexibility offered by configuration exploded into several small files.
data/lib/vagrant-dotvm.rb CHANGED
@@ -4,6 +4,15 @@ 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'
8
- require 'vagrant-dotvm/configparser'
9
7
  require 'vagrant-dotvm/configinjecter'
8
+
9
+ require 'vagrant-dotvm/config/abstractconfig'
10
+ require 'vagrant-dotvm/config/root'
11
+ require 'vagrant-dotvm/config/machine'
12
+ require 'vagrant-dotvm/config/provision'
13
+ require 'vagrant-dotvm/config/authorizedkey'
14
+ require 'vagrant-dotvm/config/host'
15
+ require 'vagrant-dotvm/config/sharedfolder'
16
+ require 'vagrant-dotvm/config/option'
17
+ require 'vagrant-dotvm/config/route'
18
+ require 'vagrant-dotvm/config/network'
@@ -0,0 +1,47 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class AbstractConfig
5
+ def populate(data)
6
+ data.each do |key, value|
7
+ if respond_to?("populate_#{key}")
8
+ m = method("populate_#{key}")
9
+ elsif respond_to? "#{key}="
10
+ m = method("#{key}=")
11
+ else
12
+ raise "Invalid configuration option: #{key}."
13
+ end
14
+
15
+ m.call(value)
16
+ end
17
+ end
18
+
19
+ def replace_vars(vars, target)
20
+ if target.kind_of?(Array)
21
+ target.each do |item|
22
+ replace_vars(vars, item)
23
+ end
24
+ elsif target.kind_of?(Hash)
25
+ target.each do |name, item|
26
+ replace_vars(vars, item)
27
+ end
28
+ elsif target.kind_of?(String)
29
+ vars.each do |k, v|
30
+ pattern = "%#{k}%"
31
+ target.gsub! pattern, v
32
+ end
33
+ elsif target.kind_of?(AbstractConfig)
34
+ target.replace_vars!(vars)
35
+ end
36
+ end
37
+
38
+ def replace_vars!(vars)
39
+ instance_variables.each do |var_name|
40
+ var = instance_variable_get(var_name)
41
+ replace_vars(vars, var)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class AuthorizedKey < AbstractConfig
5
+ attr_accessor :type
6
+ attr_accessor :path
7
+ attr_accessor :key
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Host < AbstractConfig
5
+ attr_accessor :ip
6
+ attr_accessor :host
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,124 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Machine < AbstractConfig
5
+ attr_accessor :nick
6
+ attr_accessor :name
7
+ attr_accessor :box
8
+ attr_accessor :memory
9
+ attr_accessor :cpus
10
+ attr_accessor :cpucap
11
+ attr_accessor :primary
12
+ attr_accessor :natnet
13
+ attr_accessor :networks
14
+ attr_accessor :routes
15
+ attr_accessor :provision
16
+ attr_accessor :groups
17
+ attr_accessor :authorized_keys
18
+ attr_accessor :boot_timeout
19
+ attr_accessor :box_check_update
20
+ attr_accessor :box_version
21
+ attr_accessor :graceful_halt_timeout
22
+ attr_accessor :post_up_message
23
+ attr_accessor :autostart
24
+ attr_accessor :hosts
25
+ attr_accessor :options
26
+ attr_accessor :shared_folders
27
+
28
+ def initialize()
29
+ @primary = false
30
+ @networks = []
31
+ @routes = []
32
+ @provision = []
33
+ @groups = []
34
+ @authorized_keys = []
35
+ @hosts = []
36
+ @options = {
37
+ :virtualbox => [],
38
+ }
39
+ @shared_folders = []
40
+
41
+ populate_shared_folders(
42
+ [
43
+ {
44
+ "host" => "%project.host%",
45
+ "guest" => "%project.guest%",
46
+ "disabled" => false,
47
+ "create" => false,
48
+ "type" => nil,
49
+ }
50
+ ]
51
+ )
52
+ end
53
+
54
+ def populate_networks(data)
55
+ data.to_a.each do |conf|
56
+ item = Network.new
57
+ item.populate conf
58
+ @networks << item
59
+ end
60
+ end
61
+
62
+ def populate_routes(data)
63
+ data.to_a.each do |conf|
64
+ item = Route.new
65
+ item.populate conf
66
+ @routes << item
67
+ end
68
+ end
69
+
70
+ def populate_provision(data)
71
+ data.to_a.each do |conf|
72
+ item = Provision.new
73
+ item.populate conf
74
+ @provision << item
75
+ end
76
+ end
77
+
78
+ def populate_groups(data)
79
+ data.to_a.each do |item|
80
+ @groups << item
81
+ end
82
+ end
83
+
84
+ def populate_authorized_keys(data)
85
+ data.to_a.each do |conf|
86
+ item = AuthorizedKey.new
87
+ item.populate conf
88
+ @authorized_keys << item
89
+ end
90
+ end
91
+
92
+ def populate_hosts(data)
93
+ data.to_a.each do |conf|
94
+ item = Host.new
95
+ item.populate conf
96
+ @hosts << item
97
+ end
98
+ end
99
+
100
+ def populate_options(data)
101
+ data.to_h.each do |key, confs|
102
+ key = key.to_sym
103
+ raise "Invalid options category: #{key}." unless @options.has_key?(key)
104
+
105
+ confs.to_a.each do |conf|
106
+ item = Option.new
107
+ item.populate conf
108
+ @options[key] << item
109
+ end
110
+ end
111
+ end
112
+
113
+ def populate_shared_folders(data)
114
+ data.to_a.each do |conf|
115
+ item = SharedFolder.new
116
+ item.populate conf
117
+ @shared_folders << item
118
+ end
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,38 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Network < AbstractConfig
5
+ attr_reader :net
6
+ attr_accessor :type
7
+ attr_accessor :ip
8
+ attr_accessor :mask # netmask
9
+ attr_accessor :interface
10
+ attr_accessor :guest
11
+ attr_accessor :host
12
+ attr_accessor :protocol
13
+ attr_accessor :bridge
14
+
15
+ def initialize()
16
+ @net = :private_network
17
+ end
18
+
19
+ def net=(value)
20
+ nets = {
21
+ "private_network" => :private_network,
22
+ "private" => :private_network,
23
+ "public_network" => :public_network,
24
+ "public" => :public_network,
25
+ "forwarded_port" => :forwarded_port,
26
+ "port" => :forwarded_port,
27
+ }
28
+
29
+ @net = nets[value]
30
+ end
31
+
32
+ def netmask=(value)
33
+ @mask = value
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Option < AbstractConfig
5
+ attr_accessor :name
6
+ attr_accessor :value
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Provision < AbstractConfig
5
+ attr_accessor :type
6
+ attr_accessor :source
7
+ attr_accessor :destination
8
+ attr_accessor :inline
9
+ attr_accessor :path
10
+ attr_accessor :args
11
+ attr_accessor :module_path
12
+ attr_accessor :manifests_path
13
+ attr_accessor :manifest_file
14
+ attr_accessor :privileged
15
+ attr_accessor :run
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Root < AbstractConfig
5
+ attr_reader :machines
6
+
7
+ def initialize()
8
+ @machines = []
9
+ end
10
+
11
+ def populate_machines(data)
12
+ data.to_a.each do |item|
13
+ machine = Machine.new
14
+ machine.populate item
15
+ @machines << machine
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class Route < AbstractConfig
5
+ attr_accessor :destination
6
+ attr_accessor :gateway
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Dotvm
3
+ module Config
4
+ class SharedFolder < AbstractConfig
5
+ attr_accessor :host
6
+ attr_accessor :guest
7
+ attr_accessor :disabled
8
+ attr_accessor :create
9
+ attr_accessor :type
10
+
11
+ def initialize()
12
+ @disabled = false
13
+ @create = false
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -7,97 +7,87 @@ module VagrantPlugins
7
7
  # General settings
8
8
  vc.ssh.forward_x11 = true
9
9
 
10
- config[:machines].each do |machine_cfg|
11
- vc.vm.define machine_cfg[:nick],
12
- primary: machine_cfg[:primary],
13
- autostart: machine_cfg[:autostart] do |machine|
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]
19
- machine.vm.graceful_halt_timeout = machine_cfg[:graceful_halt_timeout]
20
- machine.vm.post_up_message = machine_cfg[:post_up_message]
10
+ config.machines.each do |machine_cfg|
11
+ vc.vm.define machine_cfg.nick,
12
+ primary: machine_cfg.primary,
13
+ autostart: machine_cfg.autostart do |machine|
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
19
+ machine.vm.graceful_halt_timeout = machine_cfg.graceful_halt_timeout
20
+ machine.vm.post_up_message = machine_cfg.post_up_message
21
21
 
22
22
  machine.vm.provider "virtualbox" do |vb|
23
- vb.customize ["modifyvm", :id, "--memory", machine_cfg[:memory]] unless machine_cfg[:memory].nil?
24
- vb.customize ["modifyvm", :id, "--cpus", machine_cfg[:cpus]] unless machine_cfg[:cpus].nil?
25
- vb.customize ["modifyvm", :id, "--cpuexecutioncap", machine_cfg[:cpucap]] unless machine_cfg[:cpucap].nil?
26
- vb.customize ["modifyvm", :id, "--natnet1", machine_cfg[:natnet]] unless machine_cfg[:natnet].nil?
23
+ vb.customize ["modifyvm", :id, "--memory", machine_cfg.memory] unless machine_cfg.memory.nil?
24
+ vb.customize ["modifyvm", :id, "--cpus", machine_cfg.cpus] unless machine_cfg.cpus.nil?
25
+ vb.customize ["modifyvm", :id, "--cpuexecutioncap", machine_cfg.cpucap] unless machine_cfg.cpucap.nil?
26
+ vb.customize ["modifyvm", :id, "--natnet1", machine_cfg.natnet] unless machine_cfg.natnet.nil?
27
27
 
28
- machine_cfg[:options][:virtualbox].each do |option|
29
- vb.customize ["modifyvm", :id, option[:name], option[:value]]
28
+ machine_cfg.options[:virtualbox].each do |option|
29
+ vb.customize ["modifyvm", :id, option.name, option.value]
30
30
  end
31
31
  end
32
32
 
33
- machine_cfg[:networks].each do |net|
34
- if net[:net] == :private_network
35
- machine.vm.network net[:net],
36
- type: net[:type],
37
- ip: net[:ip],
38
- netmask: net[:mask],
39
- virtualbox__intnet: net[:interface]
40
- elsif net[:net] == :public_network
41
- machine.vm.network net[:net],
42
- type: net[:type],
43
- ip: net[:ip],
44
- netmask: net[:mask],
45
- bridge: net[:bridge]
46
- elsif net[:net] == :forwarded_port
47
- machine.vm.network net[:net],
48
- guest: net[:guest],
49
- host: net[:host],
50
- protocol: net[:protocol]
51
- end
33
+ machine_cfg.networks.each do |net|
34
+ hash = {}
35
+ hash[:type] = net.type unless net.type.nil?
36
+ hash[:ip] = net.ip unless net.ip.nil?
37
+ hash[:netmask] = net.mask unless net.mask.nil?
38
+ hash[:virtualbox__intnet] = net.interface unless net.interface.nil?
39
+ hash[:guest] = net.guest unless net.guest.nil?
40
+ hash[:host] = net.host unless net.host.nil?
41
+ hash[:protocol] = net.protocol unless net.protocol.nil?
42
+ hash[:bridge] = net.bridge unless net.bridge.nil?
43
+
44
+ machine.vm.network net.net, **hash
52
45
  end
53
46
 
54
- machine_cfg[:routes].each do |route|
47
+ machine_cfg.routes.each do |route|
55
48
  machine.vm.provision "shell", run: "always" do |s|
56
49
  s.path = File.dirname(__FILE__) + "/../../utils/setup_route.sh"
57
- s.args = [route[:destination], route[:gateway]]
50
+ s.args = [route.destination, route.gateway]
58
51
  s.privileged = true
59
52
  end
60
53
  end
61
54
 
62
- machine_cfg[:hosts].each do |host|
55
+ machine_cfg.hosts.each do |host|
63
56
  machine.vm.provision "shell", run: "always" do |s|
64
57
  s.path = File.dirname(__FILE__) + "/../../utils/add_host.sh"
65
- s.args = [host[:ip], host[:host]]
58
+ s.args = [host.ip, host.host]
66
59
  s.privileged = true
67
60
  end
68
61
  end
69
62
 
70
- machine_cfg[:provision].each do |provision|
71
- machine.vm.provision provision[:type], run: provision[:run] do |p|
72
- if provision[:type] == "shell"
73
- p.path = provision[:path] unless provision[:path].nil?
74
- p.inline = provision[:inline] unless provision[:inline].nil?
75
- p.args = provision[:args]
76
- p.privileged = provision[:privileged]
77
- elsif provision[:type] == "file"
78
- p.source = provision[:source]
79
- p.destination = provision[:destination]
80
- elsif provision[:type] == "puppet"
81
- p.module_path = provision[:module_path]
82
- p.manifest_file = provision[:manifest_file]
83
- p.manifests_path = provision[:manifests_path]
84
- end
63
+ machine_cfg.provision.each do |provision|
64
+ machine.vm.provision provision.type, run: provision.run do |p|
65
+ p.path = provision.path unless provision.path.nil?
66
+ p.inline = provision.inline unless provision.inline.nil?
67
+ p.args = provision.args unless provision.args.nil?
68
+ p.privileged = provision.privileged unless provision.privileged.nil?
69
+ p.source = provision.source unless provision.source.nil?
70
+ p.destination = provision.destination unless provision.destination.nil?
71
+ p.module_path = provision.module_path unless provision.module_path.nil?
72
+ p.manifest_file = provision.manifest_file unless provision.manifest_file.nil?
73
+ p.manifests_path = provision.manifests_path unless provision.manifests_path.nil?
85
74
  end
86
75
  end
87
76
 
88
- machine_cfg[:folders].each do |folder|
89
- machine.vm.synced_folder folder[:host],
90
- folder[:guest],
91
- disabled: folder[:disabled],
92
- create: folder[:create],
93
- type: folder[:type]
77
+ machine_cfg.shared_folders.each do |folder|
78
+ hash = {}
79
+ hash[:disabled] = folder.disabled unless folder.disabled.nil?
80
+ hash[:create] = folder.create unless folder.create.nil?
81
+ hash[:type] = folder.type unless folder.type.nil?
82
+
83
+ machine.vm.synced_folder folder.host, folder.guest, **hash
94
84
  end
95
85
 
96
- machine_cfg[:authorized_keys].each do |key|
97
- if key[:type] == "file"
98
- pubkey = File.readlines(File.expand_path(key[:path])).first.strip
99
- elsif key[:type] == "static"
100
- pubkey = key[:key]
86
+ machine_cfg.authorized_keys.each do |key|
87
+ if key.type == "file"
88
+ pubkey = File.readlines(File.expand_path(key.path)).first.strip
89
+ elsif key.type == "static"
90
+ pubkey = key.key
101
91
  end
102
92
 
103
93
  machine.vm.provision "shell" do |s|
@@ -110,9 +100,9 @@ module VagrantPlugins
110
100
  if Vagrant.has_plugin?("vagrant-group")
111
101
  vc.group.groups = {} unless vc.group.groups.kind_of?(Hash)
112
102
 
113
- machine_cfg[:groups].each do |group|
103
+ machine_cfg.groups.each do |group|
114
104
  vc.group.groups[group] = [] unless vc.group.groups.has_key?(group)
115
- vc.group.groups[group] << machine_cfg[:nick]
105
+ vc.group.groups[group] << machine_cfg.nick
116
106
  end
117
107
  end
118
108
  end
@@ -26,8 +26,16 @@ module VagrantPlugins
26
26
  vars['env.' + name] = value
27
27
  end
28
28
 
29
- parser = ConfigParser.new vars
30
- configs << parser.parse(yaml)
29
+ begin
30
+ conf = Config::Root.new
31
+ conf.populate yaml
32
+ conf.replace_vars! vars
33
+ rescue Exception => e
34
+ file = fname[(@path.length+"/projects/".length)..-1]
35
+ raise Vagrant::Errors::VagrantError.new, "DotVM: #{file}: #{e.message}"
36
+ end
37
+
38
+ configs << conf
31
39
  end
32
40
 
33
41
  return configs
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Dotvm
3
- VERSION = "0.19.0"
3
+ VERSION = "0.20.0"
4
4
  end
5
5
  end
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.19.0
4
+ version: 0.20.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-14 00:00:00.000000000 Z
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,9 +60,17 @@ files:
60
60
  - examples/config/projects/playground/main.yaml
61
61
  - examples/config/projects/playground/modules/.gitkeep
62
62
  - lib/vagrant-dotvm.rb
63
+ - lib/vagrant-dotvm/config/abstractconfig.rb
64
+ - lib/vagrant-dotvm/config/authorizedkey.rb
65
+ - lib/vagrant-dotvm/config/host.rb
66
+ - lib/vagrant-dotvm/config/machine.rb
67
+ - lib/vagrant-dotvm/config/network.rb
68
+ - lib/vagrant-dotvm/config/option.rb
69
+ - lib/vagrant-dotvm/config/provision.rb
70
+ - lib/vagrant-dotvm/config/root.rb
71
+ - lib/vagrant-dotvm/config/route.rb
72
+ - lib/vagrant-dotvm/config/sharedfolder.rb
63
73
  - lib/vagrant-dotvm/configinjecter.rb
64
- - lib/vagrant-dotvm/configparser.rb
65
- - lib/vagrant-dotvm/defaults.rb
66
74
  - lib/vagrant-dotvm/dotvm.rb
67
75
  - lib/vagrant-dotvm/plugin.rb
68
76
  - lib/vagrant-dotvm/version.rb
@@ -1,216 +0,0 @@
1
- module VagrantPlugins
2
- module Dotvm
3
- class ConfigParser
4
-
5
- def initialize(vars = {})
6
- @vars = vars
7
- end
8
-
9
- private
10
- def replace_vars(value)
11
- if value.kind_of?(Hash)
12
- result = {}
13
- value.each do |key, val|
14
- result[key] = replace_vars(val)
15
- end
16
- elsif value.kind_of?(Array)
17
- result = value.map do |val|
18
- replace_vars(val)
19
- end
20
- elsif value.kind_of?(String)
21
- result = value.dup
22
-
23
- @vars.each do |k, v|
24
- pattern = "%#{k}%"
25
- result.gsub! pattern, v
26
- end
27
- elsif !value.respond_to?(:duplicable) or !value.duplicable?
28
- result = value
29
- else
30
- result = value.dup
31
- end
32
-
33
- return result
34
- end
35
-
36
- private
37
- def parse_machine(machine)
38
- {
39
- :nick => machine["nick"],
40
- :name => machine["name"],
41
- :box => machine["box"],
42
- :memory => machine["memory"],
43
- :cpus => machine["cpus"],
44
- :cpucap => machine["cpucap"],
45
- :primary => coalesce(machine["primary"], false),
46
- :natnet => machine["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
- :hosts => [],
59
- :folders => [
60
- {
61
- :host => "%project.host%",
62
- :guest => "%project.guest%",
63
- :disabled => false,
64
- :create => false,
65
- :type => nil,
66
- }
67
- ],
68
- :options => {
69
- :virtualbox => [],
70
- },
71
- }
72
- end
73
-
74
- private
75
- def parse_net(net)
76
- nets = {
77
- "private_network" => :private_network,
78
- "private" => :private_network,
79
- "public_network" => :public_network,
80
- "public" => :public_network,
81
- "forwarded_port" => :forwarded_port,
82
- "port" => :forwarded_port,
83
- }
84
-
85
- {
86
- :net => nets.has_key?(net["net"]) ? nets[net["net"]] : Defaults::NET,
87
- :type => coalesce(net["type"], Defaults::NET_TYPE),
88
- :ip => net["ip"],
89
- :mask => coalesce(net["mask"], net["netmask"], Defaults::NETMASK),
90
- :interface => net["interface"],
91
- :guest => net["guest"],
92
- :host => net["host"],
93
- :protocol => coalesce(net["protocol"], Defaults::PROTOCOL),
94
- :bridge => net["bridge"],
95
- }
96
- end
97
-
98
- private
99
- def parse_route(route)
100
- {
101
- :destination => route["destination"],
102
- :gateway => route["gateway"],
103
- }
104
- end
105
-
106
- private
107
- def parse_provision(prv)
108
- {
109
- :type => prv["type"],
110
- :source => prv["source"],
111
- :destination => prv["destination"],
112
- :inline => prv["inline"],
113
- :path => prv["path"],
114
- :args => prv["args"],
115
- :module_path => prv["module_path"],
116
- :manifests_path => prv["manifests_path"],
117
- :manifest_file => prv["manifest_file"],
118
- :privileged => prv["privileged"].nil? ? true : prv["privileged"],
119
- :run => prv["run"],
120
- }
121
- end
122
-
123
- private
124
- def parse_folder(folder)
125
- {
126
- :host => folder["host"],
127
- :guest => folder["guest"],
128
- :disabled => coalesce(folder["disabled"], false),
129
- :create => coalesce(folder["create"], false),
130
- :type => folder["type"],
131
- }
132
- end
133
-
134
- private
135
- def parse_authorized_key(key)
136
- {
137
- :type => key["type"],
138
- :path => key["path"],
139
- :key => key["key"],
140
- }
141
- end
142
-
143
- private
144
- def parse_option(option)
145
- {
146
- :name => option["name"],
147
- :value => option["value"],
148
- }
149
- end
150
-
151
- private
152
- def parse_host(host)
153
- {
154
- :ip => host["ip"],
155
- :host => host["host"],
156
- }
157
- end
158
-
159
- public
160
- def parse(yaml)
161
- config = {
162
- :machines => []
163
- }
164
-
165
- yaml["machines"].each do |machine|
166
- item = parse_machine(machine)
167
-
168
- machine["networks"].to_a.each do |net|
169
- item[:networks] << parse_net(net)
170
- end
171
-
172
- machine["routes"].to_a.each do |route|
173
- item[:routes] << parse_route(route)
174
- end
175
-
176
- machine["provision"].to_a.each do |prv|
177
- item[:provision] << parse_provision(prv)
178
- end
179
-
180
- machine["shared_folders"].to_a.each do |folder|
181
- item[:folders] << parse_folder(folder)
182
- end
183
-
184
- machine["groups"].to_a.each do |group|
185
- item[:groups] << group
186
- end
187
-
188
- machine["authorized_keys"].to_a.each do |key|
189
- item[:authorized_keys] << parse_authorized_key(key)
190
- end
191
-
192
- machine["options"].to_h["virtualbox"].to_a.each do |option|
193
- item[:options][:virtualbox] << parse_option(option)
194
- end
195
-
196
- machine["hosts"].to_a.each do |host|
197
- item[:hosts] << parse_host(host)
198
- end
199
-
200
- config[:machines] << item
201
- end
202
-
203
- replace_vars(config)
204
- end
205
-
206
- private
207
- def coalesce(*args)
208
- args.each do |val|
209
- next if val.nil?
210
- return val
211
- end
212
- end
213
-
214
- end
215
- end
216
- end
@@ -1,14 +0,0 @@
1
- module VagrantPlugins
2
- module Dotvm
3
- class Defaults
4
- NET = :private_network
5
- NET_TYPE = "static"
6
- NETMASK = "255.255.255.0"
7
- PROTOCOL = "tcp"
8
- BOOT_TIMEOUT = 300
9
- BOX_CHECK_UPDATE = true
10
- BOX_VERSION = ">= 0"
11
- GRACEFUL_HALT_TIMEOUT = 60
12
- end # Defaults
13
- end # Dotvm
14
- end # VagrantPlugins