smart_proxy_discovery_image 1.0.5 → 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 +5 -5
 - data/lib/smart_proxy_discovery_image/power_api.rb +33 -22
 - data/lib/smart_proxy_discovery_image/version.rb +1 -1
 - metadata +13 -15
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 01103d93b909fdfc22ba01c37dd7061affb9d0440e35e041c3333c2884edaf37
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b827937012ce424a99fe4c0f1d3bb756f996971a8c496d46bbfdcf69a1deb6b2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e30242f64d5d36ab550a2ded89f3d700a4ce324d296e4243486389c2319a9d30a8c81b1830f50e285b7894609d15de8edaf554d4e5108d39103b8eb01fe1874b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4e2298339d4802460eb7f3f0fa08698bf76a034860d0944039aa690dad062c703d10cf4a4fdd60eed8242ceb9104ec011e0f1684d7c302a2acdfa179b373985f
         
     | 
| 
         @@ -7,42 +7,53 @@ module Proxy::DiscoveryImage 
     | 
|
| 
       7 
7 
     | 
    
         
             
                include Proxy::Util
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                put "/reboot" do
         
     | 
| 
       10 
     | 
    
         
            -
                  log_halt 
     | 
| 
       11 
     | 
    
         
            -
                  run_after_response 5, shutdown, "-r", "now", "Foreman  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  run_after_response 2, kexec, "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  run_after_response data, 2, kexec, "--debug", "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
         
     | 
| 
       30 
28 
     | 
    
         
             
                  { :result => true }.to_json
         
     | 
| 
       31 
29 
     | 
    
         
             
                end
         
     | 
| 
       32 
30 
     | 
    
         | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
32 
     | 
    
         
             
                # Execute command in a separate thread after 5 seconds to give the server some
         
     | 
| 
       35 
33 
     | 
    
         
             
                # time to finish the request. Does *not* execute via a shell.
         
     | 
| 
       36 
     | 
    
         
            -
                def run_after_response(seconds, *command)
         
     | 
| 
       37 
     | 
    
         
            -
                  logger.debug "BMC shell execution scheduled in #{seconds} seconds"
         
     | 
| 
      
 34 
     | 
    
         
            +
                def run_after_response(data, seconds, *command)
         
     | 
| 
       38 
35 
     | 
    
         
             
                  Thread.start do
         
     | 
| 
       39 
36 
     | 
    
         
             
                    begin
         
     | 
| 
       40 
     | 
    
         
            -
                       
     | 
| 
       41 
     | 
    
         
            -
                      logger.debug " 
     | 
| 
       42 
     | 
    
         
            -
                       
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                       
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                      # download kernel and initramdisk
         
     | 
| 
      
 38 
     | 
    
         
            +
                      logger.debug "Downloading: #{data['kernel']}"
         
     | 
| 
      
 39 
     | 
    
         
            +
                      vmlinuz_thread = ::Proxy::HttpDownload.new(data['kernel'], '/tmp/vmlinuz').start
         
     | 
| 
      
 40 
     | 
    
         
            +
                      logger.error("vmlinuz is still downloading, ignored") unless vmlinuz_thread
         
     | 
| 
      
 41 
     | 
    
         
            +
                      logger.error("cannot download vmlinuz for kexec") unless vmlinuz_thread.join == 0
         
     | 
| 
      
 42 
     | 
    
         
            +
                      logger.debug "Downloading: #{data['initram']}"
         
     | 
| 
      
 43 
     | 
    
         
            +
                      initrd_thread = ::Proxy::HttpDownload.new(data['initram'], '/tmp/initrd.img').start
         
     | 
| 
      
 44 
     | 
    
         
            +
                      logger.error("initrd.img is still downloading, ignored") unless initrd_thread
         
     | 
| 
      
 45 
     | 
    
         
            +
                      logger.error("cannot download initrd.img for kexec") unless initrd_thread.join == 0
         
     | 
