vagrant-compose 0.2.2 → 0.2.3

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: a5cf1494be11d93a996a0c39fa92a1c52f27dbd5
4
- data.tar.gz: 7245362caf0bad80f39bca9ca32caf5bf91bdd40
3
+ metadata.gz: 829887cd4923b701ab113a461eee004c59f5e53a
4
+ data.tar.gz: 150222776421af2f4acc3ca9b5177f9cf327e4fd
5
5
  SHA512:
6
- metadata.gz: 5f83e4c1a6f546027c274ecf619f93ebc1aa286c777f87d2230215077d503d4651056f03cbe5608a2a4bb1d02b84445fdeb4f4a2cc6d796dae5a99ba03803438
7
- data.tar.gz: b1afbe56b35f74a62367bf01ea3714428f69942c972625e93966bb41cf9049d684ce9b808b31fdc4e00b2c742d359170b523a9a4d7f9a5870604e4fba0e02fb1
6
+ metadata.gz: 3f30bf0ae52906e0d09a5cf2bf68a5a9a067c68614a7857fe4562ee805962242ba46dabc7bf96b7540529507e27e751007333fb70e3c79a2294cc479f010e14a
7
+ data.tar.gz: b868272274ee606bf70138cc7b94d6e66d6278846ef3ad2abe8def377875896a0d8fcb1d19d6147701d878113ce74aa6a526622734ab4284788784d3e747fb4d
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  * Initial release.
4
4
 
5
- # 0.2.0 (December 31, 2015)
5
+ # 0.2.2 (December 31, 2015)
6
6
 
7
7
  breaking changes!
8
8
  * nodes instances number defined into node method (instances attributes removed)
@@ -12,3 +12,11 @@ other changes:
12
12
  * Improved documentation.
13
13
  * cluster domain now is optional
14
14
  * nodes code block now is optional
