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
17 18 19 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 17 def container @_container ||= Docker::Container.get(Config.lbaas[:name]) rescue nil end |
#create! ⇒ Object
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 55 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 29 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
21 22 23 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 21 def image @_image ||= Docker::Image.create('fromImage' => Config.lbaas[:image]) end |
#init! ⇒ Object
11 12 13 14 15 |
# 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 } self.container || ( self.pull! && self.create! ) end |
#pull! ⇒ Object
25 26 27 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 25 def pull! @_image = Docker::Image.create('fromImage' => Config.lbaas[:image]) end |
#remove! ⇒ Object
72 73 74 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 72 def remove! @_container.delete end |
#start! ⇒ Object
80 81 82 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 80 def start! @_container.start end |
#stop! ⇒ Object
84 85 86 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 84 def stop! @_container.stop end |
#up? ⇒ Boolean
76 77 78 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 76 def up? @_container.json['State']['Running'] end |
#update! ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/port-authority/mechanism/load_balancer.rb', line 58 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 |