Class: VagrantPlugins::Compose::NodeGroup
- Inherits:
-
Object
- Object
- VagrantPlugins::Compose::NodeGroup
- Defined in:
- lib/vagrant/compose/util/node_group.rb
Overview
Definisce un node group, ovvero un insieme di nodi con caratteristiche omogenee. i singoli nodi del gruppo, sono generati in fase di compose tramite delle espressioni che generano i valori degli attributi che caratterizzano ogni nodo
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#ansible_groups ⇒ Object
Returns the value of attribute ansible_groups.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#box ⇒ Object
Returns the value of attribute box.
-
#boxname ⇒ Object
Returns the value of attribute boxname.
-
#cpus ⇒ Object
Returns the value of attribute cpus.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#instances ⇒ Object
readonly
Returns the value of attribute instances.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#compose(cluster_name, cluster_domain, cluster_offset) ⇒ Object
compone il gruppo, generando le istanze dei vari nodi.
-
#generate(var, generator, node_index) ⇒ Object
funzione di utilità per l’esecuzione delle espressioni che generano i valori degli attributi.
-
#initialize(index, instances, name) ⇒ NodeGroup
constructor
A new instance of NodeGroup.
Constructor Details
#initialize(index, instances, name) ⇒ NodeGroup
23 24 25 26 27 |
# File 'lib/vagrant/compose/util/node_group.rb', line 23 def initialize(index, instances, name) @index = index @name = name @instances = instances end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
16 17 18 |
# File 'lib/vagrant/compose/util/node_group.rb', line 16 def aliases @aliases end |
#ansible_groups ⇒ Object
Returns the value of attribute ansible_groups.
20 21 22 |
# File 'lib/vagrant/compose/util/node_group.rb', line 20 def ansible_groups @ansible_groups end |
#attributes ⇒ Object
Returns the value of attribute attributes.
21 22 23 |
# File 'lib/vagrant/compose/util/node_group.rb', line 21 def attributes @attributes end |
#box ⇒ Object
Returns the value of attribute box.
13 14 15 |
# File 'lib/vagrant/compose/util/node_group.rb', line 13 def box @box end |
#boxname ⇒ Object
Returns the value of attribute boxname.
14 15 16 |
# File 'lib/vagrant/compose/util/node_group.rb', line 14 def boxname @boxname end |
#cpus ⇒ Object
Returns the value of attribute cpus.
18 19 20 |
# File 'lib/vagrant/compose/util/node_group.rb', line 18 def cpus @cpus end |
#hostname ⇒ Object
Returns the value of attribute hostname.
15 16 17 |
# File 'lib/vagrant/compose/util/node_group.rb', line 15 def hostname @hostname end |
#instances ⇒ Object (readonly)
Returns the value of attribute instances.
12 13 14 |
# File 'lib/vagrant/compose/util/node_group.rb', line 12 def instances @instances end |
#ip ⇒ Object
Returns the value of attribute ip.
17 18 19 |
# File 'lib/vagrant/compose/util/node_group.rb', line 17 def ip @ip end |
#memory ⇒ Object
Returns the value of attribute memory.
19 20 21 |
# File 'lib/vagrant/compose/util/node_group.rb', line 19 def memory @memory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/vagrant/compose/util/node_group.rb', line 11 def name @name end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
10 11 12 |
# File 'lib/vagrant/compose/util/node_group.rb', line 10 def uid @uid end |
Instance Method Details
#compose(cluster_name, cluster_domain, cluster_offset) ⇒ Object
compone il gruppo, generando le istanze dei vari nodi
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vagrant/compose/util/node_group.rb', line 30 def compose(cluster_name, cluster_domain, cluster_offset) node_index = 0 while node_index < @instances box = generate(:box, @box, node_index) boxname = "#{cluster_name}-#{generate(:boxname, @boxname, node_index)}" hostname = "#{cluster_name}-#{generate(:hostname, @hostname, node_index)}" aliases = generate(:aliases, @aliases, node_index).join(',') fqdn = cluster_domain.empty? ? "#{hostname}" : "#{hostname}.#{cluster_domain}" ip = generate(:ip, @ip, node_index) cpus = generate(:cpus, @cpus, node_index) memory = generate(:memory, @memory, node_index) ansible_groups = generate(:ansible_groups, @ansible_groups, node_index) attributes = generate(:attributes, @attributes, node_index) yield Node.new(box, boxname, hostname, fqdn, aliases, ip, cpus, memory, ansible_groups, attributes, cluster_offset + node_index, node_index) node_index += 1 end end |
#generate(var, generator, node_index) ⇒ Object
funzione di utilità per l’esecuzione delle espressioni che generano i valori degli attributi
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vagrant/compose/util/node_group.rb', line 51 def generate(var, generator, node_index) unless generator.respond_to? :call return generator else begin return generator.call(@index, @name, node_index) rescue Exception => e raise VagrantPlugins::Compose::Errors::AttributeExpressionError, :message => e., :attribute => var, :node_index => node_index, :node_group_name => name end end end |