diff --git a/examples/ironic_config_to_net_uuid.pp b/examples/ironic_config_to_net_uuid.pp new file mode 100644 index 00000000..f370c025 --- /dev/null +++ b/examples/ironic_config_to_net_uuid.pp @@ -0,0 +1,3 @@ +ironic_config { + 'neutron/cleaning_network': value => 'cleaning_net', transform_to => 'net_uuid'; +} diff --git a/lib/puppet/provider/ironic.rb b/lib/puppet/provider/ironic.rb index d53f2bfd..8d99b796 100644 --- a/lib/puppet/provider/ironic.rb +++ b/lib/puppet/provider/ironic.rb @@ -1,5 +1,8 @@ require 'csv' require 'puppet/util/inifile' +require 'puppet/provider/openstack' +require 'puppet/provider/openstack/auth' +require 'puppet/provider/openstack/credentials' class Puppet::Provider::Ironic < Puppet::Provider @@ -149,5 +152,24 @@ correctly configured.") end hash end - +end + +class Puppet::Provider::Ironic::OpenstackRequest + include Puppet::Provider::Openstack::Auth + + def openstack_request(service, action, properties=nil, options={}) + credentials = Puppet::Provider::Openstack::CredentialsV3.new + openstack = Puppet::Provider::Openstack + + set_credentials(credentials, get_os_vars_from_env) + unless credentials.set? + credentials.unset + set_credentials(credentials, get_os_vars_from_rcfile(rc_filename)) + end + unless credentials.set? + raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate') + end + + openstack.request(service, action, properties, credentials, options) + end end diff --git a/lib/puppet/provider/ironic_config/ini_setting.rb b/lib/puppet/provider/ironic_config/ini_setting.rb index 8f6272a1..91f5af76 100644 --- a/lib/puppet/provider/ironic_config/ini_setting.rb +++ b/lib/puppet/provider/ironic_config/ini_setting.rb @@ -1,10 +1,27 @@ +require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/ironic') + Puppet::Type.type(:ironic_config).provide( :ini_setting, :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) ) do + def self.file_path '/etc/ironic/ironic.conf' end + def to_net_uuid(name) + properties = [name, '--column', 'id'] + openstack = Puppet::Provider::Ironic::OpenstackRequest.new + res = openstack.openstack_request('network', 'show', properties) + return res[:id] + end + + def from_net_uuid(uuid) + properties = [uuid, '--column', 'name'] + openstack = Puppet::Provider::Ironic::OpenstackRequest.new + res = openstack.openstack_request('network', 'show', properties) + return res[:name] + end + end diff --git a/lib/puppet/type/ironic_config.rb b/lib/puppet/type/ironic_config.rb index 2a454ab4..acd60414 100644 --- a/lib/puppet/type/ironic_config.rb +++ b/lib/puppet/type/ironic_config.rb @@ -46,6 +46,8 @@ Puppet::Type.newtype(:ironic_config) do defaultto('') end + newparam(:transform_to) + autorequire(:package) do 'ironic-common' end diff --git a/manifests/conductor.pp b/manifests/conductor.pp index e24671e6..f226d789 100644 --- a/manifests/conductor.pp +++ b/manifests/conductor.pp @@ -61,6 +61,7 @@ # [*cleaning_network*] # (optional) UUID or name of the network to create Neutron ports on, when # booting to a ramdisk for cleaning using Neutron DHCP. +# Can not be specified together with cleaning_network_name. # Defaults to $::os_service_default # # [*cleaning_disk_erase*] @@ -83,6 +84,7 @@ # [*provisioning_network*] # (optional) Neutron network UUID or name for the ramdisk to be booted into # for provisioning nodes. Required for neutron network interface. +# Can not be specified together with provisioning_network_name. # Defaults to $::os_service_default # # [*configdrive_use_swift*] @@ -100,6 +102,18 @@ # requested. One of "netboot" or "local". # Defaults to $::os_service_default # +# [*cleaning_network_name*] +# (optional) If provided the name will be converted to UUID and set +# as value of neutron/cleaning_network option in ironic.conf +# Can not be specified together with cleaning_network. +# Defaults to undef, which leaves the configuration intact +# +# [*provisioning_network_name*] +# (optional) If provided the name will be converted to UUID and set +# as value of neutron/provisioning_network option in ironic.conf +# Can not be specified together with provisioning_network. +# Defaults to undef, which leaves the configuration intact +# # DEPRECATED # # [*cleaning_network_uuid*] @@ -143,6 +157,8 @@ class ironic::conductor ( $configdrive_use_swift = $::os_service_default, $configdrive_swift_container = $::os_service_default, $default_boot_option = $::os_service_default, + $cleaning_network_name = undef, + $provisioning_network_name = undef, # DEPRECATED $cleaning_network_uuid = undef, $provisioning_network_uuid = undef, @@ -169,6 +185,16 @@ class ironic::conductor ( $cleaning_network_real = pick($cleaning_network_uuid, $cleaning_network) $provisioning_network_real = pick($provisioning_network_uuid, $provisioning_network) + if ($cleaning_network_name and !is_service_default($cleaning_network_real)) { + fail("cleaning_network_name and cleaning_network or cleaning_network_uuid can not be \ +specified in the same time.") + } + + if ($provisioning_network_name and !is_service_default($provisioning_network_real)) { + fail("provisioning_network_name and provisioning_network or provisioning_network_uuid can not be \ +specified in the same time.") + } + if $swift_account or $swift_temp_url_key or $swift_temp_url_duration { warning("swift_account, swift_temp_url_key and swift_temp_url_duration were \ moved to ironic::glance manifest") @@ -227,8 +253,6 @@ moved to ironic::glance manifest") 'conductor/force_power_state_during_sync': value => $force_power_state_during_sync; 'conductor/automated_clean': value => $automated_clean; 'conductor/api_url': value => $api_url; - 'neutron/cleaning_network': value => $cleaning_network_real; - 'neutron/provisioning_network': value => $provisioning_network_real; 'deploy/http_url': value => $http_url_real; 'deploy/http_root': value => $http_root_real; 'deploy/erase_devices_priority': value => $erase_devices_priority; @@ -239,6 +263,26 @@ moved to ironic::glance manifest") 'deploy/default_boot_option': value => $default_boot_option; } + if $cleaning_network_name { + ironic_config { + 'neutron/cleaning_network': value => $cleaning_network_name, transform_to => 'net_uuid'; + } + } else { + ironic_config { + 'neutron/cleaning_network': value => $cleaning_network_real; + } + } + + if $provisioning_network_name { + ironic_config { + 'neutron/provisioning_network': value => $provisioning_network_name, transform_to => 'net_uuid'; + } + } else { + ironic_config { + 'neutron/provisioning_network': value => $provisioning_network_real; + } + } + # Install package if $::ironic::params::conductor_package { package { 'ironic-conductor': diff --git a/releasenotes/notes/add_net_name_to_uuid_transformation-81a91758991935d0.yaml b/releasenotes/notes/add_net_name_to_uuid_transformation-81a91758991935d0.yaml new file mode 100644 index 00000000..d468cc76 --- /dev/null +++ b/releasenotes/notes/add_net_name_to_uuid_transformation-81a91758991935d0.yaml @@ -0,0 +1,7 @@ +--- +features: + - Add the ability to specify a name string for the provisioning_network in + ironic_config using the transform_to argument. + Add ``cleaning_network_name`` and ``provisioning_network_name`` options to + ::ironic::conductor class. Theirs names will be automatically converted to + UUIDs and appropriate config options will be set. diff --git a/spec/classes/ironic_conductor_spec.rb b/spec/classes/ironic_conductor_spec.rb index 251dac94..8f51073d 100644 --- a/spec/classes/ironic_conductor_spec.rb +++ b/spec/classes/ironic_conductor_spec.rb @@ -117,6 +117,20 @@ describe 'ironic::conductor' do end end + context 'when overriding parameters' do + before :each do + params.merge!( + :provisioning_network_name => 'abc', + :cleaning_network_name => 'abc', + ) + end + it 'should set provisioning/cleaning with new value' do + is_expected.to contain_ironic_config('neutron/cleaning_network').with_value('abc').with_transform_to('net_uuid') + is_expected.to contain_ironic_config('neutron/provisioning_network').with_value('abc').with_transform_to('net_uuid') + end + end + + end on_supported_os({