port-authority 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/pa-manager +1 -1
- data/bin/pa-service-list +3 -0
- data/lib/port-authority/{manager/app.rb → manager.rb} +0 -0
- data/lib/port-authority/services.rb +97 -0
- data/lib/port-authority/util/etcd.rb +19 -0
- data/lib/port-authority.rb +3 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19da798e807911a92aba99e063385e16fe4df4d1
|
4
|
+
data.tar.gz: da3fe4c9ad5f824fd8fcbf49c8ef1e91ad8b392a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e8b128d235b4271dddc7d7c9e12b191118cf6dc55f56f2d537694c17da28332764f63540cafe19e57f46bfc2224b6b5e50902ff21722aef8809b5bf1e88837
|
7
|
+
data.tar.gz: a3993e2d0677d1baccf8c0a36127a6a7c3c4fe897dbd4b5b4b77e9a830ef3b3a48ea4753f091733782e1a489deaed31a19ebdf7badb28a105fc0a3d6203d20ee
|
data/bin/pa-manager
CHANGED
data/bin/pa-service-list
ADDED
File without changes
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
require 'etcd-tools'
|
5
|
+
require 'etcd-tools/etcd'
|
6
|
+
require 'port-authority/util/etcd'
|
7
|
+
|
8
|
+
module PortAuthority
|
9
|
+
module Services
|
10
|
+
class App
|
11
|
+
include PortAuthority::Util::Etcd
|
12
|
+
include EtcdTools::Etcd
|
13
|
+
|
14
|
+
attr_reader :etcd
|
15
|
+
|
16
|
+
def optparse
|
17
|
+
@options = Hash.new
|
18
|
+
@options[:url] = ENV['ETCDCTL_ENDPOINT']
|
19
|
+
@options[:url] ||= "http://127.0.0.1:2379"
|
20
|
+
@options[:output_yaml] = false
|
21
|
+
@options[:output_json] = false
|
22
|
+
@options[:ip_only] = false
|
23
|
+
@options[:ports] = false
|
24
|
+
@options[:service_filter] = '.*'
|
25
|
+
|
26
|
+
OptionParser.new do |opts|
|
27
|
+
opts.banner = "Lists\n\nUsage: #{$0} [OPTIONS] NETWORK_NAME"
|
28
|
+
opts.separator ""
|
29
|
+
opts.separator "Connection options:"
|
30
|
+
opts.on("-u", "--url URL", "URL endpoint of the ETCD service (ETCDCTL_ENDPOINT envvar also applies) [DEFAULT: http://127.0.0.1:2379]") do |param|
|
31
|
+
@options[:url] = param
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.separator ""
|
35
|
+
opts.separator "Filter options:"
|
36
|
+
opts.on("-s SERVICE_NAME", "--service-filter SERVICE_NAME", String, "List only services by name") do |param|
|
37
|
+
@options[:service_filter] = param
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.separator ""
|
41
|
+
opts.separator "Output options:"
|
42
|
+
opts.on("-i", "--ips", "List only IPs (text mode)") do
|
43
|
+
@options[:ip_only] = true
|
44
|
+
end
|
45
|
+
opts.on("-p", "--ports", "List exposed ports (text mode)") do
|
46
|
+
@options[:ports] = true
|
47
|
+
end
|
48
|
+
opts.on("-y", "--yaml", "Output the data as YAML") do
|
49
|
+
@options[:output_yaml] = true
|
50
|
+
end
|
51
|
+
opts.on("-j", "--json", "Output the data as JSON") do
|
52
|
+
@options[:output_json] = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.separator ""
|
56
|
+
opts.separator "Common options:"
|
57
|
+
opts.on_tail("-h", "--help", "show usage") do |param|
|
58
|
+
puts opts
|
59
|
+
exit! 0
|
60
|
+
end
|
61
|
+
end.parse!
|
62
|
+
end
|
63
|
+
|
64
|
+
def initialize
|
65
|
+
self.optparse
|
66
|
+
@network = ARGV.pop
|
67
|
+
unless @network
|
68
|
+
$stderr.puts "Missing NETWORK_NAME!"
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
@etcd = etcd_connect @options[:url]
|
72
|
+
end
|
73
|
+
|
74
|
+
def run
|
75
|
+
services = list_services(@etcd, @network, @options[:service_filter])
|
76
|
+
|
77
|
+
if @options[:output_yaml]
|
78
|
+
puts services.to_yaml
|
79
|
+
elsif @options[:output_json]
|
80
|
+
puts services.to_json
|
81
|
+
else
|
82
|
+
if @options[:ip_only]
|
83
|
+
services.each { |name, params| puts "#{params['ip']}" }
|
84
|
+
elsif @options[:ports]
|
85
|
+
services.each do |name, params|
|
86
|
+
params['ports'].each do |port|
|
87
|
+
puts "#{name} #{params['ip']}:#{port}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
else
|
91
|
+
services.each { |name, params| puts "#{name} #{params['ip']}" }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -26,6 +26,25 @@ module PortAuthority
|
|
26
26
|
Socket.ip_address_list.map(&:ip_address).member?(swarm_leader(etcd).split(':').first)
|
27
27
|
end
|
28
28
|
|
29
|
+
def overlay_id(etcd, name)
|
30
|
+
etcd.get_hash('/_pa/docker/network/v1.0/network').each_value do |network|
|
31
|
+
return network['id'] if network['name'] == name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def list_services(etcd, network, service_name='.*')
|
36
|
+
svc_filter = Regexp.new(service_name)
|
37
|
+
network_id = overlay_id(etcd, network)
|
38
|
+
services = Hash.new
|
39
|
+
etcd.get_hash("/_pa/docker/network/v1.0/endpoint/#{network_id}").each_value do |container|
|
40
|
+
next unless svc_filter.match container['name']
|
41
|
+
services[container['name']] = Hash.new
|
42
|
+
services[container['name']]['id'] = container['id']
|
43
|
+
services[container['name']]['ip'] = container['ep_iface']['addr'].sub(/\/[0-9]+$/, '')
|
44
|
+
services[container['name']]['ports'] = container['exposed_ports'].map { |port| port['Port'] }
|
45
|
+
end
|
46
|
+
services
|
47
|
+
end
|
29
48
|
end
|
30
49
|
end
|
31
50
|
end
|
data/lib/port-authority.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: port-authority
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radek 'blufor' Slavicinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: etcd
|
@@ -93,16 +93,19 @@ dependencies:
|
|
93
93
|
description: CLI Tools for PortAuthority
|
94
94
|
email: radek.slavicinsky@gmail.com
|
95
95
|
executables:
|
96
|
+
- pa-service-list
|
96
97
|
- pa-manager
|
97
98
|
extensions: []
|
98
99
|
extra_rdoc_files: []
|
99
100
|
files:
|
100
101
|
- bin/pa-manager
|
102
|
+
- bin/pa-service-list
|
101
103
|
- lib/port-authority.rb
|
102
|
-
- lib/port-authority/manager
|
104
|
+
- lib/port-authority/manager.rb
|
103
105
|
- lib/port-authority/manager/init.rb
|
104
106
|
- lib/port-authority/manager/threads/icmp.rb
|
105
107
|
- lib/port-authority/manager/threads/swarm.rb
|
108
|
+
- lib/port-authority/services.rb
|
106
109
|
- lib/port-authority/util/config.rb
|
107
110
|
- lib/port-authority/util/etcd.rb
|
108
111
|
- lib/port-authority/util/helpers.rb
|