Class: VagrantPlugins::Compose::NodeGroup

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#aliasesObject

Returns the value of attribute aliases.



16
17
18
# File 'lib/vagrant/compose/util/node_group.rb', line 16

def aliases
  @aliases
end

#ansible_groupsObject

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

#attributesObject

Returns the value of attribute attributes.



21
22
23
# File 'lib/vagrant/compose/util/node_group.rb', line 21

def attributes
  @attributes
end

#boxObject

Returns the value of attribute box.



13
14
15
# File 'lib/vagrant/compose/util/node_group.rb', line 13

def box
  @box
end

#boxnameObject

Returns the value of attribute boxname.



14
15
16
# File 'lib/vagrant/compose/util/node_group.rb', line 14

def boxname
  @boxname
end

#cpusObject

Returns the value of attribute cpus.



18
19
20
# File 'lib/vagrant/compose/util/node_group.rb', line 18

def cpus
  @cpus
end

#hostnameObject

Returns the value of attribute hostname.



15
16
17
# File 'lib/vagrant/compose/util/node_group.rb', line 15

def hostname
  @hostname
end

#instancesObject (readonly)

Returns the value of attribute instances.



12
13
14
# File 'lib/vagrant/compose/util/node_group.rb', line 12

def instances
  @instances
end

#ipObject

Returns the value of attribute ip.



17
18
19
# File 'lib/vagrant/compose/util/node_group.rb', line 17

def ip
  @ip
end

#memoryObject

Returns the value of attribute memory.



19
20
21
# File 'lib/vagrant/compose/util/node_group.rb', line 19

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/vagrant/compose/util/node_group.rb', line 11

def name
  @name
end

#uidObject (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.message, :attribute => var, :node_index => node_index, :node_group_name => name
    end
  end
end