| 
      
 46 
     | 
    
         
            +
                      # wait few seconds just in case the download was fast and perform kexec
         
     | 
| 
      
 47 
     | 
    
         
            +
                      # only perform kexec when both locks were available to prevent subsequent request while downloading
         
     | 
| 
      
 48 
     | 
    
         
            +
                      if vmlinuz_thread && initrd_thread
         
     | 
| 
      
 49 
     | 
    
         
            +
                        logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
         
     | 
| 
      
 50 
     | 
    
         
            +
                        sleep seconds
         
     | 
| 
      
 51 
     | 
    
         
            +
                        logger.debug "Power API executing: #{command.inspect}"
         
     | 
| 
      
 52 
     | 
    
         
            +
                        if (sudo = which('sudo'))
         
     | 
| 
      
 53 
     | 
    
         
            +
                          status = system(sudo, *command)
         
     | 
| 
      
 54 
     | 
    
         
            +
                        else
         
     | 
| 
      
 55 
     | 
    
         
            +
                          logger.warn "sudo binary was not found"
         
     | 
| 
      
 56 
     | 
    
         
            +
                        end
         
     | 
| 
       46 
57 
     | 
    
         
             
                      end
         
     | 
| 
       47 
58 
     | 
    
         
             
                      # only report errors
         
     | 
| 
       48 
59 
     | 
    
         
             
                      logger.warn "The attempted command failed with code #{$?.exitstatus}" unless status
         
     | 
    
        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 
     | 
    
         
            +
              version: 1.2.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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-06-18 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,20 +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
         
     | 
| 
       22 
28 
     | 
    
         
             
            - lib/smart_proxy_discovery_image/inventory_api.rb
         
     | 
| 
       23 
29 
     | 
    
         
             
            - lib/smart_proxy_discovery_image/plugin.rb
         
     | 
| 
       24 
30 
     | 
    
         
             
            - lib/smart_proxy_discovery_image/power_api.rb
         
     | 
| 
       25 
     | 
    
         
            -
            - lib/smart_proxy_discovery_image/http_config.ru
         
     | 
| 
       26 
31 
     | 
    
         
             
            - lib/smart_proxy_discovery_image/version.rb
         
     | 
| 
       27 
     | 
    
         
            -
            - lib/smart_proxy_discovery_image.rb
         
     | 
| 
       28 
     | 
    
         
            -
            - bundler.d/discovery_image.rb
         
     | 
| 
       29 
32 
     | 
    
         
             
            - settings.d/discovery_image.yml.example
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
            - LICENSE
         
     | 
| 
       32 
     | 
    
         
            -
            - README.md
         
     | 
| 
       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: {}
         
     | 
| 
       37 
37 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       38 
38 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
         @@ -40,19 +40,17 @@ require_paths: 
     | 
|
| 
       40 
40 
     | 
    
         
             
            - lib
         
     | 
| 
       41 
41 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       42 
42 
     | 
    
         
             
              requirements:
         
     | 
| 
       43 
     | 
    
         
            -
              - -  
     | 
| 
      
 43 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       44 
44 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       45 
45 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       46 
46 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       47 
47 
     | 
    
         
             
              requirements:
         
     | 
| 
       48 
     | 
    
         
            -
              - -  
     | 
| 
      
 48 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       49 
49 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       50 
50 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       51 
51 
     | 
    
         
             
            requirements: []
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
            rubygems_version: 2.0.14
         
     | 
| 
      
 52 
     | 
    
         
            +
            rubygems_version: 3.0.3
         
     | 
| 
       54 
53 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       55 
54 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       56 
55 
     | 
    
         
             
            summary: FDI API for Foreman Smart-Proxy
         
     | 
| 
       57 
56 
     | 
    
         
             
            test_files: []
         
     | 
| 
       58 
     | 
    
         
            -
            has_rdoc: 
         
     |