Class: Proxy::DHCP::KeaApi::PluginConfiguration
- Inherits:
-
Object
- Object
- Proxy::DHCP::KeaApi::PluginConfiguration
- Defined in:
- lib/smart_proxy_dhcp_kea_api/plugin_configuration.rb
Overview
This class manages the setup and configuration of the KeaApi plugin's internal components. It follows a pattern used by the Foreman Smart Proxy's dependency injection (DI) framework. Its responsibilities are divided into two main parts: loading the necessary classes into memory and then "wiring" them together by defining how each service gets created and what its dependencies are.
Instance Method Summary collapse
-
#load_classes ⇒ Object
Loads all the necessary classes for this provider into memory.
-
#load_dependency_injection_wirings(container, settings) ⇒ Object
Configures the dependency injection wirings for the KeaApi provider.
Instance Method Details
#load_classes ⇒ Object
Loads all the necessary classes for this provider into memory. This is called by the Smart Proxy before the dependency injection wirings are configured.
17 18 19 20 21 22 |
# File 'lib/smart_proxy_dhcp_kea_api/plugin_configuration.rb', line 17 def load_classes require 'dhcp_common/free_ips' require 'smart_proxy_dhcp_kea_api/kea_api_client' require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_subnet_service' require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_main' end |
#load_dependency_injection_wirings(container, settings) ⇒ Object
Configures the dependency injection wirings for the KeaApi provider. The container is responsible for creating and managing instances of our services.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/smart_proxy_dhcp_kea_api/plugin_configuration.rb', line 30 def load_dependency_injection_wirings(container, settings) # A standard in-memory key-value store provided by the Smart Proxy framework. # It's used by the SubnetService to cache DHCP data. container.singleton_dependency :memory_store, -> { ::Proxy::MemoryStore.new } # A singleton service that manages the temporary blacklisting of suggested IP addresses # to prevent race conditions. Its duration is configured via the settings file. container.singleton_dependency :unused_ips, -> { ::Proxy::DHCP::FreeIps.new(settings[:blacklist_duration_minutes]) } # The custom client for communicating with the Kea API. This is registered as a singleton # so that a single, persistent HTTP connection pool is used for all API calls. # @see Proxy::DHCP::KeaApi::Client#initialize container.singleton_dependency :kea_client, (lambda do ::Proxy::DHCP::KeaApi::Client.new( url: settings[:kea_api_url], username: settings[:kea_api_username], password: settings[:kea_api_password], open_timeout: settings[:open_timeout], read_timeout: settings[:read_timeout] ) end) # The custom service for caching all subnet, reservation, and lease data. # This is a singleton because we want one central, authoritative cache that all # requests can share. It depends on the Kea client to fetch data and the memory # stores to cache it. # @see Proxy::DHCP::KeaApi::SubnetService#initialize container.singleton_dependency :subnet_service, (lambda do memory_store = container.get_dependency(:memory_store) ::Proxy::DHCP::KeaApi::SubnetService.new( container.get_dependency(:kea_client), memory_store, memory_store, memory_store, memory_store, memory_store ) end) # The main provider class that ties everything together. This is the entry point # for handling DHCP requests from Foreman. It depends on the subnet service, # the API client, and the IP blacklist service to do its job. # @see Proxy::DHCP::KeaApi::Provider#initialize container.dependency :dhcp_provider, (lambda do ::Proxy::DHCP::KeaApi::Provider.new( container.get_dependency(:subnet_service), container.get_dependency(:kea_client), container.get_dependency(:unused_ips) ) end) end |