smart_proxy_discovery_image 1.0.7 → 1.3.0

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
- SHA1:
3
- metadata.gz: e4dc7cb1398ac217438e11f78f53d58526a2c295
4
- data.tar.gz: 1724af6417967817b778f7529996ab85a6d6650b
2
+ SHA256:
3
+ metadata.gz: 249769da7939f13c7cf220e3b347613d5999a4f06ee68f81d0c930ed1494ce59
4
+ data.tar.gz: b746dcd6207df3f11c666d55dd215a1d14da5d8ae6b7bf710ad65f6438a971a9
5
5
  SHA512:
6
- metadata.gz: b8ee13bb9505903bff9c0c989ccd2daaf6d4cec08f8efccf4b7e52759f03c4b1cd8814276c32e812d95b06831a800cc97c00f4d625482ca524c2d30e14bbc68e
7
- data.tar.gz: 738479e7aebcdd9a8e2f8cc653cdc231c2bd3b9e4c112446ff2d7993fd90242eef3de427d6389021efde1d0943ec660a76078acfac0dd0a29c530ed92ed0f5eb
6
+ metadata.gz: 6a85568d2bb0b3ef030f413c197a7d3c04f6c168e15890c968250fc04b79a47024e2e8c3ff4c4b4f213f0b2684313301bd580eeb1b53d9ac9fa03f506ab2642e
7
+ data.tar.gz: 8d0e231d24fc81b5df213585b67c5ded6b64ee4f9af3cbd1e72b4fdf65ffc15c8f6375414ab83ca14fcf081aacda4b4d00f11cf35b54abca3ce1640aabfdd8fc
@@ -15,6 +15,10 @@ module Proxy::DiscoveryImage
15
15
 
16
16
  put "/kexec" do
17
17
  body_data = request.body.read
18
+ # change virtual terminal out of newt screen
19
+ system("chvt", "2")
20
+ is_secureboot = system('mokutil --sb-state|grep enabled')
21
+ logger.debug "Secure boot is #{is_secureboot}"
18
22
  logger.debug "Initiated kexec provisioning with #{body_data}"
19
23
  log_halt(500, "kexec binary was not found") unless (kexec = which('kexec'))
20
24
  begin
@@ -22,15 +26,13 @@ module Proxy::DiscoveryImage
22
26
  rescue JSON::ParserError
23
27
  log_halt 500, "Unable to parse kexec JSON input: #{body_data}"
24
28
  end
25
- logger.debug "Downloading: #{data['kernel']}"
26
- if ::Proxy::HttpDownload.new(data['kernel'], '/tmp/vmlinuz').start.join != 0
27
- log_halt 500, "cannot download kernel for kexec!"
28
- end
29
- logger.debug "Downloading: #{data['initram']}"
30
- if ::Proxy::HttpDownload.new(data['initram'], '/tmp/initrd.img').start.join != 0
31
- log_halt 500, "cannot download initram for kexec!"
32
- end
33
- run_after_response 2, kexec, "--force", "--reset-vga", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
29
+ args = ["--debug", "--force", "--reset-vga"]
30
+ args << data['extra'] if data['extra']
31
+ args << "--kexec-file-syscall" if is_secureboot
32
+ args << "--append=#{data['append']}"
33
+ args << "--initrd=/tmp/initrd.img"
34
+ download_and_run_after_response data, 2, kexec, *args, "/tmp/vmlinuz"
35
+
34
36
  { :result => true }.to_json
35
37
  end
36
38
 
@@ -38,9 +40,9 @@ module Proxy::DiscoveryImage
38
40
  # Execute command in a separate thread after 5 seconds to give the server some
39
41
  # time to finish the request. Does *not* execute via a shell.
40
42
  def run_after_response(seconds, *command)
41
- logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
42
43
  Thread.start do
43
44
  begin
45
+ logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
44
46
  sleep seconds
45
47
  logger.debug "Power API executing: #{command.inspect}"
46
48
  if (sudo = which('sudo'))
@@ -55,5 +57,32 @@ module Proxy::DiscoveryImage
55
57
  end
56
58
  end
57
59
  end
60
+
61
+ # Variant which also downloads kernel and initramdisk
62
+ def download_and_run_after_response(data, seconds, *command)
63
+ Thread.start do
64
+ begin
65
+ # download kernel and initramdisk
66
+ downloaded = download_file(data, 'kernel', 'vmlinuz', '/tmp') &&
67
+ download_file(data, 'initram', 'initrd.img', '/tmp')
68
+ # wait few seconds just in case the download was fast and perform kexec
69
+ # only perform kexec when both locks were available to prevent subsequent request while downloading
70
+ run_after_response(seconds, *command) if downloaded
71
+ rescue Exception => e
72
+ logger.error "Error during command execution: #{e}"
73
+ end
74
+ end
75
+ end
76
+
77
+ def download_file(data, kind, name, prefix)
78
+ return unless data && (url = data[kind])
79
+
80
+ logger.debug "Downloading: #{url}"
81
+ download_thread = ::Proxy::HttpDownload.new(url, File.join(prefix, name)).start
82
+ logger.error("#{name} is still downloading, ignored") unless download_thread
83
+ download_success = download_thread.join.zero?
84
+ logger.error("cannot download #{name} for kexec") unless download_success
85
+ download_success
86
+ end
58
87
  end
59
88
  end
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module DiscoveryImage
3
- VERSION = '1.0.7'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  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.0.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Zapletal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-10 00:00:00.000000000 Z
11
+ date: 2020-09-07 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,7 +30,7 @@ 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: http://github.com/theforeman/smart_proxy_discovery_image
33
+ homepage: https://github.com/theforeman/smart_proxy_discovery_image
34
34
  licenses:
35
35
  - GPL-3.0
36
36
  metadata: {}
@@ -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
- rubyforge_project:
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