Sha256: d295446a95f63d1f1f0b9f11938442c233ba6d4be627c3f34e5fbbe9e5927cb0

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 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_filter :find_host, :only => :host

        # 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.new(tmpl).generate do |iso|
            send_data File.read(iso), :filename => "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
          end
        end

        api :GET, '/hosts/:host_id', N_('Download host image')
        param :host_id, :identifier_dottable, :required => true
        def host
          host = @disk
          tmpl = host.bootdisk_template_render
          ForemanBootdisk::ISOGenerator.new(tmpl).generate do |iso|
            send_data File.read(iso), :filename => "#{host.name}.iso"
          end
        end

        private

        def action_permission
          case params[:action]
            when 'generic'
              :download
            when 'host'
              :view
          else
            super
          end
        end

        def find_host
          find_resource('hosts')
        end

        def resource_class
          Host::Managed
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_bootdisk-3.1.1 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
foreman_bootdisk-3.1.0 app/controllers/foreman_bootdisk/api/v2/disks_controller.rb