Class: SwarmClusterCliOpe::Commands::Base

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

Direct Known Subclasses

Container, Service, Swarm, Task

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggerConcern

#logger

Constructor Details

#initialize(connection_uri: nil, base_suffix_command: ["--format=\"{{json .}}\""]) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 13

def initialize(connection_uri: nil, base_suffix_command: ["--format=\"{{json .}}\""])
  if connection_uri
    if connection_uri.blank?
      @docker_host = "DOCKER_HOST=" # casistica di sviluppo, in cui l'host viene mappato localmente
    else
      @docker_host = "DOCKER_HOST=#{connection_uri}"
    end
  end
  @base_suffix_command = base_suffix_command
end

Instance Attribute Details

#base_suffix_commandArray<String>

Returns elenco di comandi da aggiungere in coda al comando lanciato.

Returns:

  • (Array<String>)

    elenco di comandi da aggiungere in coda al comando lanciato



11
12
13
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 11

def base_suffix_command
  @base_suffix_command
end

#docker_hostString

Returns Identifivo per potersi collegare.

Returns:

  • (String)

    Identifivo per potersi collegare



8
9
10
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 8

def docker_host
  @docker_host
end

Class Method Details

.object_identifierString

Ritorna il nome identificativo dell’elemento all’interno di docker: container,service,stack ecc..

Returns:

  • (String)


53
54
55
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 53

def self.object_identifier
  self.name.demodulize.downcase
end

Instance Method Details

#command {|cmd| ... } ⇒ SwarmClusterCliOpe::ShellCommandExecution

Aggiunge al blocco passato di comandi, i comandi standard iniziali



35
36
37
38
39
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 35

def command
  cmd = ShellCommandExecution.new(base_prefix_command)
  yield cmd if block_given?
  cmd.add(*base_suffix_command)
end

#docker_inspect(id) ⇒ SwarmClusterCliOpe::ShellCommandResponse

Esegue l’inspect sul componente

Parameters:

  • id (String)

Returns:



44
45
46
47
48
# File 'lib/swarm_cluster_cli_ope/commands/base.rb', line 44

def docker_inspect(id)
  command do |cmd|
    cmd.add(" #{self.class.object_identifier} inspect #{id}")
  end.execute
end