Skip to content

Commit

Permalink
feat: Add Zeitwerk loader support (theforeman#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadjaheitmann authored Oct 2, 2024
1 parent 00db43f commit c237bc0
Show file tree
Hide file tree
Showing 37 changed files with 82 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module HostsController
prepend Overrides
end
module Overrides
include ForemanFogProxmox::ProxmoxVmNew
include ForemanFogProxmox::ProxmoxVMNew
# Clone the host
def clone
super
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_attrs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmAttrsHelper
module ProxmoxVMAttrsHelper
def object_to_attributes_hash(vms, from_profile, start_checked)
param_scope = from_profile ? "compute_attribute[vm_attrs]" : "host[compute_attributes]"
vm_h = ActiveSupport::HashWithIndifferentAccess.new
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_cdrom_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmCdromHelper
module ProxmoxVMCdromHelper
def parse_server_cdrom(args)
cdrom_media = args['cdrom'] if args.key?('cdrom')
cdrom_image = args['volid'] if args.key?('volid')
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_cloudinit_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmCloudinitHelper
module ProxmoxVMCloudinitHelper
def parse_server_cloudinit(args)
cloudinit_h = {}
cloudinit = args['cloudinit']
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmConfigHelper
module ProxmoxVMConfigHelper
def object_to_config_hash(vm, type)
vm_h = ActiveSupport::HashWithIndifferentAccess.new
main_a = ['vmid', 'type']
Expand Down
10 changes: 5 additions & 5 deletions app/helpers/proxmox_vm_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
require 'fog/proxmox/helpers/nic_helper'
require 'foreman_fog_proxmox/value'

module ProxmoxVmHelper
include ProxmoxVmInterfacesHelper
include ProxmoxVmVolumesHelper
include ProxmoxVmConfigHelper
include ProxmoxVmOsTemplateHelper
module ProxmoxVMHelper
include ProxmoxVMInterfacesHelper
include ProxmoxVMVolumesHelper
include ProxmoxVMConfigHelper
include ProxmoxVMOsTemplateHelper

def vm_collection(type)
collection = :servers
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_interfaces_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmInterfacesHelper
module ProxmoxVMInterfacesHelper
def parsed_typed_interfaces(args, type, parsed_vm)
interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(args, type)
interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_os_template_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require 'foreman_fog_proxmox/value'
require 'foreman_fog_proxmox/hash_collection'

module ProxmoxVmOsTemplateHelper
module ProxmoxVMOsTemplateHelper
def ostemplate_keys
['ostemplate_storage', 'ostemplate_file']
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/proxmox_vm_uuid_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

module ProxmoxVmUuidHelper
module ProxmoxVMUuidHelper
UUID_REGEXP = /(?<cluster_id>\d+)_(?<vmid>\d+)/.freeze
def extract(uuid, name)
captures_h = uuid ? UUID_REGEXP.match(uuid.to_s) : { cluster_id: '', vmid: '' }
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/proxmox_vm_volumes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmVolumesHelper
include ProxmoxVmCdromHelper
include ProxmoxVmCloudinitHelper
module ProxmoxVMVolumesHelper
include ProxmoxVMCdromHelper
include ProxmoxVMCloudinitHelper

def add_disk_options(disk, args)
options = ForemanFogProxmox::HashCollection.new_hash_reject_keys(args,
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/host_ext/proxmox/for_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module HostExt
module Proxmox
module ForVm
module ForVM
extend ActiveSupport::Concern
module ClassMethods
def for_vm_uuid(cr, vm)
Expand Down
8 changes: 4 additions & 4 deletions app/models/foreman_fog_proxmox/proxmox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

module ForemanFogProxmox
class Proxmox < ComputeResource
include ProxmoxVmHelper
include ProxmoxVMHelper
include ProxmoxConnection
include ProxmoxVmNew
include ProxmoxVmCommands
include ProxmoxVmQueries
include ProxmoxVMNew
include ProxmoxVMCommands
include ProxmoxVMQueries
include ProxmoxComputeAttributes
include ProxmoxVolumes
include ProxmoxInterfaces
Expand Down
4 changes: 2 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
require 'foreman_fog_proxmox/hash_collection'

module ForemanFogProxmox
module ProxmoxVmCommands
module ProxmoxVMCommands
include ProxmoxVolumes
include ProxmoxPools
include ProxmoxVmHelper
include ProxmoxVMHelper

def start_on_boot(vm, args)
startonboot = args[:start_after_create].blank? ? false : Foreman::Cast.to_bool(args[:start_after_create])
Expand Down
4 changes: 2 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
require 'foreman_fog_proxmox/hash_collection'

module ForemanFogProxmox
module ProxmoxVmNew
include ProxmoxVmHelper
module ProxmoxVMNew
include ProxmoxVMHelper

def cdrom_defaults
{ storage_type: 'cdrom', id: 'ide2', volid: 'none', media: 'cdrom' }
Expand Down
4 changes: 2 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

module ForemanFogProxmox
module ProxmoxVmQueries
module ProxmoxVMQueries
include ProxmoxPools
include ProxmoxVmUuidHelper
include ProxmoxVMUuidHelper

def nodes
nodes = client.nodes.all if client
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

module ForemanFogProxmox
module ProxmoxVolumes
include ProxmoxVmHelper
include ProxmoxVMHelper

def delete_volume(vm, id, volume_attributes)
logger.info("vm #{vm.identity} delete volume #{id}")
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20210312105013_update_proxmox_uuid_host.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include ProxmoxVmUuidHelper
include ProxmoxVMUuidHelper
class UpdateProxmoxUuidHost < ActiveRecord::Migration[6.0]
def up
execute(sql(:concat))
Expand Down
49 changes: 22 additions & 27 deletions lib/foreman_fog_proxmox/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,34 @@ module ForemanFogProxmox
class Engine < ::Rails::Engine
engine_name 'foreman_fog_proxmox'

config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
config.autoload_paths += Dir["#{config.root}/app/services/concerns"]
config.autoload_paths += Dir["#{config.root}/app/overrides"]
config.autoload_paths += Dir["#{config.root}/app/services"]

# Add any db migrations
initializer 'foreman_fog_proxmox.load_app_instance_data' do |app|
ForemanFogProxmox::Engine.paths['db/migrate'].existent.each do |path|
app.config.paths['db/migrate'] << path
end
end

initializer 'foreman_fog_proxmox.register_plugin', :before => :finisher_hook do |_app|
Foreman::Plugin.register :foreman_fog_proxmox do
requires_foreman '>= 1.22.0'
# Add Global files for extending foreman-core components and routes
register_global_js_file 'global'
# Register Proxmox VE compute resource in foreman
compute_resource ForemanFogProxmox::Proxmox
parameter_filter(ComputeResource, :uuid)
# add dashboard widget
widget 'foreman_fog_proxmox_widget', name: N_('Foreman Fog Proxmox widget'), sizex: 8, sizey: 1
security_block :foreman_fog_proxmox do
permission :view_compute_resources, { :'foreman_fog_proxmox/compute_resources' =>
[:ostemplates_by_id_and_node_and_storage,
:isos_by_id_and_node_and_storage,
:ostemplates_by_id_and_node,
:isos_by_id_and_node,
:storages_by_id_and_node,
:iso_storages_by_id_and_node,
:bridges_by_id_and_node] }
initializer 'foreman_fog_proxmox.register_plugin', :before => :finisher_hook do |app|
app.reloader.to_prepare do
Foreman::Plugin.register :foreman_fog_proxmox do
requires_foreman '>= 1.22.0'
# Add Global files for extending foreman-core components and routes
register_global_js_file 'global'
# Register Proxmox VE compute resource in foreman
compute_resource ForemanFogProxmox::Proxmox
parameter_filter(ComputeResource, :uuid)
# add dashboard widget
widget 'foreman_fog_proxmox_widget', name: N_('Foreman Fog Proxmox widget'), sizex: 8, sizey: 1
security_block :foreman_fog_proxmox do
permission :view_compute_resources, { :'foreman_fog_proxmox/compute_resources' =>
[:ostemplates_by_id_and_node_and_storage,
:isos_by_id_and_node_and_storage,
:ostemplates_by_id_and_node,
:isos_by_id_and_node,
:storages_by_id_and_node,
:iso_storages_by_id_and_node,
:bridges_by_id_and_node] }
end
end
end
end
Expand Down Expand Up @@ -112,7 +107,7 @@ class Engine < ::Rails::Engine
::Host::Managed.include Orchestration::Proxmox::Compute
::Host::Managed.include HostExt::Proxmox::Interfaces
::Host::Managed.include HostExt::Proxmox::Associator
::Host::Base.include HostExt::Proxmox::ForVm
::Host::Base.include HostExt::Proxmox::ForVM
::ComputeResourceHostAssociator.include ForemanFogProxmox::ComputeResourceHostAssociator
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

module ForemanFogProxmox
class ProxmoxContainerHelperTest < ActiveSupport::TestCase
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'parse' do
setup { Fog.mock! }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

module ForemanFogProxmox
class ProxmoxServerHelperTest < ActiveSupport::TestCase
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'parse' do
setup { Fog.mock! }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
require 'fog/proxmox/compute/models/tasks'

module ForemanFogProxmox
class ProxmoxVmHelperTest < ActiveSupport::TestCase
include ProxmoxVmHelper
class ProxmoxVMHelperTest < ActiveSupport::TestCase
include ProxmoxVMHelper

let(:container) do
service = mock('service')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
require 'test_plugin_helper'

module ForemanFogProxmox
class ProxmoxVmUuidHelperTest < ActiveSupport::TestCase
include ProxmoxVmUuidHelper
class ProxmoxVMUuidHelperTest < ActiveSupport::TestCase
include ProxmoxVMUuidHelper

describe 'extract_vmid' do
setup { Fog.mock! }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
require 'test_plugin_helper'

module ForemanFogProxmox
class ProxmoxVmVolumesHelperTest < ActiveSupport::TestCase
include ProxmoxVmVolumesHelper
class ProxmoxVMVolumesHelperTest < ActiveSupport::TestCase
include ProxmoxVMVolumesHelper

describe 'remove_deletes' do
setup { Fog.mock! }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ProxmoxComputeAttributesTest < ActiveSupport::TestCase
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxContainerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'host_compute_attrs' do
before do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman_fog_proxmox/proxmox_images_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require 'active_support/core_ext/hash/indifferent_access'

module ForemanFogProxmox
class ProxmoxVmCommandsServerTest < ActiveSupport::TestCase
class ProxmoxVMCommandsServerTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers

describe 'clone_from_image' do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxContainerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'host_interfaces_attrs' do
before do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman_fog_proxmox/proxmox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ProxmoxTest < ActiveSupport::TestCase
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxContainerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

should validate_presence_of(:url)
should validate_presence_of(:user)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman_fog_proxmox/proxmox_version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
module ForemanFogProxmox
class ProxmoxVersionTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers
include ProxmoxVmHelper
include ProxmoxVMHelper

wrong_version = { version: '5.a', release: '5.a-1' }.with_indifferent_access
supported_version = { version: '5.4', release: '5.4-3' }.with_indifferent_access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
require 'active_support/core_ext/hash/indifferent_access'

module ForemanFogProxmox
class ProxmoxVmCommandsContainerTest < ActiveSupport::TestCase
class ProxmoxVMCommandsContainerTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers
include ProxmoxNodeMockFactory
include ProxmoxContainerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'save_vm' do
before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
require 'active_support/core_ext/hash/indifferent_access'

module ForemanFogProxmox
class ProxmoxVmCommandsServerCreateTest < ActiveSupport::TestCase
class ProxmoxVMCommandsServerCreateTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'create_vm' do
it 'raises Foreman::Exception when vmid <= 100 and vmid > 0' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
require 'active_support/core_ext/hash/indifferent_access'

module ForemanFogProxmox
class ProxmoxVmCommandsServerUpdateCdromTest < ActiveSupport::TestCase
class ProxmoxVMCommandsServerUpdateCdromTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'save_vm' do
before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
require 'active_support/core_ext/hash/indifferent_access'

module ForemanFogProxmox
class ProxmoxVmCommandsServerUpdateCloudinitTest < ActiveSupport::TestCase
class ProxmoxVMCommandsServerUpdateCloudinitTest < ActiveSupport::TestCase
include ComputeResourceTestHelpers
include ProxmoxNodeMockFactory
include ProxmoxServerMockFactory
include ProxmoxVmHelper
include ProxmoxVMHelper

describe 'save_vm' do
before do
Expand Down
Loading

0 comments on commit c237bc0

Please sign in to comment.