upman-daemon 0.0.8.1 → 0.0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/upman/core/daemon.rb +3 -0
- data/lib/upman/core/register.rb +50 -0
- data/lib/upman/extensions/index.rb +36 -0
- data/lib/upman/server/socket.rb +3 -8
- data/lib/upman/utils/api.rb +7 -2
- data/lib/upman/utils/dynload.rb +11 -0
- data/lib/upman.rb +8 -5
- data/lib/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70896bf0b492b51778903072b680b0859866a07ecb11f3c5f08e95f56b36a938
|
4
|
+
data.tar.gz: 2b7d02093f844606b0010fcb49b3fda99ff13e05c1feb4f35e7f1bcda49b2f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf227befbd1ca524c9698f574cf9ae4fc0f83b172e7905ace320cb61f9a9a05fac32f87cadcdf397e71bd7129f6080f0fb4057fed520d637c698eb606a7e622c
|
7
|
+
data.tar.gz: b87d75fef10d68e7f8865494177acb934a13c62022f3beb76828769a84a5f2a8b3ca1ebccc2fa350952b7bc568c59868be7effa0c870bedb8db3b82f7c0fe70a
|
data/lib/upman/core/daemon.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Upman
|
2
|
+
module Core
|
3
|
+
class Register
|
4
|
+
include ::Upman::Utils::Helper
|
5
|
+
using SymbolizeHelper
|
6
|
+
require 'securerandom'
|
7
|
+
|
8
|
+
require 'facter'
|
9
|
+
attr_accessor :hostdata_file
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@hostdata_file = 'hostdata.yml'
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform
|
16
|
+
data = generate_host_data
|
17
|
+
info "Register Daemon running on #{data[:hostname]} with foreman_upman"
|
18
|
+
|
19
|
+
api = ::Upman::Utils::Api.new
|
20
|
+
api.post("upman/node/register", data.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_host_data
|
24
|
+
unless File.exist? @hostdata_file
|
25
|
+
data = {
|
26
|
+
:hostname => Socket.gethostbyname(Socket.gethostname).first,
|
27
|
+
:uuid => SecureRandom.uuid,
|
28
|
+
}
|
29
|
+
File.write(@hostdata_file, data.to_yaml)
|
30
|
+
end
|
31
|
+
update_node_data
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_node_data
|
35
|
+
if File.exist? @hostdata_file
|
36
|
+
data = YAML::load_file(@hostdata_file).deep_symbolize_keys
|
37
|
+
data.merge!({
|
38
|
+
:operatingsystem => Facter['operatingsystem'].value,
|
39
|
+
:rubyversion => Facter['rubyversion'].value,
|
40
|
+
:operatingsystemrelease => Facter['operatingsystemrelease'].value,
|
41
|
+
:last_sync => DateTime.now
|
42
|
+
})
|
43
|
+
File.write(@hostdata_file, data.to_yaml)
|
44
|
+
end
|
45
|
+
data
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Upman
|
2
|
+
module Extensions
|
3
|
+
class Index < ::Upman::Core::ExtensionBase
|
4
|
+
REQUEST_PATH = "index"
|
5
|
+
|
6
|
+
def register
|
7
|
+
return Servlet
|
8
|
+
end
|
9
|
+
|
10
|
+
class Servlet < ::Upman::Server::BaseServlet
|
11
|
+
|
12
|
+
include ::Upman::Utils::Dynload
|
13
|
+
|
14
|
+
# rubocop:disable Naming/MethodName
|
15
|
+
def do_GET(request, response)
|
16
|
+
# rubocop:enable Naming/MethodName
|
17
|
+
|
18
|
+
super(request, response)
|
19
|
+
response = ok(response, perform_action(request))
|
20
|
+
end
|
21
|
+
|
22
|
+
def perform_action(request)
|
23
|
+
endpoints = []
|
24
|
+
hostname = request.request_uri.to_s.sub(request.script_name, '')
|
25
|
+
::Upman::Core::Config.daemon[:extensions].each do |extension|
|
26
|
+
ext_obj = dynload("Upman::Extensions::#{extension.split('_').map(&:capitalize).join('')}")
|
27
|
+
endpoints.append "#{hostname}/#{ext_obj ::REQUEST_PATH}.do"
|
28
|
+
end
|
29
|
+
"{\"message\": \"upman-#{::Upman::Version::VERSION} - Daemon is running\", \"endpoints\": #{endpoints.to_json}}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/upman/server/socket.rb
CHANGED
@@ -7,6 +7,7 @@ module Upman
|
|
7
7
|
class Socket
|
8
8
|
|
9
9
|
include ::Upman::Utils::Helper
|
10
|
+
include ::Upman::Utils::Dynload
|
10
11
|
|
11
12
|
include WEBrick
|
12
13
|
|
@@ -33,29 +34,23 @@ module Upman
|
|
33
34
|
Logger: WEBrick::Log.new("/dev/null"),
|
34
35
|
AccessLog: [],
|
35
36
|
)
|
37
|
+
|
36
38
|
_register_extensions(server)
|
37
39
|
|
38
40
|
protocol = @config[:ssl] ? 'https://' : 'http://'
|
39
41
|
info "Starting listener on #{protocol}#{@config[:listen]}:#{@config[:port]}"
|
40
|
-
|
41
42
|
server.start
|
42
43
|
|
43
44
|
end
|
44
45
|
|
45
46
|
private
|
46
47
|
|
47
|
-
def _dynload(str)
|
48
|
-
str.split('::').inject(Object) do |mod, class_name|
|
49
|
-
mod.const_get(class_name)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
48
|
|
54
49
|
def _register_extensions(server)
|
55
50
|
|
56
51
|
@config[:extensions].each do |extension|
|
57
52
|
require_relative "../../upman/extensions/#{extension}"
|
58
|
-
ext_obj =
|
53
|
+
ext_obj = dynload("Upman::Extensions::#{extension.split('_').map(&:capitalize).join('')}")
|
59
54
|
info "Register /#{ext_obj ::REQUEST_PATH}.do for Upman::Extensions::#{extension.split('_').map(&:capitalize).join('')}"
|
60
55
|
ext_class = ext_obj .new
|
61
56
|
server.mount "/#{ext_obj ::REQUEST_PATH}.do", ext_class.register
|
data/lib/upman/utils/api.rb
CHANGED
@@ -10,7 +10,7 @@ module Upman
|
|
10
10
|
def check_connection
|
11
11
|
response = self.get "status"
|
12
12
|
if response.nil?
|
13
|
-
|
13
|
+
false
|
14
14
|
end
|
15
15
|
|
16
16
|
unless response.code == 200
|
@@ -24,7 +24,12 @@ module Upman
|
|
24
24
|
|
25
25
|
def post(api_endoint, data)
|
26
26
|
begin
|
27
|
-
RestClient::Request.execute method: :post,
|
27
|
+
RestClient::Request.execute method: :post,
|
28
|
+
url: _url + api_endoint,
|
29
|
+
payload: data,
|
30
|
+
headers: {:accept => :json, content_type: :json},
|
31
|
+
user: Upman::Core::Config.foreman_api[:username],
|
32
|
+
password: Upman::Core::Config.foreman_api[:password]
|
28
33
|
rescue RestClient::Unauthorized
|
29
34
|
fail "API Endpoint could not validate your credentials. Please check username or password"
|
30
35
|
rescue OpenSSL::SSL::SSLError
|
data/lib/upman.rb
CHANGED
@@ -6,28 +6,31 @@ require_relative 'upman/utils/symbolize_helper'
|
|
6
6
|
require_relative 'upman/utils/helper'
|
7
7
|
require_relative 'upman/utils/api'
|
8
8
|
require_relative 'upman/utils/files'
|
9
|
+
require_relative 'upman/utils/dynload'
|
9
10
|
require_relative 'upman/utils/parser'
|
10
11
|
|
12
|
+
require_relative 'upman/core/register'
|
11
13
|
require_relative 'upman/core/daemon'
|
12
14
|
require_relative 'upman/core/config'
|
13
15
|
require_relative 'upman/core/extension_base'
|
14
16
|
require_relative 'upman/core/worker'
|
15
17
|
|
18
|
+
|
16
19
|
require_relative 'upman/server/socket'
|
17
20
|
require_relative 'upman/server/base_servlet'
|
18
21
|
|
19
22
|
module Upman
|
20
23
|
def self.run!(options)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
config_file = nil
|
25
|
+
config_file = "config.yml" if File.exist? "config.yml"
|
26
|
+
config_file = "/etc/upman/config.yml" if File.exist? "/etc/upman/config.yml"
|
24
27
|
|
25
|
-
if
|
28
|
+
if config_file.nil?
|
26
29
|
p "Can not find configuration file in /etc/upman/config.yml"
|
27
30
|
return nil
|
28
31
|
end
|
29
32
|
|
30
|
-
Core::Config.load!(
|
33
|
+
Core::Config.load!(config_file)
|
31
34
|
Core::Daemon.new(options).run!
|
32
35
|
end
|
33
36
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upman-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.8.
|
4
|
+
version: 0.0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Ehrig
|
@@ -88,14 +88,17 @@ files:
|
|
88
88
|
- lib/upman/core/config.rb
|
89
89
|
- lib/upman/core/daemon.rb
|
90
90
|
- lib/upman/core/extension_base.rb
|
91
|
+
- lib/upman/core/register.rb
|
91
92
|
- lib/upman/core/worker.rb
|
92
93
|
- lib/upman/extensions/get_install_history.rb
|
93
94
|
- lib/upman/extensions/get_installed_packages.rb
|
95
|
+
- lib/upman/extensions/index.rb
|
94
96
|
- lib/upman/extensions/install_package.rb
|
95
97
|
- lib/upman/extensions/ping.rb
|
96
98
|
- lib/upman/server/base_servlet.rb
|
97
99
|
- lib/upman/server/socket.rb
|
98
100
|
- lib/upman/utils/api.rb
|
101
|
+
- lib/upman/utils/dynload.rb
|
99
102
|
- lib/upman/utils/files.rb
|
100
103
|
- lib/upman/utils/helper.rb
|
101
104
|
- lib/upman/utils/parser.rb
|