Class: SwarmClusterCliOpe::Commands::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/swarm_cluster_cli_ope/commands/service.rb

Instance Attribute Summary

Attributes inherited from Base

#base_suffix_command, #docker_host

Instance Method Summary collapse

Methods inherited from Base

#command, #docker_inspect, #initialize, object_identifier

Methods included from LoggerConcern

#logger

Constructor Details

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

Instance Method Details

#find(service_name, stack_name: nil) ⇒ SwarmClusterCliOpe::ShellCommandResponse

Ricarca il servizio per nome, nel caso in cui abbiamo anche il nome dello stack, concateniamo il nome del servizio con lo stack (dato che è il sistema con cui è più semplice trovare un servizio di uno stack). sucessivamente troviamo tutti i containers legati a quel servizio ed estrapoliamo l’istanza del primo

Parameters:

  • service_name (String)
  • stack_name (String) (defaults to: nil)

    optional

Returns:



21
22
23
24
25
# File 'lib/swarm_cluster_cli_ope/commands/service.rb', line 21

def find(service_name, stack_name: nil)
  command do |cmd|
    cmd.add("service ls --filter=\"name=#{  stack_name ? "#{stack_name}_" : "" }#{service_name}\"")
  end.execute
end

#ls(stack_name: nil) ⇒ SwarmClusterCliOpe::ShellCommandResponse

Parameters:

  • stack_name (String) (defaults to: nil)

    nome dello stack da filtrare

Returns:



7
8
9
10
11
12
# File 'lib/swarm_cluster_cli_ope/commands/service.rb', line 7

def ls(stack_name: nil)
  command do |cmd|
    cmd.add("service ls")
    cmd.add("--filter=\"label=com.docker.stack.namespace=#{stack_name}\"") if stack_name
  end.execute
end

#ps(service_name, stack_name: nil, only_active: true) ⇒ SwarmClusterCliOpe::ShellCommandResponse

Esegue il ps per un determinato servizio

Parameters:

  • service_name (String)
  • stack_name (String) (defaults to: nil)

    optional

  • only_active (TrueClass) (defaults to: true)

    se si vuole avere solo quelli attivi

Returns:



33
34
35
36
37
38
# File 'lib/swarm_cluster_cli_ope/commands/service.rb', line 33

def ps(service_name, stack_name: nil, only_active: true)
  command do |cmd|
    cmd.add("service ps  #{stack_name ? "#{stack_name}_" : "" }#{service_name}")
    cmd.add('-f "desired-state=running"') if only_active
  end.execute
end