Class: SwarmClusterCliOpe::Kubernetes::Pod
- Inherits:
-
Object
- Object
- SwarmClusterCliOpe::Kubernetes::Pod
- Includes:
- LoggerConcern
- Defined in:
- lib/swarm_cluster_cli_ope/kubernetes/pod.rb
Overview
Interfaccia per la comunicazione con il POD
Instance Attribute Summary collapse
Class Method Summary collapse
- .find_by_name(name, namespace: nil, context: nil) ⇒ Object
- .find_by_selector(selector, namespace: nil, context: nil) ⇒ Pod
Instance Method Summary collapse
-
#base_cmd(cmd) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Appende solamente la parte base dei comandi.
-
#copy_in(src, dst) ⇒ TrueClass, FalseClass
Proxy class per essere simili al container per swarm.
- #copy_out(src, dst) ⇒ TrueClass, FalseClass
-
#cp_in(src, dst) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Comando per la copia del file.
-
#cp_out(src, dst) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Comando per la copia del file dal container.
- #exec(cmd, allow_failure: false) ⇒ SwarmClusterCliOpe::ShellCommandResponse
-
#initialize(pod_description, context:) ⇒ Pod
constructor
A new instance of Pod.
- #name ⇒ String
- #namespace ⇒ Object
Methods included from LoggerConcern
Constructor Details
#initialize(pod_description, context:) ⇒ Pod
Returns a new instance of Pod.
17 18 19 20 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 17 def initialize(pod_description, context:) @pod_description = pod_description.to_h.deep_symbolize_keys @context = context end |
Instance Attribute Details
#context ⇒ String
13 14 15 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 13 def context @context end |
#pod_description ⇒ Hash
10 11 12 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 10 def pod_description @pod_description end |
Class Method Details
.find_by_name(name, namespace: nil, context: nil) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 112 def self.find_by_name(name, namespace: nil, context: nil) base_cmd = ["kubectl"] base_cmd << "--namespace=#{namespace}" unless namespace.blank? base_cmd << "--context=#{context}" unless context.blank? base_cmd << "get pod #{name}" base_cmd << "--output=json" cmd = ShellCommandExecution.new(base_cmd) ris = cmd.execute(allow_failure: true) if ris.failed? puts "Problemi nella ricerca del pod" exit else self.new(ris.single_obj, context: context) end end |
.find_by_selector(selector, namespace: nil, context: nil) ⇒ Pod
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 87 def self.find_by_selector(selector, namespace: nil, context: nil) base_cmd = ["kubectl"] base_cmd << "--namespace=#{namespace}" unless namespace.blank? base_cmd << "--context=#{context}" unless context.blank? base_cmd << "get pod" base_cmd << "--selector=#{selector}" base_cmd << "--field-selector=status.phase=Running" #solo pod che stanno girando teniamo sotto controllo base_cmd << "--output=json" cmd = ShellCommandExecution.new(base_cmd) ris = cmd.execute(allow_failure: true) if ris.failed? puts "Problemi nella ricerca del pod" exit else if ris.single_obj[:items].empty? puts "non abbiamo trovato il pod" exit else self.new(ris.single_obj[:items].first, context: context) end end end |
Instance Method Details
#base_cmd(cmd) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Appende solamente la parte base dei comandi
43 44 45 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 43 def base_cmd(cmd) ShellCommandExecution.new([base_kubectl_cmd_env, cmd].flatten) end |
#copy_in(src, dst) ⇒ TrueClass, FalseClass
Proxy class per essere simili al container per swarm
71 72 73 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 71 def copy_in(src, dst) cp_in(src, dst).execute.success? end |
#copy_out(src, dst) ⇒ TrueClass, FalseClass
78 79 80 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 78 def copy_out(src, dst) cp_out(src, dst).execute.success? end |
#cp_in(src, dst) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Comando per la copia del file
53 54 55 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 53 def cp_in(src, dst) base_cmd(["cp", src, "#{name}:#{dst}"]) end |
#cp_out(src, dst) ⇒ SwarmClusterCliOpe::ShellCommandExecution
Comando per la copia del file dal container
62 63 64 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 62 def cp_out(src, dst) base_cmd(["cp", "#{name}:#{src}", dst]) end |
#exec(cmd, allow_failure: false) ⇒ SwarmClusterCliOpe::ShellCommandResponse
35 36 37 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 35 def exec(cmd, allow_failure: false) base_cmd(["exec", name, "--", cmd].flatten).execute(allow_failure: allow_failure) end |
#name ⇒ String
24 25 26 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 24 def name @pod_description[:metadata][:name] end |
#namespace ⇒ Object
28 29 30 |
# File 'lib/swarm_cluster_cli_ope/kubernetes/pod.rb', line 28 def namespace @pod_description[:metadata][:namespace] end |