Class: SwarmClusterCliOpe::Models::Base

Inherits:
Object
  • Object
show all
Includes:
ConfigurationConcern, LoggerConcern
Defined in:
lib/swarm_cluster_cli_ope/models/base.rb

Direct Known Subclasses

Container, MappedVolume, Service, Stack, Task

Constant Summary collapse

IDNotFoundOnObject =
Class.new(Error)

Instance Method Summary collapse

Methods included from LoggerConcern

#logger

Constructor Details

#initialize(obj) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'lib/swarm_cluster_cli_ope/models/base.rb', line 8

def initialize(obj)
  logger.debug { obj.inspect }
  obj.each do |k, v|
    name = k.underscore
    self.send("#{name}=", v) if respond_to?("#{name}=".to_sym)
  end
end

Instance Method Details

#docker_commandCommands::Base

Ritorna il comando corretto, inizializzato con la connecttion uri corretta

Returns:



29
30
31
# File 'lib/swarm_cluster_cli_ope/models/base.rb', line 29

def docker_command
  Commands.const_get(self.class.name.demodulize).new(connection_uri: mapped_uri_connection)
end

#docker_inspectObject

Esegue un inspect del tipo di componente di docker

Raises:



20
21
22
23
# File 'lib/swarm_cluster_cli_ope/models/base.rb', line 20

def docker_inspect
  raise IDNotFoundOnObject if id.blank?
  docker_command.docker_inspect(id).result.first
end

#mapped_uri_connectionObject

Override della connessione al nodo corretto, i container sono legati allo swarm, conseguentemente dobbiamo collegarci al nodo giusto, di default lasiamo nil, così che prende le cfgs di default



36
37
38
# File 'lib/swarm_cluster_cli_ope/models/base.rb', line 36

def mapped_uri_connection
  nil
end