15
+
16
+ # 0.2.3 (April 2, 2016)
17
+
18
+ * Now custer name can be omitted (thanks to jaydoane)
19
+
20
+ other changes:
21
+ * Documented cluster.debug feature
22
+ * Improved code inline documentation
data/README.md CHANGED
@@ -391,7 +391,7 @@ For instance, when building a [Consul](https://consul.io/) cluster, all the `con
391
391
  ``` ruby
392
392
  config.cluster.compose('test') do |c|
393
393
  ...
394
- c.context_vars['consul-server'] = lambda { |context, nodes|
394
+ c.ansible_context_vars['consul-server'] = lambda { |context, nodes|
395
395
  return { 'consul-serverIPs' => nodes.map { |n| n.ip }.to_a }
396
396
  }
397
397
  ...
@@ -403,10 +403,10 @@ Then, you can use the above context var when generating group_vars for nodes in
403
403
  ``` ruby
404
404
  config.cluster.compose('test') do |c|
405
405
  ...
406
- c.context_vars['consul-server'] = lambda { |context, nodes|
406
+ c.ansible_context_vars['consul-server'] = lambda { |context, nodes|
407
407
  return { 'serverIPs' => nodes.map { |n| n.ip }.to_a }
408
408
  }
409
- c.group_vars['consul-agent'] = lambda { |context, nodes|
409
+ c.ansible_group_vars['consul-agent'] = lambda { |context, nodes|
410
410
  return { 'consul_joins' => context['consul-serverIPs'] }
411
411
  }
412
412
  ...
@@ -4,27 +4,39 @@ require_relative "util/cluster"
4
4
 
5
5
  module VagrantPlugins
6
6
  module Compose
7
+
8
+ # Vagrant compose plugin definition class.
9
+ # This plugins allows easy configuration of a data structure that can be used as a recipe
10
+ # for setting up and provisioning a vagrant cluster composed by several machines with different
11
+ # roles.
7
12
  class Config < Vagrant.plugin("2", :config)
8
13
 
9
- attr_reader :nodes, :ansible_groups
14
+ # After executing compose, it returns the list of nodes in the cluster.
15
+ attr_reader :nodes
16
+
17
+ # After executing compose, it returns the ansible_groups configuration for provisioning nodes in the cluster.
18
+ attr_reader :ansible_groups
10
19
 
11
20
  def initialize
12
21
  @nodes = {}
13
22
  @ansible_groups = {}
14
23
  end
15
-
24
+
25
+ # Implements cluster creation, through the execution of the give code.
16
26
  def compose (name, &block)
17
- # implementa la creazione di un cluster, l'esecuzione di un blocco di codice
18
- # per la configurazione del cluster stesso, e l'esecuzione della sequenza di compose.
27
+ # create the cluster (the data structure representing the cluster)
19
28
  @cluster = Cluster.new(name)
20
29
  begin
30
+ # executes the cluster configuration code
21
31
  block.call(@cluster)
22
32
  rescue Exception => e
23
33
  raise VagrantPlugins::Compose::Errors::ClusterInitializeError, :message => e.message, :cluster_name => name
24
34
  end
35
+ # tranform cluster configuration into a list of nodes/ansible groups to be used for
25
36
  @nodes, @ansible_groups = @cluster.compose
26
37
  end
27
38
 
39
+ # Implements a utility method that allows to check the list of nodes generated by compose.
28
40
  def debug
29
41
  puts "==> cluster #{@cluster.name} with #{nodes.size} nodes"
30
42
  @nodes.each do |node|
@@ -2,7 +2,10 @@ require "vagrant"
2
2
 
3
3
  module VagrantPlugins
4
4
  module Compose
5
+
6
+ #Plugin custom error classes, handling localization of error messages
5
7
  module Errors
8
+ #Base class for vagrant compose custom errors
6
9
  class VagrantComposeError < Vagrant::Errors::VagrantError
7
10
  error_namespace("vagrant_compose.errors")
8
11
  end
@@ -15,7 +15,8 @@ module VagrantPlugins
15
15
  class Plugin < Vagrant.plugin("2")
16
16
  name "Compose"
17
17
  description <<-DESC
18
- This plugin installs ...
18
+ A Vagrant plugin that helps building complex multi-machine scenarios.
19
+ see https://github.com/fabriziopandini/vagrant-compose for documentation.
19
20
  DESC
20
21
 
21
22
  config "cluster" do
@@ -4,18 +4,40 @@ require_relative "node_group"
4
4
  module VagrantPlugins
5
5
  module Compose
6
6
 
7
- # Definisce un cluster, ovvero l'insieme di 1..n gruppi di nodi con caratteristiche simili.
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
9
+ # vagrant cluster composed by several machines with different roles.
8
10
  class Cluster
9
11
 
12
+ # The name of the cluster
10
13
  attr_reader :name
11
- attr_reader :multimachine_filter
14
+
15
+ # The default vagrant base box to be used for creating vagrant machines in this cluster.
16
+ # This setting can be changed at group/node level
12
17
  attr_accessor :box
18
+
19
+ # The network domain to wich the cluster belongs (used for computing nodes fqdn)
13
20
  attr_accessor :domain
21
+
22
+
23
+ # The root path for ansible playbook; it is used as a base path for computing ansible_group_vars and ansible_host_vars
24
+ # It defaults to current directory/provisioning
14
25
  attr_accessor :ansible_playbook_path
15
- attr_accessor :ansible_context_vars
26
+
27
+ # The path where ansible group vars files are stores.
28
+ # It default to ansible_playbook_path/group_vars
16
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
17
33
  attr_accessor :ansible_host_vars
18
34
 
35
+ # A dictionary, allowing to setup context vars to be uses is value_generators when composing nodes
36
+ attr_accessor :ansible_context_vars
37
+
38
+ # A variable that reflects if vagrant is tageting a single machine, like f.i. when executing vagrant up machine-name
39
+ attr_reader :multimachine_filter
40
+
19
41
  # Costruttore di una istanza di cluster.
20
42
  def initialize(name)
21
43
  @group_index = 0
@@ -25,6 +47,8 @@ module VagrantPlugins
25
47
  @ansible_host_vars = {}
26
48
  @multimachine_filter = ""
27
49
  @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')
28
52
 
29
53
  @name = name
30
54
  @box = 'ubuntu/trusty64'
@@ -129,8 +153,6 @@ module VagrantPlugins
129
153
  end
130
154
 
131
155
  # cleanup ansible_group_vars files
132
- # TODO: make variable public
133
- @ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars')
134
156
  # TODO: make safe
135
157
  FileUtils.mkdir_p(@ansible_group_vars_path) unless File.exists?(@ansible_group_vars_path)
136
158
  Dir.foreach(@ansible_group_vars_path) {|f| fn = File.join(@ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
@@ -166,8 +188,6 @@ module VagrantPlugins
166
188
  end
167
189
 
168
190
  # cleanup ansible_host_vars files (NB. 1 nodo = 1 host)
169
- # TODO: make variable public
170
- @ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars')
171
191
  # TODO: make safe
172
192
  FileUtils.mkdir_p(@ansible_host_vars_path) unless File.exists?(@ansible_host_vars_path)
173
193
  Dir.foreach(@ansible_host_vars_path) {|f| fn = File.join(@ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
@@ -1,19 +1,45 @@
1
1
  module VagrantPlugins
2
2
  module Compose
3
3
 
4
- # Definisce un nodo, ovvero uno delle istanze di nodi che compongono il cluster
4
+ # This class define a node throught a set of setting to be used when creating vagrant machines in the cluster.
5
+ # Settings will be assigned value by cluster.compose method, according with the connfiguration
6
+ # of the group of nodes to which the node belongs.
5
7
  class Node
8
+
9
+ # The vagrant base box to be used for creating the vagrant machine that implements the node.
6
10
  attr_reader :box
11
+
12
+ # The box name for this node a.k.a. the name for the machine in VirtualBox/VMware console.
7
13
  attr_reader :boxname
14
+
15
+ # The hostname for the node.
8
16
  attr_reader :hostname
17
+
18
+ # The fully qualified name for the node.
9
19
  attr_reader :fqdn
20
+
21
+ # The list of aliases a.k.a. alternative host names for the node.
10
22
  attr_reader :aliases
23
+
24
+ # The ip for the node.
11
25
  attr_reader :ip
26
+
27
+ # The cpu for the node.
12
28
  attr_reader :cpus
29
+
30
+ # The memory for the node.
13
31
  attr_reader :memory
32
+
33
+ # The list of ansible_groups for the node.
14
34
  attr_reader :ansible_groups
35
+
36
+ # A set of custom attributes for the node.
15
37
  attr_reader :attributes
38
+
39
+ # A number identifying the node within the group of nodes to which the node belongs.
16
40
  attr_reader :index
41
+
42
+ # A number identifying the group of nodes to which the node belongs.
17
43
  attr_reader :group_index
18
44
 
19
45
  def initialize(box, boxname, hostname, fqdn, aliases, ip, cpus, memory, ansible_groups, attributes, index, group_index)
@@ -3,21 +3,45 @@ require_relative "node"
3
3
  module VagrantPlugins
4
4
  module Compose
5
5
 
6
- # Definisce un node group, ovvero un insieme di nodi con caratteristiche omogenee.
7
- # i singoli nodi del gruppo, sono generati in fase di compose tramite delle espressioni
8
- # che generano i valori degli attributi che caratterizzano ogni nodo
6
+ # This class defines a group of nodes, representig a set of vagrant machines with similar characteristics.
7
+ # Nodes will be composed by NodeGroup.compose method, according with the configuration of values/value_generator
8
+ # of the group of node itself.
9
9
  class NodeGroup
10
- attr_reader :uid
10
+
11
+ # A number identifying the group of nodes withing the cluster.
12
+ attr_reader :index
13
+
14
+ # The name of the group of nodes
11
15
  attr_reader :name
16
+
17
+ # The number of nodes/instances to be created in the group of nodes.
12
18
  attr_reader :instances
19
+
20
+ # The vagrant base box to be used for creating vagrant machines implementing nodes in this group.
13
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.
14
24
  attr_accessor :boxname
25
+
26
+ # The value geneator to be used for assigning to each node in this group a unique hostname
15
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
16
30
  attr_accessor :aliases
31
+
32
+ # The value geneator to be used for assigning to each node in this groupa unique ip
17
33
  attr_accessor :ip
34
+
35
+ # The value/value geneator to be used for assigning to each node in this group cpus
18
36
  attr_accessor :cpus
37
+
38
+ # The value/value geneator to be used for assigning to each node in this group memory
19
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
20
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.
21
45
  attr_accessor :attributes
22
46
 
23
47
  def initialize(index, instances, name)
@@ -26,13 +50,18 @@ module VagrantPlugins
26
50
  @instances = instances
27
51
  end
28
52
 
29
- # compone il gruppo, generando le istanze dei vari nodi
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
56
+ # some "autogenerated" node properties will be computed (fqdn).
30
57
  def compose(cluster_name, cluster_domain, cluster_offset)
31
58
  node_index = 0
32
59
  while node_index < @instances
33
60
  box = generate(:box, @box, node_index)
34
- boxname = "#{cluster_name}-#{generate(:boxname, @boxname, node_index)}"
35
- hostname = "#{cluster_name}-#{generate(:hostname, @hostname, node_index)}"
61
+ boxname = maybe_prefix(cluster_name,
62
+ "#{generate(:boxname, @boxname, node_index)}")
63
+ hostname = maybe_prefix(cluster_name,
64
+ "#{generate(:hostname, @hostname, node_index)}")
36
65
  aliases = generate(:aliases, @aliases, node_index).join(',')
37
66
  fqdn = cluster_domain.empty? ? "#{hostname}" : "#{hostname}.#{cluster_domain}"
38
67
  ip = generate(:ip, @ip, node_index)
@@ -46,8 +75,16 @@ module VagrantPlugins
46
75
  end
47
76
  end
48
77
 
49
- # funzione di utilità per l'esecuzione delle espressioni che generano
50
- # i valori degli attributi
78
+ # utility function for concatenating cluster name (if present) to boxname/hostname
79
+ def maybe_prefix(cluster_name, name)
80
+ if cluster_name && cluster_name.length > 0
81
+ "#{cluster_name}-" + name
82
+ else
83
+ name
84
+ end
85
+ end
86
+
87
+ # utility function for resolving value/value generators
51
88
  def generate(var, generator, node_index)
52
89
  unless generator.respond_to? :call
53
90
  return generator
@@ -1,5 +1,5 @@
1
- module Vagrant
1
+ module Vagrant
2
2
  module Compose
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -5,7 +5,6 @@ require "vagrant/compose/plugin"
5
5
  module VagrantPlugins
6
6
  module Compose
7
7
  lib_path = Pathname.new(File.expand_path("../compose", __FILE__))
8
-
9
8
  autoload :Errors, lib_path.join("errors")
10
9
 
11
10
  # This returns the path to the source of this plugin.
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Pandini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-31 00:00:00.000000000 Z
11
+ date: 2016-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake