Sha256: 0e3ace578e8b24b144af12913c6bf10c822108aacff8eae2db1071f876f72931

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module ForemanDiscovery::NodeAPI
  class Power
    class << self
      def service(data)
        PowerService.new(data)
      end

      def legacy_direct_service(data)
        PowerLegacyDirectService.new(data)
      end

      def legacy_proxied_service(data)
        PowerLegacyProxiedService.new(data)
      end
    end
  end

  class PowerService < NodeResource
    def url
      @args[:url] + "/power"
    end

    def reboot
      put({}, "/reboot")
    end

    def kexec(json)
      put(json, "/kexec")
    end

  end

  # legacy /reboot call direct
  class PowerLegacyDirectService < NodeResource
    def initialize(args)
      super args
      raise ArgumentError, "Legacy direct service only supports http scheme" if scheme != 'http'
      raise ArgumentError, "Legacy direct service only supports port 8443" if port != 8443
      Foreman::Deprecation.deprecation_warning("1.11", "Discovery legacy API will be removed, use the new Power API")
    end

    def reboot
      ::ProxyAPI::BMC.new(:url => url).power :action => "cycle"
    end
  end

  # legacy /reboot call via proxy
  class PowerLegacyProxiedService < NodeResource
    def initialize(args)
      super args.merge(:proxy => true)
    end

    def reboot
      put({}, "/reboot")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_discovery-4.1.2 app/services/foreman_discovery/node_api/power.rb
foreman_discovery-4.1.1 app/services/foreman_discovery/node_api/power.rb
foreman_discovery-4.1.0 app/services/foreman_discovery/node_api/power.rb