Class: SwarmClusterCliOpe::Models::Container

Inherits:
Base
  • Object
show all
Defined in:
lib/swarm_cluster_cli_ope/models/container.rb

Direct Known Subclasses

ComposeContainer

Constant Summary

Constants inherited from Base

Base::IDNotFoundOnObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#docker_command, #docker_inspect, #initialize

Methods included from LoggerConcern

#logger

Constructor Details

This class inherits a constructor from SwarmClusterCliOpe::Models::Base

Instance Attribute Details

#idString

Returns id del container.

Returns:

  • (String)

    id del container



8
9
10
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 8

def id
  @id
end

#imageString

Returns nome dell’immagine.

Returns:

  • (String)

    nome dell’immagine



10
11
12
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 10

def image
  @image
end

#labelsHash

Returns labels del container.

Returns:

  • (Hash)

    labels del container



12
13
14
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 12

def labels
  @labels
end

#nameString

Returns:

  • (String)


6
7
8
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 6

def name
  @name
end

Class Method Details

.all(service_name: nil) ⇒ Object



34
35
36
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 34

def self.all(service_name: nil)
  Commands::Container.new.ps(service_name: service_name).result(object_class: Container)
end

.find_by_service_name(service_name, stack_name: nil) ⇒ SwarmClusterCliOpe::Models::Container



30
31
32
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 30

def self.find_by_service_name(service_name, stack_name: nil)
  Service.find(service_name,stack_name:stack_name).containers.first
end

Instance Method Details

#config=(config) ⇒ Object

Può essere che riceva dei valori dal config, tipo quando facciamo inspect



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

def config=(config)
  @labels = config["Labels"]
end

#copy_in(src, dest) ⇒ Object

Copia i file dentro al container

Parameters:

  • src (String)

    sorgente da cui copiare

  • dest (String)

    destinazione a cui copiare



42
43
44
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 42

def copy_in(src, dest)
  docker_command.cp(src, "#{id}:#{dest}").success?
end

#copy_out(src, dest) ⇒ Object

Copia i file dal container all’esterno

Parameters:

  • src (String)

    sorgente da cui copiare

  • dest (String)

    destinazione a cui copiare



50
51
52
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 50

def copy_out(src, dest)
  docker_command.cp("#{id}:#{src}", dest).success?
end

#exec(cmd) ⇒ Object

Esegue il comando passato



56
57
58
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 56

def exec(cmd)
  docker_command.exec(id, cmd)
end

#mapped_uri_connectionString

Ritorna il connection_uri del nodo che ospita il container

Returns:

  • (String)


63
64
65
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 63

def mapped_uri_connection
  node.connection_uri
end

#mapped_volumesArray<MappedVolume>

Elenco dei volumi mappato

Returns:



70
71
72
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 70

def mapped_volumes
  docker_inspect.Mounts.collect { |v| MappedVolume.new(v, container: self) }
end

#nodeSwarmClusterCliOpe::Node

Ritorna il nodo dello swarm che contiene questo container



77
78
79
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 77

def node
  cfgs.get_node_by_id(node_id)
end

#node_idString

Returns id del nodo di appartenenza.

Returns:

  • (String)

    id del nodo di appartenenza



25
26
27
# File 'lib/swarm_cluster_cli_ope/models/container.rb', line 25

def node_id
  labels["com.docker.swarm.node.id"]
end