smart_proxy_pulp 1.0.1 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 122c90c7a6e896cc2e3ebc15ac974f289047c1e3
4
- data.tar.gz: 62d073204449a0dfa2846c67832a0d4eeb72aeb7
3
+ metadata.gz: 449eb101bce06ca7d526b94e2d5f1ac5c494cfcd
4
+ data.tar.gz: e572ad1882b60f02d023a6fcabe7ec8500cedb0b
5
5
  SHA512:
6
- metadata.gz: 9c51b3ffc313b5e083664ae9d0f3852ccbbf26ab72db0daea8dd5161f0a095c7fd0e8c6d736059ab4f758dd6c310d37242f46e1b538938a6595ba0a3f39ec111
7
- data.tar.gz: c739d6ee6f3acae5554f9005537215202ecf3c1678e40014cc0e87d7795370b1468f608a625bf24faf56807413b083515cedd12bf40d20ff3481d5d012d1efa6
6
+ metadata.gz: a5dd127eb6ea63480e5ff35121f7a56159eb321db7ae55ce1cf2f50b0a42642d6adbced81e65285adb781a2065e1fddfa4c7620674ac8ba1673bda8feb2de4ad
7
+ data.tar.gz: b8d31112946962ef098b5b899002b7200e5d6326d19137b2448624896e3f5baa4a606171fb3f3820635471ccfdf7ff892488fe94bfc7718474b57a1891afb597
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  group :development do
5
- gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy"
5
+ gem 'smart_proxy', :git => 'https://github.com/theforeman/smart-proxy', :branch => 'develop'
6
6
  end
@@ -0,0 +1,81 @@
1
+ module PulpProxy
2
+ class DiskUsage
3
+ include ::Proxy::Util
4
+ include ::Proxy::Log
5
+ SIZE = { :kilobyte => 1_024, :megabyte => 1_048_576, :gigabyte => 1_073_741_824, :terabyte => 1_099_511_627_776 }
6
+
7
+ attr_reader :path, :stat, :size
8
+
9
+ def initialize(opts ={})
10
+ raise(::Proxy::Error::ConfigurationError, 'Unable to continue - must provide a path.') if opts[:path].nil?
11
+ @paths_hash = validate_path(path_hash(opts[:path]))
12
+ @path = @paths_hash.values
13
+ @size = SIZE[opts[:size]] || SIZE[:kilobyte]
14
+ @stat = {}
15
+ find_df
16
+ get_stat
17
+ end
18
+
19
+ def to_json
20
+ stat.to_json
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :command_path
26
+
27
+ def find_df
28
+ @command_path = which('df') || raise(::Proxy::Error::ConfigurationError, 'df command was not found unable to retrieve usage information.')
29
+ end
30
+
31
+ def command
32
+ [command_path, "-B", "#{size}", *path]
33
+ end
34
+
35
+ def get_stat
36
+ raw = Open3::popen3({"LC_ALL" => "C"}, *command) do |stdin, stdout, stderr, thread|
37
+ unless stderr.read.empty?
38
+ error_line = stderr.read
39
+ logger.error "[#{command_path}] #{error_line}"
40
+ raise(::Proxy::Error::ConfigurationError, "#{command_path} raised an error: #{error_line}")
41
+ end
42
+ stdout.read.split("\n")
43
+ end
44
+ logger.debug "[#{command_path}] #{raw.to_s}"
45
+
46
+ titles = normalize_titles(raw)
47
+ raw.each_with_index do |line, index|
48
+ mount_path = path[index]
49
+ values = normalize_values(line.split)
50
+ @stat[@paths_hash.key(mount_path)] = Hash[titles.zip(values)].merge({:path => mount_path, :size => SIZE.key(size)})
51
+ end
52
+ end
53
+
54
+ def path_hash(path)
55
+ path.is_a?(Hash) ? path : Hash[path, path]
56
+ end
57
+
58
+ def normalize_titles(raw)
59
+ replacers = {"mounted on" => :mounted, "use%" => :percent}
60
+ raw.shift.downcase.gsub(/(use%|mounted on)/) { |m| replacers.fetch(m,m)}.split.map(&:to_sym)
61
+ end
62
+
63
+ def normalize_values(values)
64
+ values.each_with_index do |value, index|
65
+ is_int = Integer(value) rescue false
66
+ values[index] = is_int if is_int
67
+ end
68
+ values
69
+ end
70
+
71
+ def validate_path(path_hash)
72
+ path_hash.each do |key, value|
73
+ unless File.readable?(value)
74
+ logger.warn "File at #{value} defined in #{key} parameter doesn't exist or is unreadable"
75
+ path_hash.delete(key)
76
+ end
77
+ end
78
+ path_hash
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,6 @@
1
1
  require 'sinatra'
