Sha256: 0dccc19f7d6e425c0183bd019ae1bb00eef89d5a0f04868cb301dcf719092343

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

require 'uri'

module ForemanBootdisk
  module Api
    module V2
      class DisksController < ::Api::V2::BaseController
        include ::Api::Version2

        resource_description do
          api_base_url "/bootdisk/api"
        end

        before_action :find_resource, :only => :host
        skip_after_action :log_response_body

        # no-op, but required for apipie documentation
        api :GET, '', N_('Boot disks')
        def index; end

        api :GET, '/generic', N_('Download generic image')
        def generic
          tmpl = ForemanBootdisk::Renderer.new.generic_template_render
          ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
            send_data read_file(iso), :filename => "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
          end
        end

        api :GET, '/hosts/:host_id', N_('Download host image')
        param :full, :bool, :required => false, :desc => N_('True for full, false for basic reusable image')
        param :host_id, :identifier_dottable, :required => true
        def host
          host = @disk
          if params[:full]
            ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
              send_data read_file(iso), :filename => "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
            end
          else
            tmpl = host.bootdisk_template_render
            ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
              send_data read_file(iso), :filename => "#{host.name}.iso"
            end
          end
        end

        private

        def read_file(filename)
          File.read(filename)
        end

        def resource_scope
          Host::Managed.authorized('view_hosts')
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_bootdisk-12.0.1 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-13.0.0 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-12.0.0 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-11.0.0 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-10.0.2 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-10.0.1 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-10.0.0 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb