Class: Serverspec::Type::DockerService
- Inherits:
-
DockerBase
- Object
- DockerBase
- Serverspec::Type::DockerService
- Defined in:
- lib/serverspec_extra_types/types/docker_service.rb
Instance Method Summary collapse
- #configs ⇒ Object
- #environment_variable(regex) ⇒ Object
- #environment_variables ⇒ Object
- #exist? ⇒ Boolean
- #global? ⇒ Boolean
- #has_config?(name, target = nil) ⇒ Boolean
- #has_environment_variable?(regex, value = nil) ⇒ Boolean
- #has_host?(host) ⇒ Boolean
- #has_image?(image) ⇒ Boolean
- #has_image_sha?(image) ⇒ Boolean
- #has_label?(label, value = nil) ⇒ Boolean
- #has_mount?(source, target, type) ⇒ Boolean
- #has_network?(name) ⇒ Boolean
- #has_placement_constraint?(constraint) ⇒ Boolean
- #has_restart_limit?(limit) ⇒ Boolean
- #has_restart_policy?(policy) ⇒ Boolean
- #has_secret?(name, target = nil) ⇒ Boolean
- #has_user?(user) ⇒ Boolean
- #hosts ⇒ Object
- #image ⇒ Object
- #image_sha ⇒ Object
- #label(label) ⇒ Object
- #labels ⇒ Object
- #map_port?(published, target, protocol = 'tcp', mode = 'ingress') ⇒ Boolean
- #mounts ⇒ Object
- #networks ⇒ Object
- #placement_constraints ⇒ Object
- #port_map ⇒ Object
- #replicas ⇒ Object
- #replicated? ⇒ Boolean
- #restart_limit ⇒ Object
- #restart_policy ⇒ Object
- #secrets ⇒ Object
- #user ⇒ Object
Instance Method Details
#configs ⇒ Object
72 73 74 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 72 def configs inspection['Spec']['TaskTemplate']['ContainerSpec']['Configs'] end |
#environment_variable(regex) ⇒ Object
145 146 147 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 145 def environment_variable(regex) environment_variables.find { |str| str =~ /^#{regex}=/ }.split('=')[1..-1].join('=') end |
#environment_variables ⇒ Object
149 150 151 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 149 def environment_variables inspection['Spec']['TaskTemplate']['ContainerSpec']['Env'] end |
#exist? ⇒ Boolean
10 11 12 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 10 def exist? get_inspection.success? end |
#global? ⇒ Boolean
108 109 110 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 108 def global? inspection['Spec']['Mode']['Global'] end |
#has_config?(name, target = nil) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 64 def has_config?(name, target = nil) if target configs.find { |config| config['ConfigName'] == name && config['File']['Name'] == target } else configs.find { |config| config['ConfigName'] == name } end end |
#has_environment_variable?(regex, value = nil) ⇒ Boolean
137 138 139 140 141 142 143 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 137 def has_environment_variable?(regex, value = nil) if value environment_variable(regex) == value else environment_variable(regex) end end |
#has_host?(host) ⇒ Boolean
88 89 90 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 88 def has_host?(host) hosts.include? host end |
#has_image?(image) ⇒ Boolean
30 31 32 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 30 def has_image?(image) self.image == image end |
#has_image_sha?(image) ⇒ Boolean
34 35 36 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 34 def has_image_sha?(image) self.image == image end |
#has_label?(label, value = nil) ⇒ Boolean
153 154 155 156 157 158 159 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 153 def has_label?(label, value = nil) if value label(label)[1] == value else label(label) end end |
#has_mount?(source, target, type) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 54 def has_mount?(source, target, type) mounts.find do |mount| mount['Source'] == source && mount['Target'] == target && mount['Type'] == type end end |
#has_network?(name) ⇒ Boolean
120 121 122 123 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 120 def has_network?(name) target_network = DockerNetwork.new(name) networks.find { |network| network['Target'].include? target_network.id } end |
#has_placement_constraint?(constraint) ⇒ Boolean
96 97 98 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 96 def has_placement_constraint?(constraint) placement_constraints.include? constraint end |
#has_restart_limit?(limit) ⇒ Boolean
18 19 20 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 18 def has_restart_limit?(limit) restart_limit == limit end |
#has_restart_policy?(policy) ⇒ Boolean
14 15 16 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 14 def has_restart_policy?(policy) restart_policy == policy end |
#has_secret?(name, target = nil) ⇒ Boolean
76 77 78 79 80 81 82 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 76 def has_secret?(name, target = nil) if target secrets.find { |secret| secret['SecretName'] == name && secret['File']['Name'] == target } else secrets.find { |secret| secret['SecretName'] == name } end end |
#has_user?(user) ⇒ Boolean
46 47 48 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 46 def has_user?(user) self.user == user end |
#hosts ⇒ Object
92 93 94 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 92 def hosts inspection['Spec']['TaskTemplate']['ContainerSpec']['Hosts'] end |
#image ⇒ Object
38 39 40 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 38 def image inspection['Spec']['TaskTemplate']['ContainerSpec']['Image'].split('@')[0] end |
#image_sha ⇒ Object
42 43 44 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 42 def image_sha inspection['Spec']['TaskTemplate']['ContainerSpec']['Image'].split('@')[1] end |
#label(label) ⇒ Object
161 162 163 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 161 def label(label) labels.find { |key, _val| key == label } end |
#labels ⇒ Object
165 166 167 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 165 def labels inspection['Spec']['Labels'] end |
#map_port?(published, target, protocol = 'tcp', mode = 'ingress') ⇒ Boolean
129 130 131 132 133 134 135 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 129 def map_port?(published, target, protocol = 'tcp', mode = 'ingress') port_map.find do |port| port['PublishedPort'] == published.to_i && port['TargetPort'] == target.to_i && port['PublishMode'] == mode && port['Protocol'] == protocol end end |
#mounts ⇒ Object
60 61 62 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 60 def mounts inspection['Spec']['TaskTemplate']['ContainerSpec']['Mounts'] end |
#networks ⇒ Object
116 117 118 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 116 def networks inspection['Spec']['TaskTemplate']['Networks'] end |
#placement_constraints ⇒ Object
100 101 102 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 100 def placement_constraints inspection['Spec']['TaskTemplate']['Placement']['Constraints'] end |
#port_map ⇒ Object
125 126 127 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 125 def port_map inspection['Spec']['EndpointSpec']['Ports'] end |
#replicas ⇒ Object
112 113 114 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 112 def replicas inspection['Spec']['Mode']['Replicated']['Replicas'] end |
#replicated? ⇒ Boolean
104 105 106 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 104 def replicated? inspection['Spec']['Mode']['Replicated'] end |
#restart_limit ⇒ Object
26 27 28 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 26 def restart_limit inspection['Spec']['TaskTemplate']['RestartPolicy']['MaxAttempts'] end |
#restart_policy ⇒ Object
22 23 24 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 22 def restart_policy inspection['Spec']['TaskTemplate']['RestartPolicy']['Condition'] end |
#secrets ⇒ Object
84 85 86 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 84 def secrets inspection['Spec']['TaskTemplate']['ContainerSpec']['Secrets'] end |
#user ⇒ Object
50 51 52 |
# File 'lib/serverspec_extra_types/types/docker_service.rb', line 50 def user inspection['Spec']['TaskTemplate']['ContainerSpec']['User'] end |