Class: SwarmClusterCliOpe::Configuration

Inherits:
BaseConfiguration show all
Defined in:
lib/swarm_cluster_cli_ope/configuration.rb

Overview

Classe per la gestione delle configurazioni, unisce le configurazioni di base alle configurazioni di progetto; le quali sono salvate nel file di configurazione del progetto .swarm_cluster_project sottoforma di json che vengono mergiate sulle configurazioni base

Constant Summary

Constants inherited from BaseConfiguration

BaseConfiguration::NoBaseConfigurations

Instance Attribute Summary

Attributes inherited from BaseConfiguration

#environment, #stack_name

Instance Method Summary collapse

Methods inherited from BaseConfiguration

base_cfg_path, #development_mode?, #env, exist_base?, #get_syncro, #local_compose_project_name, #logger_level, #merged_configurations, #save_project_cfgs, #sync_configurations

Methods included from LoggerConcern

#logger

Instance Method Details

#get_node(node) ⇒ SwarmClusterCliOpe::Node

Parameters:

  • node (String)

    nome del nodo

Returns:



72
73
74
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 72

def get_node(node)
  nodes.find { |c| c.name == node }
end

#get_node_by_id(node_id) ⇒ SwarmClusterCliOpe::Node

Parameters:

  • node_id (String)

Returns:



78
79
80
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 78

def get_node_by_id(node_id)
  nodes.find { |c| c.id == node_id }
end

#managersArray<SwarmClusterCliOpe::Manager>

Lista di nodi su cui lavorare

Returns:



17
18
19
20
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 17

def managers
  return @_managers if @_managers
  @_managers = self.nodes.select { |n| read_managers_cache_list.include?(n.name) }.collect { |c| Manager.new(name: c.name.to_s, connection_uri: c.connection_uri) }
end

#nodesArray<SwarmClusterCliOpe::Node>

Lista di tutti i nodi del cluster

Returns:



44
45
46
47
48
49
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 44

def nodes
  @_nodes ||= Hash.new do |hash, key|
    hash[key] = self.merged_configurations[:connections_maps].collect { |m, c| Node.new(name: m.to_s, connection_uri: c) }
  end
  @_nodes[environment]
end

#nodes=(objs) ⇒ Configuration

Lista di nodi da assegnare alle configurazioni

Parameters:

Returns:



56
57
58
59
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 56

def nodes=(objs)
  nodes[environment] = objs
  self
end

#read_managers_cache_listObject



34
35
36
37
38
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 34

def read_managers_cache_list
  # TODO sarebbe da aggiornare ogni tanto, metti che uno non spegne mai il pc
  refresh_managers_cache_list unless File.exists?(swarm_manager_cache_path)
  File.read(swarm_manager_cache_path).split("\n")
end

#refresh_managers_cache_listObject

Esegue un refresh della lista dei manager, ciclando su tutti i nodi, e scrivendo in /tmp un file temporaneo con con la lista dei nomi dei managers



25
26
27
28
29
30
31
32
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 25

def refresh_managers_cache_list
  list = self.nodes.select(&:manager?).collect { |c| Manager.new(name: c.name, connection_uri: c.connection_uri) }
  File.open(swarm_manager_cache_path, "w") do |f|
    list.collect(&:name).each do |name|
      f.puts(name)
    end
  end
end

#save_base_cfgsObject

Salva le configurazioni base in HOME



63
64
65
66
67
# File 'lib/swarm_cluster_cli_ope/configuration.rb', line 63

def save_base_cfgs
  super do |obj|
    obj.merge({connections_maps: nodes.collect { |k| [k.name, k.connection_uri] }.to_h})
  end
end