Class: PortAuthority::Etcd
- Inherits:
-
Etcd::Client
- Object
- Etcd::Client
- PortAuthority::Etcd
- Defined in:
- lib/port-authority/etcd.rb
Class Method Summary collapse
Instance Method Summary collapse
- #am_i_swarm_leader? ⇒ Boolean
- #swarm_leader ⇒ Object
- #swarm_list_services(network, service_name = '.*') ⇒ Object
- #swarm_overlay_id(name) ⇒ Object
Class Method Details
.cluster_connect(config) ⇒ Object
7 8 9 10 11 |
# File 'lib/port-authority/etcd.rb', line 7 def self.cluster_connect(config) endpoints = config[:endpoints].map {|ep| Hash[[:host, :port].zip(ep.match(/^(?:https?:\/\/)?([0-9a-zA-Z\.-_]+):([0-9]+)\/?/).captures)]} timeout = config[:timeout].to_i PortAuthority::Etcd.new(cluster: endpoints, read_timeout: timeout) end |
.shell_cluster_connect(env, timeout = 2) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/port-authority/etcd.rb', line 13 def self.shell_cluster_connect(env, timeout = 2) env.split(',').each do |u| (host, port) = u.gsub(/^https?:\/\//, '').gsub(/\/$/, '').split(':') etcd = PortAuthority::Etcd.new(cluster: [{ host: host, port: port }], read_timeout: timeout) return etcd if etcd.healthy? next end raise Etcd::ClusterConnectError end |
Instance Method Details
#am_i_swarm_leader? ⇒ Boolean
28 29 30 |
# File 'lib/port-authority/etcd.rb', line 28 def am_i_swarm_leader? Socket.ip_address_list.map(&:ip_address).member?(swarm_leader) end |
#swarm_leader ⇒ Object
24 25 26 |
# File 'lib/port-authority/etcd.rb', line 24 def swarm_leader get('/_pa/docker/swarm/leader').value.split(':').first end |
#swarm_list_services(network, service_name = '.*') ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/port-authority/etcd.rb', line 38 def swarm_list_services(network, service_name='.*') services = {} self.get_hash("/_pa/docker/network/v1.0/endpoint/#{(network)}").each_value do |container| next unless Regexp.new(service_name).match container['name'] services = { container['name'] => { 'id' => container['id'], 'ip' => container['ep_iface']['addr'].sub(/\/[0-9]+$/, ''), 'ports' => container['exposed_ports'].map { |port| port['Port'] } } } end services end |
#swarm_overlay_id(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/port-authority/etcd.rb', line 32 def (name) get_hash('/_pa/docker/network/v1.0/network').each_value do |network| return network['id'] if network['name'] == name end end |