2
2
  require 'smart_proxy_pulp_plugin/pulp_client'
3
+ require 'smart_proxy_pulp_plugin/disk_usage'
3
4
 
4
5
  module PulpProxy
5
6
  class Api < Sinatra::Base
@@ -17,5 +18,17 @@ module PulpProxy
17
18
  log_halt 503, "Pulp server '#{URI.parse(::PulpProxy::Plugin.settings.pulp_url.to_s).host}' is unknown"
18
19
  end
19
20
  end
21
+
22
+ get '/status/disk_usage' do
23
+ size = (params[:size] && DiskUsage::SIZE.keys.include?(params[:size].to_sym)) ? params[:size].to_sym : :kilobyte
24
+ monitor_dirs = ::PulpProxy::Plugin.settings.to_h.select { |key, _| key == :pulp_dir || key == :pulp_content_dir || key == :mongodb_dir }
25
+ begin
26
+ pulp_disk = DiskUsage.new({:path => monitor_dirs, :size => size})
27
+ pulp_disk.to_json
28
+ rescue ::Proxy::Error::ConfigurationError
29
+ log_halt 500, 'Could not find df command to evaluate disk space'
30
+ end
31
+
32
+ end
20
33
  end
21
34
  end
@@ -1,7 +1,10 @@
1
1
  module PulpMasterProxy
2
2
  class Plugin < ::Proxy::Plugin
3
3
  plugin "pulpnode", ::PulpProxy::VERSION
4
- default_settings :pulp_url => 'https://localhost/pulp'
4
+ default_settings :pulp_url => 'https://localhost/pulp',
5
+ :pulp_dir => '/var/lib/pulp',
6
+ :pulp_content_dir => '/var/lib/pulp/content',
7
+ :mongodb_dir => '/var/lib/mongodb'
5
8
 
6
9
  http_rackup_path File.expand_path("pulp_node_http_config.ru", File.expand_path("../", __FILE__))
7
10
  https_rackup_path File.expand_path("pulp_node_http_config.ru", File.expand_path("../", __FILE__))
@@ -1,9 +1,12 @@
1
1
  module PulpProxy
2
2
  class Plugin < ::Proxy::Plugin
3
3
  plugin "pulp", ::PulpProxy::VERSION
4
- default_settings :pulp_url => 'https://localhost/pulp'
4
+ default_settings :pulp_url => 'https://localhost/pulp',
5
+ :pulp_dir => '/var/lib/pulp',
6
+ :pulp_content_dir => '/var/lib/pulp/content',
7
+ :mongodb_dir => '/var/lib/mongodb'
5
8
 
6
9
  http_rackup_path File.expand_path("pulp_http_config.ru", File.expand_path("../", __FILE__))
7
10
  https_rackup_path File.expand_path("pulp_http_config.ru", File.expand_path("../", __FILE__))
8
11
  end
9
- end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module PulpProxy
2
- VERSION = "1.0.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,3 +1,7 @@
1
1
  ---
2
2
  :enabled: true
3
- #:pulp_url: https://localhost/pulp
3
+ #:pulp_url: https://localhost/pulp
4
+ # Path to pulp, pulp content and mongodb directories
5
+ #:pulp_dir: /var/lib/pulp
6
+ #:pulp_content_dir: /var/lib/pulp/content
7
+ #:mongodb_dir: /var/lib/mongodb
@@ -1,3 +1,7 @@
1
1
  ---
2
2
  :enabled: true
3
- #:pulp_url: https://localhost/pulp
3
+ #:pulp_url: https://localhost/pulp
4
+ # Path to pulp, pulp content and mongodb directories
5
+ #:pulp_dir: /var/lib/pulp
6
+ #:pulp_content_dir: /var/lib/pulp/content
7
+ #:mongodb_dir: /var/lib/mongodb
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_pulp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Dolguikh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mocha
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: webmock
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1'
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: '1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10'
83
83
  description: |2
@@ -92,6 +92,7 @@ files:
92
92
  - LICENSE
93
93
  - bundler.d/pulp.rb
94
94
  - lib/smart_proxy_pulp.rb
95
+ - lib/smart_proxy_pulp_plugin/disk_usage.rb
95
96
  - lib/smart_proxy_pulp_plugin/pulp_api.rb
96
97
  - lib/smart_proxy_pulp_plugin/pulp_client.rb
97
98
  - lib/smart_proxy_pulp_plugin/pulp_http_config.ru
@@ -111,17 +112,17 @@ require_paths:
111
112
  - lib
112
113
  required_ruby_version: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - '>='
115
+ - - ">="
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
- - - '>='
120
+ - - ">="
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  requirements: []
123
124
  rubyforge_project:
124
- rubygems_version: 2.2.2
125
+ rubygems_version: 2.4.8
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Basic Pulp support for Foreman Smart-Proxy