smart_proxy_discovery_image 1.0.6 → 1.2.1
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5fc93e913ac9a70a9d099a12e4a7eba8139777de210569b44fb8e305e74299c
|
4
|
+
data.tar.gz: b41a1f2e085f2f7a04a33a88a6f670581d1d89ae34b6a59a497b135f12ad76ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e79b8fc34a0f3e04a99fd5f380bb9aa55699fe9d9db0b61e093173e41aa98e0340a8bc99a981b799ae669b5aec8fed82283d6c00ebd5000ced63c026cf6af94d
|
7
|
+
data.tar.gz: 6c2a81f40a1f6285a3e928cea8340a7c3ad633bd3cca2f87c1352b76f1c4599c49f94b15b5f6b8fbd4e66349c24dc9ceeba27bbfdb17d8bd85f8aa6c98f63de3
|
@@ -7,25 +7,24 @@ module Proxy::DiscoveryImage
|
|
7
7
|
include Proxy::Util
|
8
8
|
|
9
9
|
put "/reboot" do
|
10
|
-
log_halt
|
10
|
+
log_halt(500, "shutdown binary was not found") unless (shutdown = which('shutdown'))
|
11
11
|
run_after_response 5, shutdown, "-r", "now", "Foreman Power API reboot"
|
12
12
|
content_type :json
|
13
13
|
{ :result => true }.to_json
|
14
14
|
end
|
15
15
|
|
16
16
|
put "/kexec" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
logger.debug "
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
log_halt 500, "cannot download initram for kexec!"
|
17
|
+
body_data = request.body.read
|
18
|
+
# change virtual terminal out of newt screen
|
19
|
+
system("chvt", "2")
|
20
|
+
logger.debug "Initiated kexec provisioning with #{body_data}"
|
21
|
+
log_halt(500, "kexec binary was not found") unless (kexec = which('kexec'))
|
22
|
+
begin
|
23
|
+
data = JSON.parse body_data
|
24
|
+
rescue JSON::ParserError
|
25
|
+
log_halt 500, "Unable to parse kexec JSON input: #{body_data}"
|
27
26
|
end
|
28
|
-
|
27
|
+
download_and_run_after_response data, 2, kexec, "--debug", "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
|
29
28
|
{ :result => true }.to_json
|
30
29
|
end
|
31
30
|
|
@@ -33,9 +32,9 @@ module Proxy::DiscoveryImage
|
|
33
32
|
# Execute command in a separate thread after 5 seconds to give the server some
|
34
33
|
# time to finish the request. Does *not* execute via a shell.
|
35
34
|
def run_after_response(seconds, *command)
|
36
|
-
logger.debug "Power API command scheduled in #{seconds} seconds"
|
37
35
|
Thread.start do
|
38
36
|
begin
|
37
|
+
logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
|
39
38
|
sleep seconds
|
40
39
|
logger.debug "Power API executing: #{command.inspect}"
|
41
40
|
if (sudo = which('sudo'))
|
@@ -50,5 +49,32 @@ module Proxy::DiscoveryImage
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
52
|
+
|
53
|
+
# Variant which also downloads kernel and initramdisk
|
54
|
+
def download_and_run_after_response(data, seconds, *command)
|
55
|
+
Thread.start do
|
56
|
+
begin
|
57
|
+
# download kernel and initramdisk
|
58
|
+
downloaded = download_file(data, 'kernel', 'vmlinuz', '/tmp') &&
|
59
|
+
download_file(data, 'initram', 'initrd.img', '/tmp')
|
60
|
+
# wait few seconds just in case the download was fast and perform kexec
|
61
|
+
# only perform kexec when both locks were available to prevent subsequent request while downloading
|
62
|
+
run_after_response(seconds, *command) if downloaded
|
63
|
+
rescue Exception => e
|
64
|
+
logger.error "Error during command execution: #{e}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def download_file(data, kind, name, prefix)
|
70
|
+
return unless data && (url = data[kind])
|
71
|
+
|
72
|
+
logger.debug "Downloading: #{url}"
|
73
|
+
download_thread = ::Proxy::HttpDownload.new(url, File.join(prefix, name)).start
|
74
|
+
logger.error("#{name} is still downloading, ignored") unless download_thread
|
75
|
+
download_success = download_thread.join.zero?
|
76
|
+
logger.error("cannot download #{name} for kexec") unless download_success
|
77
|
+
download_success
|
78
|
+
end
|
53
79
|
end
|
54
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_discovery_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Zapletal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Smart Proxy plugin providing Image API on discovered nodes. This plugin is only
|
@@ -30,9 +30,9 @@ files:
|
|
30
30
|
- lib/smart_proxy_discovery_image/power_api.rb
|
31
31
|
- lib/smart_proxy_discovery_image/version.rb
|
32
32
|
- settings.d/discovery_image.yml.example
|
33
|
-
homepage:
|
33
|
+
homepage: https://github.com/theforeman/smart_proxy_discovery_image
|
34
34
|
licenses:
|
35
|
-
-
|
35
|
+
- GPL-3.0
|
36
36
|
metadata: {}
|
37
37
|
post_install_message:
|
38
38
|
rdoc_options: []
|
@@ -49,8 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
|
53
|
-
rubygems_version: 2.6.11
|
52
|
+
rubygems_version: 3.1.2
|
54
53
|
signing_key:
|
55
54
|
specification_version: 4
|
56
55
|
summary: FDI API for Foreman Smart-Proxy
|