port-authority 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a4e10d54d910de555798deb51e4311e1182d9bc
4
- data.tar.gz: 693d8f129ab1a1102e04784be34e952561c19244
3
+ metadata.gz: 19da798e807911a92aba99e063385e16fe4df4d1
4
+ data.tar.gz: da3fe4c9ad5f824fd8fcbf49c8ef1e91ad8b392a
5
5
  SHA512:
6
- metadata.gz: 8c1817f66a0872a6cab73f1628809dd6cb8b932b2aba3d673e64fca203d8138ca715df92e46c6b52b63451d704a434cfad390828cc5c6ae27ee4b5a7fec0814e
7
- data.tar.gz: bb161b523118bf5100e7e64210e92b46983c2643fde1bb4aff2ceea5b74a6def589890707ea825344ea7004a1dd54fb445a5010dd16bc63728cfc732772dd962
6
+ metadata.gz: e0e8b128d235b4271dddc7d7c9e12b191118cf6dc55f56f2d537694c17da28332764f63540cafe19e57f46bfc2224b6b5e50902ff21722aef8809b5bf1e88837
7
+ data.tar.gz: a3993e2d0677d1baccf8c0a36127a6a7c3c4fe897dbd4b5b4b77e9a830ef3b3a48ea4753f091733782e1a489deaed31a19ebdf7badb28a105fc0a3d6203d20ee
data/bin/pa-manager CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'port-authority/manager/app'
2
+ require 'port-authority/manager'
3
3
  PortAuthority::Manager::App.new('pa-manager').run
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'port-authority/services'
3
+ PortAuthority::Services::App.new.run
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
@@ -2,6 +2,9 @@ module PortAuthority
2
2
  module Manager
3
3
  end
4
4
 
5
+ module Services
6
+ end
7
+
5
8
  module Util
6
9
  end
7
10
 
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.6
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-08 00:00:00.000000000 Z
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/app.rb
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