Module: PortAuthority::Mechanism::LoadBalancer
- Extended by:
- LoadBalancer
- Included in:
- LoadBalancer
- Defined in:
- lib/port-authority/mechanism/load_balancer.rb
Instance Attribute Summary collapse
-
#_container ⇒ Object
readonly
Returns the value of attribute _container.
-
#_container_def ⇒ Object
readonly
Returns the value of attribute _container_def.
-
#_image ⇒ Object
readonly
Returns the value of attribute _image.
Instance Method Summary collapse
- #container ⇒ Object
- #create! ⇒ Object
- #image ⇒ Object
- #init! ⇒ Object
- #pull! ⇒ Object
- #remove! ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #up? ⇒ Boolean
- #update! ⇒ Object
Instance Attribute Details
#_container ⇒ Object (readonly)
Returns the value of attribute _container.
9 10 11 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 9 def _container @_container end |
#_container_def ⇒ Object (readonly)
Returns the value of attribute _container_def.
9 10 11 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 9 def _container_def @_container_def end |
#_image ⇒ Object (readonly)
Returns the value of attribute _image.
9 10 11 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 9 def _image @_image end |
Instance Method Details
#container ⇒ Object
16 17 18 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 16 def container @_container ||= Docker::Container.get(Config.lbaas[:name]) rescue nil end |
#create! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 28 def create! port_bindings = Hash.new self.image.json['ContainerConfig']['ExposedPorts'].keys.each do |port| port_bindings[port] = [ { 'HostPort' => "#{port.split('/').first}" } ] end @_container_def = { 'Image' => self.image.json['Id'], 'name' => Config.lbaas[:name], 'Hostname' => Config.lbaas[:name], 'Env' => [ "ETCDCTL_ENDPOINT=#{Config.etcd[:endpoints].map { |e| "http://#{e}" }.join(',')}" ], 'RestartPolicy' => { 'Name' => 'never' }, 'HostConfig' => { 'PortBindings' => port_bindings, 'NetworkMode' => Config.lbaas[:network] } } if Config.lbaas[:log_dest] != '' @_container_def['HostConfig']['LogConfig'] = { 'Type' => 'gelf', 'Config' => { 'gelf-address' => Config.lbaas[:log_dest], 'tag' => Socket.gethostbyname(Socket.gethostname).first + '/{{.Name}}/{{.ID}}' } } end @_container = Docker::Container.create(@_container_def) end |
#image ⇒ Object
20 21 22 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 20 def image @_image ||= Docker::Image.create('fromImage' => Config.lbaas[:image]) end |
#init! ⇒ Object
11 12 13 14 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 11 def init! Docker.url = Config.lbaas[:docker_endpoint] Docker. = { connect_timeout: Config.lbaas[:docker_timeout] || 10 } end |
#pull! ⇒ Object
24 25 26 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 24 def pull! @_image = Docker::Image.create('fromImage' => Config.lbaas[:image]) end |
#remove! ⇒ Object
71 72 73 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 71 def remove! self.container.delete end |
#start! ⇒ Object
79 80 81 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 79 def start! self.container.start end |
#stop! ⇒ Object
83 84 85 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 83 def stop! self.container.stop end |
#up? ⇒ Boolean
75 76 77 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 75 def up? self.container.json['State']['Running'] end |
#update! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 57 def update! begin self.stop! && start = true if self.up? self.remove! self.pull! self.create! self.start! if start == true rescue StandardError => e Logger.error "UNCAUGHT EXCEPTION IN THREAD #{Thread.current[:name]}" Logger.error [' ', e.class, e.].join(' ') Logger.error ' ' + e.backtrace.to_s end end |