Sha256: f704e053fc16296267ff8dde1c16ed21fbba60124531d28e5655b6030687c36f

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require 'uri'

module ForemanBootdisk
  module Api
    module V2
      class SubnetDisksController < ::Api::V2::BaseController
        include ::Api::Version2
        include AllowedActions

        rescue_from ActiveRecord::RecordNotFound, :with => :subnet_not_found
        before_action :bootdisk_type_allowed?, only: :subnet
        before_action :find_resource, only: :subnet

        skip_after_action :log_response_body

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

        api :GET, '/subnets/:subnet_id', N_('Download subnet generic image')
        param :subnet_id, :identifier_dottable, required: true
        def subnet
          subnet = @subnet_disk
          subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), subnet.name))
          tmpl_bios = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
          tmpl_efi = nil
          if subnet.httpboot
            tmpl_efi = ForemanBootdisk::Renderer.new.generic_efi_template_render(subnet)
          else
            ForemanBootdisk.logger.warn('HTTPBOOT feature is not enabled for subnet %s, UEFI may not be available for bootdisk' % subnet.name)
          end
          ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl_bios, grub: tmpl_efi) do |temp_iso_filename|
            send_file(temp_iso_filename, filename: subnet.name)
          end
        end

        private

        def resource_scope
          Subnet.authorized('view_subnets')
        end

        def subnet_not_found
          not_found ("Subnet not found by id '%s'") % params[:id]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_bootdisk-21.0.1 app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb
foreman_bootdisk-21.0.0 app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb