New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #11081 - broke out dhcp providers into modules #312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
# | ||
# Configuration file for ISC dhcp provider | ||
# | ||
|
||
#:config: /etc/dhcp/dhcpd.conf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order in this file is muddled, this used to be under a "Redhat 6" (ugh) heading with the other OSes. I'd suggest some whitespace between the config/lease sections and key/secret sections would help make it more readable. |
||
#:leases: /var/lib/dhcpd/dhcpd.leases | ||
# | ||
# Redhat 5 | ||
# | ||
#:config: /etc/dhcpd.conf | ||
# | ||
# Settings for Ubuntu | ||
# | ||
#:config: /etc/dhcp3/dhcpd.conf | ||
#:leases: /var/lib/dhcp3/dhcpd.leases | ||
|
||
# Specifies TSIG key name and secret | ||
#:key_name: secret_key_name | ||
#:key_secret: secret_key | ||
|
||
#:omapi_port: 7911 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, just put a new line between the keys and omapi_port, as the port's not part of the TSIG config |
||
|
||
# use :server setting in dhcp.yml if you are managing a dhcp server which is not localhost |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
# | ||
# Configuration file for Windows-specific 'netsh' dhcp provider | ||
# | ||
# There's currently no configuration options for this provider. | ||
# use :server setting in dhcp.yml if you are managing a dhcp server which is not localhost |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# | ||
# Configuration file for libvirtd-specific 'virsh' dhcp provider | ||
# | ||
# There's currently no configuration options for this provider. | ||
# Virsh network name is a global parameter that can be set | ||
# in the main settings.yml file in 'virsh_network' parameter. | ||
# |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'yaml' | ||
|
||
class MigrateDhcpSettings < ::Proxy::Migration | ||
KNOWN_PARAMETERS = { | ||
:enabled => [:dhcp, :enabled], | ||
:dhcp_vendor => [:dhcp, :use_provider, :old_provider_name_to_new], | ||
:dhcp_subnets => [:dhcp, :subnets], | ||
:dhcp_config => [:dhcp_isc, :config], | ||
:dhcp_leases => [:dhcp_isc, :leases], | ||
:dhcp_key_name => [:dhcp_isc, :key_name], | ||
:dhcp_key_secret => [:dhcp_isc, :key_secret], | ||
:dhcp_omapi_port => [:dhcp_isc, :omapi_port], | ||
:dhcp_server => [:dhcp, :server] | ||
} | ||
|
||
def remap_parameter(aparameter, avalue) | ||
module_name, parameter_name, converter = | ||
KNOWN_PARAMETERS.has_key?(aparameter) ? KNOWN_PARAMETERS[aparameter] : [:unknown, aparameter] | ||
|
||
converter.nil? ? [module_name, parameter_name, avalue] : [module_name, parameter_name, send(converter, avalue)] | ||
end | ||
|
||
def migrate | ||
dhcp_config = path(src_dir, "settings.d", "dhcp.yml") | ||
if !File.exist?(dhcp_config) | ||
duplicate_original_configuration | ||
return | ||
end | ||
|
||
to_migrate = YAML.load_file(dhcp_config) | ||
output = migrate_dhcp_configuration(to_migrate) | ||
copy_original_configuration_except(path("settings.d", "dhcp.yml")) | ||
write_to_files(output) | ||
end | ||
|
||
def old_provider_name_to_new(aname) | ||
if ['isc', 'native_ms', 'virsh'].include?(aname) | ||
'dhcp_' + aname | ||
else | ||
aname | ||
end | ||
end | ||
|
||
def migrate_dhcp_configuration(to_migrate) | ||
migrated = Hash.new { |h,k| h[k] = Hash.new } | ||
to_migrate.each do |option, value| | ||
module_name, parameter_name, parameter_value = remap_parameter(option, value) | ||
migrated[module_name][parameter_name] = parameter_value | ||
end | ||
migrated | ||
end | ||
|
||
def write_to_files(output) | ||
output.keys.each do |m| | ||
next if output[m].empty? || m == :unknown | ||
File.open(path(dst_dir, "settings.d", "#{m}.yml"),'w') do |f| | ||
f.write(strip_ruby_symbol_encoding(output[m].to_yaml)) | ||
if (m == :dhcp) && !output[:unknown].empty? | ||
f.write "\n# Unparsed options, please review\n" | ||
f.write(strip_ruby_symbol_encoding(output[:unknown].to_yaml).gsub(/^---/,'')) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def strip_ruby_symbol_encoding(astring) | ||
astring.gsub("!ruby/symbol ", ":").gsub("!ruby/sym ", ":") | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
class ::Proxy::ProviderFactory | ||
class << self | ||
def get_provider(provider_name, opts) | ||
def get_provider(provider_name, opts = {}) | ||
provider = ::Proxy::Plugins.find_provider(provider_name.to_sym) | ||
provider.provider_factory.call(opts) | ||
pf = provider.provider_factory | ||
pf.is_a?(Proc) ? pf.call(opts) : pf.new.get_provider(opts) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1 @@ | ||
require 'dhcp/dhcp_plugin' | ||
|
||
module Proxy::DHCP | ||
Standard = { | ||
:hostname => {:code => 12, :kind => "String" }, # The host's name | ||
:PXEClient => {:code => 60, :kind => "String" }, # Needs to be empty for foreman to function | ||
:nextServer => {:code => 66, :kind => "String" }, # From where we download the pxeboot image via TFTP | ||
:filename => {:code => 67, :kind => "String" } # The pxeboot image | ||
} | ||
SUNW = { | ||
:root_server_ip => {:code => 2, :kind => "IPAddress" }, # 192.168.216.241 | ||
:root_server_hostname => {:code => 3, :kind => "String" }, # mediahost | ||
:root_path_name => {:code => 4, :kind => "String" }, # /vol/solgi_5.10/sol10_hw0910/Solaris_10/Tools/Boot | ||
:install_server_ip => {:code => 10, :kind => "IPAddress" }, # 192.168.216.241 | ||
:install_server_name => {:code => 11, :kind => "String" }, # mediahost | ||
:install_path => {:code => 12, :kind => "String" }, # /vol/solgi_5.10/sol10_hw0910 | ||
:sysid_server_path => {:code => 13, :kind => "String" }, # 192.168.216.241:/vol/jumpstart/sysidcfg/sysidcfg_primary | ||
:jumpstart_server_path => {:code => 14, :kind => "String" } # 192.168.216.241:/vol/jumpstart | ||
} | ||
class Error < RuntimeError; end | ||
class Collision < RuntimeError; end | ||
class InvalidRecord < RuntimeError; end | ||
class AlreadyExists < RuntimeError; end | ||
|
||
def kind | ||
self.class.to_s.sub("Proxy::DHCP::","").downcase | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing "Configuration file for..." introduction.