vagrant-compose 0.2.3 → 0.2.4

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: 829887cd4923b701ab113a461eee004c59f5e53a
4
- data.tar.gz: 150222776421af2f4acc3ca9b5177f9cf327e4fd
3
+ metadata.gz: f830b936e191533e4b7af81b6a8a28aff5895b65
4
+ data.tar.gz: 340bfc23e34b5538bf2efd653042e851594bb2f1
5
5
  SHA512:
6
- metadata.gz: 3f30bf0ae52906e0d09a5cf2bf68a5a9a067c68614a7857fe4562ee805962242ba46dabc7bf96b7540529507e27e751007333fb70e3c79a2294cc479f010e14a
7
- data.tar.gz: b868272274ee606bf70138cc7b94d6e66d6278846ef3ad2abe8def377875896a0d8fcb1d19d6147701d878113ce74aa6a526622734ab4284788784d3e747fb4d
6
+ metadata.gz: d898460561c00f26860490b0ef1f1f60bc0244cef3b049bc3faffcbc69b705d82b2a291c21c1955ace7850ca505a44e92bb5d6160490921cbc348f77d18d524d
7
+ data.tar.gz: 6f28b559521b5ee1a340b2dc4e09c7d6cc03aef6c6760c0332437f437c837d700fe1400f522c3c51a444eb5e0e5eb19c7cfbcd54b80e6b197d2430499ae06eae
data/CHANGELOG.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  * Initial release.
4
4
 
5
+
5
6
  # 0.2.2 (December 31, 2015)
6
7
 
7
- breaking changes!
8
+ breaking changes!
8
9
  * nodes instances number defined into node method (instances attributes removed)
9
10
  * cluster.nodes return only nodes (before nodes with index were returned)
10
11
 
@@ -12,6 +13,8 @@ other changes:
12
13
  * Improved documentation.
13
14
  * cluster domain now is optional
14
15
  * nodes code block now is optional
16
+ * improved detection of multimachine_filter
17
+ * minor fixes
15
18
 
16
19
  # 0.2.3 (April 2, 2016)
17
20
 
@@ -20,3 +23,11 @@ other changes:
20
23
  other changes:
21
24
  * Documented cluster.debug feature
22
25
  * Improved code inline documentation
26
+
27
+ # 0.2.4 (June 26, 2016)
28
+
29
+ * issues #3 Now vagrant up and vagrant provision support also a list of machine name / regular expressions.
30
+ * pr #3 Support changing ansible_playbook_path & clean up path management
31
+
32
+ NB. breaking change
33
+ ansible_group_vars_path and ansible_host_vars_path are not supported anymore
data/README.md CHANGED
@@ -85,7 +85,9 @@ See following chapters for more details.
85
85
 
86
86
  ## Configuring the cluster
87
87
 
88
- There are several options to customise the cluster definition.
88
+ Each cluster can be named passing a value to `cluster.compose` method, and the default behaviour is that name of vagrant boxes and hostnames will be prefixed by such name; if cluster name will be set to nil or "", vagrant boxes and hostnames will be composed without prefix.
89
+
90
+ Apart for cluster name, there are several options to customize the cluster definition.
89
91
 
90
92
  ### Defining cluster attributes
91
93
 
@@ -96,7 +98,7 @@ You can set set cluster attributes in the block of code that is passed as a seco
96
98
  ``` ruby
97
99
  config.cluster.compose('test') do |c|
98
100
  c.box = "centos/7"
99
- ...
101
+ ...
100
102
  end
101
103
  ```
102
104
 
@@ -104,7 +106,7 @@ Following cluster attributes are available:
104
106
 
105
107
  - **box**, [String], default = 'ubuntu/trusty64'
106
108
 
107
- Sets the base box for nodes, a.k.a the image that will be used to spin up the machine; please note that the base box can be customised also for each set of nodes (see Defining set of nodes).
109
+ Sets the base box for nodes, a.k.a the image that will be used to spin up the machine; please note that the base box can be customized also for each set of nodes (see Defining set of nodes).
108
110
 
109
111
 
110
112
  - **domain**, [String], default = 'vagrant'
@@ -125,12 +127,12 @@ Set of nodes can be defined in the block of code that is passed as a second para
125
127
  ``` ruby
126
128
  config.cluster.compose('test') do |c|
127
129
  ...
128
- c.nodes(3, 'zookeeper')
129
- ...
130
+ c.nodes(3, 'consul-agents')
131
+ ...
130
132
  end
131
133
  ```
132
134
 
133
- The first parameter of the `nodes` method is the number of nodes in the set, while the second parameter is the name of the set; `nodes` accepts an optional third parameter, allowing to define a block of code where it is possible to customise several attributes of the set of nodes itself:
135
+ The first parameter of the `nodes` method is the number of nodes in the set, while the second parameter is the name of the set; `nodes` accepts an optional third parameter, allowing to define a block of code where it is possible to customize several attributes of the set of nodes itself:
134
136
 
135
137
  ``` ruby
136
138
  config.cluster.compose('test') do |c|
@@ -138,7 +140,7 @@ config.cluster.compose('test') do |c|
138
140
  c.nodes(3, 'zookeeper') do |n|
139
141
  n.box = "centos/7"
140
142
  end
141
- ...
143
+ ...
142
144
  end
143
145
  ```
144
146
 
@@ -159,8 +161,6 @@ Please note that all the available attributes can be set to:
159
161
  return "#{group_name}#{node_index + 1}"
160
162
  }
161
163
  ```
162
-
163
-
164
164
 
165
165
  Following set of nodes attributes are available:
166
166
 
@@ -171,15 +171,13 @@ Following set of nodes attributes are available:
171
171
  - **boxname**, [String|String_Generator], default = `"#{group_name}#{node_index + 1}"`
172
172
 
173
173
  Sets the box name (a.k.a. the name of the machine in VirtualBox/VMware) for each node in this set.
174
-
175
- Note: when generating nodes, the resulting boxname will be automatically prefixed by `"#{cluster_name}-"`.
174
+ Note: when generating nodes, if cluster name not equals to nil or empty string the resulting boxname will be automatically prefixed by `"#{cluster_name}-"` if cluster name not equals to nil or empty string.
176
175
 
177
176
  - **hostname**, [String|String_Generator], default = `"#{group_name}#{node_index + 1}"`
178
177
 
179
178
  Sets the hostname for each node in this set.
180
179
 
181
- Note: when generating nodes, the resulting hostname will be automatically prefixed by `"#{cluster_name}-"`; additionally the **fqdn** attribute will be computed by concatenating `".#{cluster.domain}"`, if defined (if `domain` is not defined, fqdn will be the same of hostname).
182
-
180
+ Note: when generating nodes, if cluster name not equals to nil or empty string the resulting hostname will be automatically prefixed by `"#{cluster_name}-"`; additionally the **fqdn** attribute will be computed by concatenating `".#{cluster.domain}"`, if defined (if `domain` is not defined, fqdn will be the same of hostname).
183
181
 
184
182
  - **aliases**, [Array(String)|Array(String)_Generator], default = `[]`
185
183
 
@@ -187,25 +185,21 @@ Following set of nodes attributes are available:
187
185
 
188
186
  Note: when generating nodes, aliases will be automatically concatenated into a string, comma separated.
189
187
 
190
-
191
188
  - **ip**, [String|String_Generator], default = `"172.31.#{group_index}.#{100 + node_index + 1}"`
192
189
 
193
190
  Sets the ip for for each node in this set.
194
191
 
195
-
196
192
  - **cpus**, [Integer|Integer_Generator], default = `1`
197
193
 
198
194
  Sets the number of cpus for each node in this set.
199
195
 
200
-
201
196
  - **memory**, [Integer|Integer_Generator], default = `256` (MB)
202
197
 
203
198
  Sets the memory allocated for each node in this set.
204
199
 
205
-
206
200
  - **attributes**, [Hash(String, obj)|Hash(String, obj)_Generator], default = `{}`
207
201
 
208
- Allows to provide customisable additional attributes for each node in this set.
202
+ Allows to provide custom additional attributes for each node in this set.
209
203
 
210
204
  > Please note that some attribute, like boxname, hostname, ip, *must* be different for each node in the set (and in the cluster).
211
205
  >
@@ -221,29 +215,34 @@ The resulting list of nodes is stored in the `config.cluster.nodes` variable; ea
221
215
  - **boxname**
222
216
  - **hostname**
223
217
  - **fqdn**
224
-
225
-
226
218
  - **aliases**
227
-
228
-
229
219
  - **ip**
230
-
231
-
232
220
  - **cpus**
233
-
234
-
235
221
  - **memory**
236
-
237
-
238
222
  - **attributes**
239
223
 
240
-
241
-
242
224
  Two additional attributes will be automatically set for each node:
243
225
 
244
226
  - **index**, [integer (zero based)], uniquely assigned to each node in the cluster
245
227
  - **group_index**, [integer (zero based)], uniquely assigned to each node in a set of nodes
246
228
 
229
+ ## Checking cluster configuration
230
+
231
+ It is possible to check the resulting list of nodes by using the `compose.debug` command:
232
+
233
+ ``` ruby
234
+ Vagrant.configure(2) do |config|
235
+ #cluster definition
236
+ config.cluster.compose('test') do |c|
237
+ ...
238
+ end
239
+
240
+ config.cluster.debug
241
+ end
242
+ ```
243
+
244
+ Main information about nodes will be printed into the sequence of vagrant messages.
245
+
247
246
  ## Creating nodes
248
247
 
249
248
  Given the list of nodes stored in the `config.cluster.nodes` variable, it is possible to create a multi-machine environment by iterating over the list:
@@ -380,12 +379,9 @@ Ansible host vars will be stored into yaml files saved into `{cluster.ansible_pl
380
379
 
381
380
  Group vars and host var generation by design can operate only with the set of information that comes with a groups of nodes or a single node.
382
381
 
383
- However, sometimes, it is necessary to share some information across group of nodes, like for instance providing information about zookeeper nodes to mesos master nodes.
384
-
382
+ However, sometimes, it is necessary to share some information across group of nodes.
385
383
  This can be achieved by setting one or more context_vars generator for each ansible_groups.
386
384
 
387
- > Context_vars generator are always executed before group_vars and host_vars generators; the resulting context, is given in input to group_vars and host_vars generators.
388
-
389
385
  For instance, when building a [Consul](https://consul.io/) cluster, all the `consul-agent` nodes should be configured with the ip - the list of ip - to be used when joining the cluster; such list can be generated from the list of nodes in the `consul-server` set of nodes, and stored in a context_vars:
390
386
 
391
387
  ``` ruby
@@ -398,6 +394,8 @@ config.cluster.compose('test') do |c|
398
394
  end
399
395
  ```
400
396
 
397
+ > Context_vars generator are always executed before group_vars and host_vars generators; the resulting context, is given in input to group_vars and host_vars generators.
398
+
401
399
  Then, you can use the above context var when generating group_vars for nodes in the `consul-agent` group.
402
400
 
403
401
  ``` ruby
@@ -436,3 +434,9 @@ end
436
434
 
437
435
  ```
438
436
 
437
+ # Additional notes
438
+ Vagrant compose will play nicely with all vagrant commands.
439
+
440
+ For instance, When using vagrant tageting a single machine, like f.i. `vagrant up mesos-master1`, the `cluster.ansible_groups` variable will include only the given machine.
441
+
442
+ Happy vagrant-compose!
data/lib/locales/en.yml CHANGED
@@ -35,3 +35,7 @@ en:
35
35
  %{message}
36
36
 
37
37
  Ansible host var expression expected to be a Hash literal or a code block returning an Hash literal (see documentation).
38
+
39
+ pycompose_error: |-
40
+ Error generating:
41
+ %{message}
@@ -4,7 +4,7 @@ require_relative "util/cluster"
4
4
 
5
5
  module VagrantPlugins
6
6
  module Compose
7
-
7
+
8
8
  # Vagrant compose plugin definition class.
9
9
  # This plugins allows easy configuration of a data structure that can be used as a recipe
10
10
  # for setting up and provisioning a vagrant cluster composed by several machines with different
@@ -17,33 +17,48 @@ module VagrantPlugins
17
17
  # After executing compose, it returns the ansible_groups configuration for provisioning nodes in the cluster.
18
18
  attr_reader :ansible_groups
19
19
 
20
- def initialize
21
- @nodes = {}
22
- @ansible_groups = {}
23
- end
24
-
25
- # Implements cluster creation, through the execution of the give code.
26
- def compose (name, &block)
27
- # create the cluster (the data structure representing the cluster)
28
- @cluster = Cluster.new(name)
29
- begin
30
- # executes the cluster configuration code
31
- block.call(@cluster)
32
- rescue Exception => e
33
- raise VagrantPlugins::Compose::Errors::ClusterInitializeError, :message => e.message, :cluster_name => name
34
- end
35
- # tranform cluster configuration into a list of nodes/ansible groups to be used for
36
- @nodes, @ansible_groups = @cluster.compose
37
- end
38
-
39
- # Implements a utility method that allows to check the list of nodes generated by compose.
40
- def debug
41
- puts "==> cluster #{@cluster.name} with #{nodes.size} nodes"
42
- @nodes.each do |node|
43
- puts " #{node.boxname} accessible as #{node.fqdn} #{node.aliases} #{node.ip} => [#{node.box}, #{node.cpus} cpus, #{node.memory} memory]"
44
- end
45
- puts " ansible_groups filtered by #{@cluster.multimachine_filter}" if not @cluster.multimachine_filter.empty?
46
- end
20
+ def initialize
21
+ @nodes = {}
22
+ @ansible_groups = {}
23
+ end
24
+
25
+ # Implements cluster creation, through the execution of the give code.
26
+ def compose (name, &block)
27
+ # create the cluster (the data structure representing the cluster)
28
+ @cluster = Cluster.new(name)
29
+ begin
30
+ # executes the cluster configuration code
31
+ block.call(@cluster)
32
+ rescue Exception => e
33
+ raise VagrantPlugins::Compose::Errors::ClusterInitializeError, :message => e.message, :cluster_name => name
34
+ end
35
+ # tranform cluster configuration into a list of nodes/ansible groups to be used for
36
+ @nodes, @ansible_groups = @cluster.compose
37
+ end
38
+
39
+ # Implements cluster creation, through the execution of the give code.
40
+ def from (file)
41
+ puts "from #{file}"
42
+ begin
43
+ a = `xxxxx`
44
+ puts "get #{a}"
45
+ rescue Exception => e
46
+ raise VagrantPlugins::Compose::Errors::PyComposeError, :message => e.message
47
+ end
48
+
49
+
50
+ # tranform cluster configuration into a list of nodes/ansible groups to be used for
51
+ @nodes, @ansible_groups = @cluster.compose
52
+ end
53
+
54
+ # Implements a utility method that allows to check the list of nodes generated by compose.
55
+ def debug
56
+ puts "==> cluster #{@cluster.name} with #{nodes.size} nodes"
57
+ @nodes.each do |node|
58
+ puts " #{node.boxname} accessible as #{node.fqdn} #{node.aliases} #{node.ip} => [#{node.box}, #{node.cpus} cpus, #{node.memory} memory]"
59
+ end
60
+ puts " ansible_groups filtered by #{@cluster.multimachine_filter}" if not @cluster.multimachine_filter.empty?
61
+ end
47
62
  end
48
63
  end
49
- end
64
+ end
@@ -29,6 +29,10 @@ module VagrantPlugins
29
29
  class HostVarExpressionError < VagrantComposeError
30
30
  error_key(:host_var_expression_error)
31
31
  end
32
+
33
+ class PyComposeError < VagrantComposeError
34
+ error_key(:pycompose_error)
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -5,35 +5,33 @@ module VagrantPlugins
5
5
  module Compose
6
6
 
7
7
  # This class defines a cluster, thas is a set of group of nodes, where nodes in each group has similar characteristics.
8
- # Basically, a cluster is a data structure that can be used as a recipe for setting up and provisioning a
8
+ # Basically, a cluster is a data structure that can be used as a recipe for setting up and provisioning a
9
9
  # vagrant cluster composed by several machines with different roles.
10
10
  class Cluster
11
11
 
12
12
  # The name of the cluster
13
13
  attr_reader :name
14
14
 
15
- # The default vagrant base box to be used for creating vagrant machines in this cluster.
15
+ # The default vagrant base box to be used for creating vagrant machines in this cluster.
16
16
  # This setting can be changed at group/node level
17
17
  attr_accessor :box
18
-
18
+
19
19
  # The network domain to wich the cluster belongs (used for computing nodes fqdn)
20
20
  attr_accessor :domain
21
-
21
+
22
22
 
23
23
  # The root path for ansible playbook; it is used as a base path for computing ansible_group_vars and ansible_host_vars
24
24
  # It defaults to current directory/provisioning
25
25
  attr_accessor :ansible_playbook_path
26
-
27
- # The path where ansible group vars files are stores.
28
- # It default to ansible_playbook_path/group_vars
29
- attr_accessor :ansible_group_vars
30
-
31
- # The path where ansible group vars files are stores.
32
- # It default to ansible_playbook_path/host_vars
33
- attr_accessor :ansible_host_vars
26
+
27
+ # A dictionary, allowing to setup ansible_group_vars generators foreach node_group
28
+ attr_reader :ansible_group_vars
29
+
30
+ # A dictionary, allowing to setup ansible_host_vars generators foreach node_group
31
+ attr_reader :ansible_host_vars
34
32
 
35
33
  # A dictionary, allowing to setup context vars to be uses is value_generators when composing nodes
36
- attr_accessor :ansible_context_vars
34
+ attr_reader :ansible_context_vars
37
35
 
38
36
  # A variable that reflects if vagrant is tageting a single machine, like f.i. when executing vagrant up machine-name
39
37
  attr_reader :multimachine_filter
@@ -47,13 +45,11 @@ module VagrantPlugins
47
45
  @ansible_host_vars = {}
48
46
  @multimachine_filter = ""
49
47
  @ansible_playbook_path = File.join(Dir.pwd, 'provisioning')
50
- @ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars')
51
- @ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars')
52
48
 
53
- @name = name
49
+ @name = name
54
50
  @box = 'ubuntu/trusty64'
55
51
  @domain = 'vagrant'
56
- end
52
+ end
57
53
 
58
54
  # Metodo per la creazione di un gruppo di nodi; in fase di creazione, il blocco inizializza
59
55
  # i valori/le expressioni da utilizzarsi nella valorizzazione degli attributi dei nodi in fase di compose.
@@ -64,7 +60,7 @@ module VagrantPlugins
64
60
  raise RuntimeError, "Nodes #{name} already exists in this cluster." unless not @node_groups.has_key?(name)
65
61
 
66
62
  @node_groups[name] = NodeGroup.new(@group_index, instances, name)
67
- @node_groups[name].box = @box
63
+ @node_groups[name].box = @box
68
64
  @node_groups[name].boxname = lambda { |group_index, group_name, node_index| return "#{group_name}#{node_index + 1}" }
69
65
  @node_groups[name].hostname = lambda { |group_index, group_name, node_index| return "#{group_name}#{node_index + 1}" }
70
66
  @node_groups[name].aliases = []
@@ -74,22 +70,22 @@ module VagrantPlugins
74
70
  @node_groups[name].ansible_groups = []
75
71
  @node_groups[name].attributes = {}
76
72
 
77
- @group_index += 1
73
+ @group_index += 1
78
74
 
79
75
  block.call(@node_groups[name]) if block_given?
80
- end
76
+ end
81
77
 
82
78
  # Prepara il provisioning del cluster
83
- def compose
79
+ def compose
84
80
 
85
- @multimachine_filter = ARGV.length > 1 ? ARGV[1] : "" # detect if running vagrant up/provision MACHINE
81
+ @multimachine_filter = ((['up', 'provision'].include? ARGV[0]) && ARGV.length > 1) ? ARGV.drop(1) : [] # detect if running vagrant up/provision MACHINE
86
82
 
87
83
  ## Fase1: Creazione dei nodi
88
84
 
89
85
  # sviluppa i vari gruppi di nodi, creando i singoli nodi
90
86
  nodes = []
91
87
 
92
- @node_groups.each do |key, group|
88
+ @node_groups.each do |key, group|
93
89
  group.compose(@name, @domain, nodes.size) do |node|
94
90
  nodes << node
95
91
  end
@@ -102,11 +98,11 @@ module VagrantPlugins
102
98
  node.ansible_groups.each do |ansible_group|
103
99
  ansible_groups[ansible_group] = [] unless ansible_groups.has_key? (ansible_group)
104
100
  ansible_groups[ansible_group] << node
105
- end
101
+ end
106
102
  end
107
103
 
108
104
  ## Fase2: Configurazione provisioning del cluster via Ansible
109
- # Ogni nodo diventerà una vm su cui sarà fatto il provisioning, ovvero un host nell'inventory di ansible
105
+ # Ogni nodo diventerà una vm su cui sarà fatto il provisioning, ovvero un host nell'inventory di ansible
110
106
  # Ad ogni gruppo corrispondono nodi con caratteristiche simili
111
107
 
112
108
  # genearazione inventory file per ansible, aka ansible_groups in Vagrant (NB. 1 group = 1 gruppo ansible)
@@ -114,8 +110,8 @@ module VagrantPlugins
114
110
  ansible_groups.each do |ansible_group, ansible_group_nodes|
115
111
  ansible_groups_provision[ansible_group] = []
116
112
  ansible_group_nodes.each do |node|
117
- ansible_groups_provision[ansible_group] << node.hostname if @multimachine_filter.empty? or @multimachine_filter == node.boxname #filter ansible groups if vagrant command on one node
118
- end
113
+ ansible_groups_provision[ansible_group] << node.hostname if checkMultimachineFilter(node.boxname) #filter ansible groups if vagrant command on one node
114
+ end
119
115
  end
120
116
  ansible_groups_provision['all_groups:children'] = ansible_groups.keys
121
117
 
@@ -132,13 +128,13 @@ module VagrantPlugins
132
128
 
133
129
  #genearazione context (NB. 1 group = 1 gruppo host ansible)
134
130
  ansible_groups.each do |ansible_group, ansible_group_nodes|
135
-
136
131
  # genero le variabili per il group
137
132
  provisioners = @ansible_context_vars[ansible_group]
138
133
  unless provisioners.nil?
134
+
139
135
  # se necessario, normalizzo provisioner in array provisioners
140
- provisioners = [ provisioners ] if not provisioners.respond_to?('each')
141
- # per tutti i provisioners abbinati al ruolo
136
+ provisioners = [ provisioners ] if not provisioners.respond_to?('each')
137
+ # per tutti i provisioners abbinati al ruolo
142
138
  provisioners.each do |provisioner|
143
139
  begin
144
140
  vars = provisioner.call(context, ansible_group_nodes)
@@ -148,14 +144,16 @@ module VagrantPlugins
148
144
  rescue Exception => e
149
145
  raise VagrantPlugins::Compose::Errors::ContextVarExpressionError, :message => e.message, :ansible_group => ansible_group
150
146
  end
151
- end
147
+ end
152
148
  end
153
149
  end
154
150
 
155
151
  # cleanup ansible_group_vars files
156
152
  # TODO: make safe
157
- FileUtils.mkdir_p(@ansible_group_vars_path) unless File.exists?(@ansible_group_vars_path)
158
- Dir.foreach(@ansible_group_vars_path) {|f| fn = File.join(@ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
153
+ ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars')
154
+
155
+ FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path)
156
+ Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
159
157
 
160
158
  #generazione ansible_group_vars file (NB. 1 group = 1 gruppo host ansible)
161
159
  ansible_groups.each do |ansible_group, ansible_group_nodes|
@@ -164,8 +162,8 @@ module VagrantPlugins
164
162
  provisioners = @ansible_group_vars[ansible_group]
165
163
  unless provisioners.nil?
166
164
  # se necessario, normalizzo provisioner in array provisioners
167
- provisioners = [ provisioners ] if not provisioners.respond_to?('each')
168
- # per tutti i provisioners abbinati al ruolo
165
+ provisioners = [ provisioners ] if not provisioners.respond_to?('each')
166
+ # per tutti i provisioners abbinati al ruolo
169
167
  provisioners.each do |provisioner|
170
168
  begin
171
169
  vars = provisioner.call(context, ansible_group_nodes)
@@ -175,22 +173,24 @@ module VagrantPlugins
175
173
  rescue Exception => e
176
174
  raise VagrantPlugins::Compose::Errors::GroupVarExpressionError, :message => e.message, :ansible_group => ansible_group
177
175
  end
178
- end
176
+ end
179
177
  end
180
178
 
181
179
  # crea il file (se sono state generate delle variabili)
182
180
  unless ansible_group_vars.empty?
183
- # TODO: make safe
184
- File.open(File.join(@ansible_group_vars_path,"#{ansible_group}.yml") , 'w+') do |file|
181
+ # TODO: make safe
182
+ File.open(File.join(ansible_group_vars_path,"#{ansible_group}.yml") , 'w+') do |file|
185
183
  file.puts YAML::dump(ansible_group_vars)
186
- end
184
+ end
187
185
  end
188
186
  end
189
187
 
190
188
  # cleanup ansible_host_vars files (NB. 1 nodo = 1 host)
191
189
  # TODO: make safe
192
- FileUtils.mkdir_p(@ansible_host_vars_path) unless File.exists?(@ansible_host_vars_path)
193
- Dir.foreach(@ansible_host_vars_path) {|f| fn = File.join(@ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
190
+ ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars')
191
+
192
+ FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path)
193
+ Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
194
194
 
195
195
  #generazione ansible_host_vars file
196
196
  nodes.each do |node|
@@ -201,7 +201,7 @@ module VagrantPlugins
201
201
  provisioners = @ansible_host_vars[ansible_group]
202
202
  unless provisioners.nil?
203
203
  # se necessario, normalizzo provisioner in array provisioners
204
- provisioners = [ provisioners ] if not provisioners.respond_to?('each')
204
+ provisioners = [ provisioners ] if not provisioners.respond_to?('each')
205
205
  # per tutti i provisioners abbinati al gruppo
206
206
  provisioners.each do |provisioner|
207
207
  begin
@@ -212,23 +212,54 @@ module VagrantPlugins
212
212
  rescue Exception => e
213
213
  raise VagrantPlugins::Compose::Errors::HostVarExpressionError, :message => e.message, :host => node.hostname, :ansible_group => ansible_group
214
214
  end
215
- end
215
+ end
216
216
  end
217
217
  end
218
218
 
219
219
  # crea il file (se sono state generate delle variabili)
220
220
  unless ansible_host_vars.empty?
221
- # TODO: make safe
222
- File.open(File.join(@ansible_host_vars_path,"#{node.hostname}.yml") , 'w+') do |file|
221
+ # TODO: make safe
222
+ File.open(File.join(ansible_host_vars_path,"#{node.hostname}.yml") , 'w+') do |file|
223
223
  file.puts YAML::dump(ansible_host_vars)
224
- end
224
+ end
225
225
  end
226
226
  end
227
227
 
228
228
  return nodes, ansible_groups_provision
229
229
  end
230
- end
231
230
 
232
- end
233
- end
231
+ # Prepara il provisioning del cluster
232
+ def from(file)
233
+ puts "from #{file}"
234
+ begin
235
+ a = `ls`
236
+ puts "get #{a}"
237
+ rescue Exception => e
238
+ raise VagrantPlugins::Compose::Errors::PyComposeError, :message => e.message
239
+ end
240
+ end
234
241
 
242
+ def checkMultimachineFilter(boxname)
243
+ if @multimachine_filter.length > 0
244
+ @multimachine_filter.each do |name|
245
+ if pattern = name[/^\/(.+?)\/$/, 1]
246
+ # This is a regular expression name, so we convert to a regular
247
+ # expression and allow that sort of matching.
248
+ regex = Regexp.new(pattern)
249
+ return boxname =~ regex
250
+ else
251
+ # String name, just look for a specific VM
252
+ return boxname == name
253
+ end
254
+ end
255
+ else
256
+ # No name was given, so we return every VM in the order
257
+ # configured.
258
+ return true
259
+ end
260
+ end
261
+
262
+ end
263
+
264
+ end
265
+ end
@@ -6,58 +6,58 @@ module VagrantPlugins
6
6
  # This class defines a group of nodes, representig a set of vagrant machines with similar characteristics.
7
7
  # Nodes will be composed by NodeGroup.compose method, according with the configuration of values/value_generator
8
8
  # of the group of node itself.
9
- class NodeGroup
9
+ class NodeGroup
10
10
 
11
11
  # A number identifying the group of nodes withing the cluster.
12
12
  attr_reader :index
13
-
14
- # The name of the group of nodes
13
+
14
+ # The name of the group of nodes
15
15
  attr_reader :name
16
-
16
+
17
17
  # The number of nodes/instances to be created in the group of nodes.
18
18
  attr_reader :instances
19
-
20
- # The vagrant base box to be used for creating vagrant machines implementing nodes in this group.
19
+
20
+ # The value/value generator to be used for assigning to each node in this group a vagrant base box to be used for creating vagrant machines implementing nodes in this group.
21
21
  attr_accessor :box
22
-
23
- # The value geneator to be used for assigning to each node in this group a box name a.k.a. the name for the machine in VirtualBox/VMware console.
22
+
23
+ # The value/value generator to be used for assigning to each node in this group a box name a.k.a. the name for the machine in VirtualBox/VMware console.
24
24
  attr_accessor :boxname
25
-
26
- # The value geneator to be used for assigning to each node in this group a unique hostname
25
+
26
+ # The value/value generator to be used for assigning to each node in this group a unique hostname
27
27
  attr_accessor :hostname
28
-
29
- # The value geneator to be used for assigning to each node in this group a unique list of aliases a.k.a. alternative host names
28
+
29
+ # The value/value generator to be used for assigning to each node in this group a unique list of aliases a.k.a. alternative host names
30
30
  attr_accessor :aliases
31
-
32
- # The value geneator to be used for assigning to each node in this groupa unique ip
31
+
32
+ # The value/value generator to be used for assigning to each node in this groupa unique ip
33
33
  attr_accessor :ip
34
-
35
- # The value/value geneator to be used for assigning to each node in this group cpus
34
+
35
+ # The value/value generator to be used for assigning to each node in this group cpus
36
36
  attr_accessor :cpus
37
-
38
- # The value/value geneator to be used for assigning to each node in this group memory
37
+
38
+ # The value/value generator to be used for assigning to each node in this group memory
39
39
  attr_accessor :memory
40
-
41
- # The value/value geneator to be used for assigning each node in this group to a list of ansible groups
40
+
41
+ # The value/value generator to be used for assigning each node in this group to a list of ansible groups
42
42
  attr_accessor :ansible_groups
43
-
44
- # The value/value geneator to be used for assigning a dictionary with custom attributes - Hash(String, obj) - to each node in this group.
43
+
44
+ # The value/value generator to be used for assigning a dictionary with custom attributes - Hash(String, obj) - to each node in this group.
45
45
  attr_accessor :attributes
46
46
 
47
- def initialize(index, instances, name)
47
+ def initialize(index, instances, name)
48
48
  @index = index
49
49
  @name = name
50
50
  @instances = instances
51
- end
51
+ end
52
52
 
53
- # Composes the group of nodes, by creating the requiring number of nodes
54
- # in accrodance with values/value_generators.
55
- # Additionally, some "embedded" trasformation will be applied to attributes (boxname, hostname) and
53
+ # Composes the group of nodes, by creating the required number of nodes
54
+ # in accordance with values/value_generators.
55
+ # Additionally, some "embedded" trasformation will be applied to attributes (boxname, hostname) and
56
56
  # some "autogenerated" node properties will be computed (fqdn).
57
57
  def compose(cluster_name, cluster_domain, cluster_offset)
58
58
  node_index = 0
59
59
  while node_index < @instances
60
- box = generate(:box, @box, node_index)
60
+ box = generate(:box, @box, node_index)
61
61
  boxname = maybe_prefix(cluster_name,
62
62
  "#{generate(:boxname, @boxname, node_index)}")
63
63
  hostname = maybe_prefix(cluster_name,
@@ -66,7 +66,7 @@ module VagrantPlugins
66
66
  fqdn = cluster_domain.empty? ? "#{hostname}" : "#{hostname}.#{cluster_domain}"
67
67
  ip = generate(:ip, @ip, node_index)
68
68
  cpus = generate(:cpus, @cpus, node_index)
69
- memory = generate(:memory, @memory, node_index)
69
+ memory = generate(:memory, @memory, node_index)
70
70
  ansible_groups = generate(:ansible_groups, @ansible_groups, node_index)
71
71
  attributes = generate(:attributes, @attributes, node_index)
72
72
  yield Node.new(box, boxname, hostname, fqdn, aliases, ip, cpus, memory, ansible_groups, attributes, cluster_offset + node_index, node_index)
@@ -90,13 +90,13 @@ module VagrantPlugins
90
90
  return generator
91
91
  else
92
92
  begin
93
- return generator.call(@index, @name, node_index)
93
+ return generator.call(@index, @name, node_index)
94
94
  rescue Exception => e
95
95
  raise VagrantPlugins::Compose::Errors::AttributeExpressionError, :message => e.message, :attribute => var, :node_index => node_index, :node_group_name => name
96
96
  end
97
97
  end
98
98
  end
99
- end
100
-
99
+ end
100
+
101
101
  end
102
- end
102
+ end
@@ -1,5 +1,5 @@
1
- module Vagrant
1
+ module Vagrant
2
2
  module Compose
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ x: 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Pandini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -75,6 +75,7 @@ files:
75
75
  - lib/vagrant/compose/version.rb
76
76
  - lib/vagrant/compose.rb
77
77
  - LICENCE
78
+ - provisioning/group_vars/zookeeper.yml
78
79
  - Rakefile
79
80
  - README.md
80
81
  - vagrant-compose.gemspec
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: 2.0.13
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 2.0.14
105
+ rubygems_version: 2.0.14.1
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: A Vagrant plugin that helps building complex multi-machine scenarios.