panteras_api 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWQ2MWNmY2JiZWI4MTQ5NjlkNmI1MDFlNmI2YWI3ZWUyNDY2Y2JjMQ==
5
- data.tar.gz: !binary |-
6
- ZmM1MTM0NmYzZDU4NDllNTI0MjUxZjQ5YmMxZjI3YTE0MGI5OGEzMw==
2
+ SHA1:
3
+ metadata.gz: 04b2044a073ff5134787239d54c829a0401b5fa5
4
+ data.tar.gz: f5ca0869cdf4ed9e1e2bf151f14a17638d5ac802
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- N2ZkN2NhZDBjMDgwZjBhNTY0ZTU3MDdiY2JkYWMwM2RjNjVjODdmZmFiMTQy
10
- OGM5Mjk5ZWZiMGU4ZTQyZjAwZTkwYjc4ZGQ4NDZkMDA0YjQ0ZDlhMDJkYTQ2
11
- NTdkNjZjZmFkN2MwNmIxYmEwNjRmNTlmY2IyY2Y3NjNmMWQzMjA=
12
- data.tar.gz: !binary |-
13
- MjNiMWU2OWFmZTM5Y2NmYTBhOWMzYTI5YjE5YmEyOTJjNzdjNjkzZDlmMGVk
14
- M2M5OWI4NjFiOGNmMjA5MWM5MjA0OTVjNzYyNmMyNGIwNDgxYWVjOTE1YmRl
15
- YmM2YWM4Zjc2OTk2OTBkMDY0ZjQ4MTIzMDY0MWEwNWVlMGFhMWU=
6
+ metadata.gz: a78b15818d7a3813127fed991b1d6f0591c1f58606d878afa92ad0246c23d10458536d8e66d30dbc888b954eb9ea3fce4d3804d89da3d6513c7ad24b81450201
7
+ data.tar.gz: f53ca0840db6080f2a1aa0988bcc5f45e8997e47bc259d3014d3fe2d48160061cd32bfbd51503fc8f3a7da7c38e24e951f087e656a3e3bf77d8a80350d400c24
@@ -38,6 +38,14 @@ OptionParser.new("Usage: #{$0} [options]") do |opts|
38
38
  opts.on("-f", "--fqdn FULLY_QUALIFIED_HOSTNAME", "Default: autodiscovery via gethostbyname") do |f|
39
39
  options[:fqdn] = f
40
40
  end
41
+
42
+ opts.on("-U", "--user MARATHON_USERNAME", "default: empty") do |user|
43
+ options[:marathon_username] = user
44
+ end
45
+
46
+ opts.on("-P", "--passwd MARATHON_PASSWORD", "default: empty") do |passwd|
47
+ options[:marathon_password] = passwd
48
+ end
41
49
 
42
50
 
43
51
  end.parse!
@@ -77,7 +85,7 @@ good_news << "#{mesos_tasks.size} mesos tasks running." if ! mesos_tasks.empty?
77
85
 
78
86
 
79
87
  ### MARATHON
80
- marathon = MarathonEndpoint.new(mesos.master_hostname)
88
+ marathon = MarathonEndpoint.new(mesos.master_hostname, 8080, config[:marathon_username], config[:marathon_password])
81
89
 
82
90
  puts "#" * 75 if config[:debug]
83
91
  puts "* Marathon tasks on #{my_fqdn}:" if config[:debug]
@@ -4,8 +4,11 @@ require 'uri'
4
4
 
5
5
  module HTTPUtils
6
6
 
7
- def get_response_with_redirect(*args)
8
- response = Net::HTTP.get_response(*args)
7
+ def get_response_with_redirect(host, request_uri, port, user='', passwd='')
8
+ http = Net::HTTP::new(host, port)
9
+ req = Net::HTTP.const_get('Get').new(request_uri)
10
+ req.basic_auth user,passwd
11
+ response = http.request(req)
9
12
  if response.is_a?(Net::HTTPRedirection)
10
13
  begin
11
14
  redirect_uri = URI.parse(response.header['location'])
@@ -16,7 +19,7 @@ module HTTPUtils
16
19
  end
17
20
  response
18
21
  end
19
-
22
+
20
23
  def to_j(response)
21
24
  if response.is_a? Net::HTTPResponse
22
25
  JSON.parse(response.body, :symbolize_names => true)
@@ -37,4 +40,4 @@ module HTTPUtils
37
40
  return URI.parse(url)
38
41
  end
39
42
 
40
- end
43
+ end
@@ -2,21 +2,24 @@ class MarathonEndpoint
2
2
  include HTTPUtils
3
3
  include Utils
4
4
 
5
- def initialize(host, port=8080)
5
+ def initialize(host, port=8080, user='', passwd='')
6
6
  @host = host
7
7
  @port = port
8
+ @user = user
9
+ @passwd = passwd
8
10
  end
9
11
 
10
12
  def app(app_name)
11
13
  raise ArgumentError, "Argument be a String" unless (app_name.class == String )
12
- to_j(get_response_with_redirect(@host, '/v2/apps/' + app_name, @port))[:app]
14
+ to_j(get_response_with_redirect(@host, '/v2/apps/' + app_name, @port, @user, @passwd))[:app]
13
15
  end
14
16
 
15
17
  def all_apps
16
- to_j(get_response_with_redirect(@host, '/v2/apps/', @port))[:apps]
18
+ to_j(get_response_with_redirect(@host, '/v2/apps/', @port, @user, @passwd))[:apps]
17
19
  end
18
20
 
19
21
  def app_names
22
+ raise StandardError, "Empty response from marathon", caller if all_apps.nil?
20
23
  all_apps.collect { |a| a[:id][1..-1] }
21
24
  end
22
25
 
@@ -27,7 +27,8 @@ class MesosCluster
27
27
  if ! valid_url(redirect_response.to_s)
28
28
  raise StandardError, "Response from #{@protocol}//#{@host}:#{@port}#{@master_info} is not a valid url: #{redirect_response.to_s}"
29
29
  end
30
- return to_j(get_response_with_redirect(URI.join(redirect_response.to_s, @state_info)))
30
+ uri = construct_uri redirect_response.to_s
31
+ return to_j(get_response_with_redirect(uri.host, @state_info, uri.port))
31
32
  end
32
33
 
33
34
  end
@@ -1,3 +1,3 @@
1
1
  module PanterasApi
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panteras_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Colby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: A convenient api for getting information from consul, mesos, marathon,
@@ -90,17 +90,17 @@ require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ! '>='
93
+ - - '>='
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ! '>='
98
+ - - '>='
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.4.8
103
+ rubygems_version: 2.0.14
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Ruby API library for Panteras PaaS platform.