smart_proxy_discovery_image 1.0.4 → 1.1.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: c9cc8032e81068991f7892a103cfc512f76cdfff
4
- data.tar.gz: 74eee65dc8349bf8aaf527cf88f5d6c6ae1f19a3
2
+ SHA256:
3
+ metadata.gz: 33b1e050b42bfdaa738931d647c63a8a57ba82d264770fe3713a377ee8d26761
4
+ data.tar.gz: 3c7f7b8d0ec6a82eff559184537c1d207fd317d0e83ea4e91f86cac2100758b2
5
5
  SHA512:
6
- metadata.gz: 94610057ed09b8a37d57d4b5813adc75a6a3e5f06c082a87efece5920897d79906e2480c6c5c51da3e6f2a4f6bf10835e4f9e5abe751b46e6b9383cde664dd86
7
- data.tar.gz: ba058eef91e4e2216ccf6e3ba7a4dfde159a7887f1f613f14f6bd10a30309cb17f194c525dcf3cbc60f76a4e92c14dc7ada0f933717679fda950fd09385fe752
6
+ metadata.gz: 79c394795be0c33935ef82f2396f77fefe8158a151501235544ae5ec6781cb7b31431477e1daa96ede830e8a8dd7a3deed9375b17a44b0c8c7336bfc683ea60c
7
+ data.tar.gz: c11681c80e5381cc7a0494497dd9e19337b768b404cd47395f77e81503e38ec4d527ddafe6c7d68dc8881fa1da2079dc35485cc84408bd7f847050a087ae3de3
@@ -1,5 +1,10 @@
1
1
  require 'smart_proxy_discovery_image/power_api'
2
+ require 'smart_proxy_discovery_image/inventory_api'
2
3
 
3
4
  map "/power" do
4
5
  run Proxy::DiscoveryImage::PowerApi
5
6
  end
7
+
8
+ map "/inventory" do
9
+ run Proxy::DiscoveryImage::InventoryApi
10
+ end
@@ -0,0 +1,13 @@
1
+ class Proxy::DiscoveryImage::InventoryApi < Sinatra::Base
2
+ helpers ::Proxy::Helpers
3
+
4
+ get "/facter" do
5
+ begin
6
+ content_type :json
7
+ Facter.clear
8
+ Facter.to_hash.to_json
9
+ rescue => e
10
+ log_halt 400, e
11
+ end
12
+ end
13
+ end
@@ -7,24 +7,32 @@ module Proxy::DiscoveryImage
7
7
  include Proxy::Util
8
8
 
9
9
  put "/reboot" do
10
- log_halt 500, "shutdown binary was not found" unless (shutdown = which('shutdown'))
11
- run_after_response 5, shutdown, "-r", "now", "Foreman BMC API reboot"
10
+ log_halt(500, "shutdown binary was not found") unless (shutdown = which('shutdown'))
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
- log_halt 500, "kexec binary was not found" unless (kexec = which('kexec'))
18
- data = JSON.parse request.body.read
19
-
20
- # download kernel and image synchronously (can be improved: http://projects.theforeman.org/issues/11318)
21
- wget = "#{which("wget")} --timeout=10 --tries=3 --no-check-certificate -qc "
22
- status = system("#{wget} '#{escape_for_shell(data['kernel'])}' -O /tmp/vmlinuz")
23
- log_halt 500, "Cannot download kernel: #{$?.exitstatus}" unless status
24
- status = system("#{wget} '#{escape_for_shell(data['initram'])}' -O /tmp/initrd.img")
25
- log_halt 500, "Cannot download kernel: #{$?.exitstatus}" unless status
26
-
27
- run_after_response 2, kexec, "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz"
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}"
26
+ end
27
+ logger.debug "Downloading: #{data['kernel']}"
28
+ if ::Proxy::HttpDownload.new(data['kernel'], '/tmp/vmlinuz').start.join != 0
29
+ log_halt 500, "cannot download kernel for kexec!"
30
+ end
31
+ logger.debug "Downloading: #{data['initram']}"
32
+ if ::Proxy::HttpDownload.new(data['initram'], '/tmp/initrd.img').start.join != 0
33
+ log_halt 500, "cannot download initram for kexec!"
34
+ end
35
+ run_after_response 2, kexec, "--debug", "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
28
36
  { :result => true }.to_json
29
37
  end
30
38
 
@@ -32,11 +40,11 @@ module Proxy::DiscoveryImage
32
40
  # Execute command in a separate thread after 5 seconds to give the server some
33
41
  # time to finish the request. Does *not* execute via a shell.
34
42
  def run_after_response(seconds, *command)
35
- logger.debug "BMC shell execution scheduled in #{seconds} seconds"
43
+ logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
36
44
  Thread.start do
37
45
  begin
38
46
  sleep seconds
39
- logger.debug "BMC shell executing: #{command.inspect}"
47
+ logger.debug "Power API executing: #{command.inspect}"
40
48
  if (sudo = which('sudo'))
41
49
  status = system(sudo, *command)
42
50
  else
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module DiscoveryImage
3
- VERSION = '1.0.4'
3
+ VERSION = '1.1.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.4
4
+ version: 1.1.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: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2020-06-03 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
@@ -19,19 +19,20 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - bundler.d/discovery_image.rb
26
+ - lib/smart_proxy_discovery_image.rb
27
+ - lib/smart_proxy_discovery_image/http_config.ru
28
+ - lib/smart_proxy_discovery_image/inventory_api.rb
22
29
  - lib/smart_proxy_discovery_image/plugin.rb
23
30
  - lib/smart_proxy_discovery_image/power_api.rb
24
- - lib/smart_proxy_discovery_image/http_config.ru
25
31
  - lib/smart_proxy_discovery_image/version.rb
26
- - lib/smart_proxy_discovery_image.rb
27
- - bundler.d/discovery_image.rb
28
32
  - settings.d/discovery_image.yml.example
29
- - Gemfile
30
- - LICENSE
31
- - README.md
32
- homepage: http://github.com/theforeman/smart_proxy_discovery_image
33
+ homepage: https://github.com/theforeman/smart_proxy_discovery_image
33
34
  licenses:
34
- - GPLv3
35
+ - GPL-3.0
35
36
  metadata: {}
36
37
  post_install_message:
37
38
  rdoc_options: []
@@ -39,19 +40,17 @@ require_paths:
39
40
  - lib
40
41
  required_ruby_version: !ruby/object:Gem::Requirement
41
42
  requirements:
42
- - - '>='
43
+ - - ">="
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  requirements:
47
- - - '>='
48
+ - - ">="
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  requirements: []
51
- rubyforge_project:
52
- rubygems_version: 2.0.14
52
+ rubygems_version: 3.0.3
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: FDI API for Foreman Smart-Proxy
56
56
  test_files: []
57
- has_rdoc: