diff --git a/manifests/cell_v2/map_cell_and_hosts.pp b/manifests/cell_v2/map_cell_and_hosts.pp new file mode 100644 index 000000000..a8a632f43 --- /dev/null +++ b/manifests/cell_v2/map_cell_and_hosts.pp @@ -0,0 +1,22 @@ +# == Class: nova::cell_v2::map_cell_and_hosts +# +# Class to run the map_cell_and_hosts action for cell v2 +# +# === Parameters +# +# [*extra_params*] +# (String) Extra parameters to pass to the nova-manage commands. +# Defaults to ''. +# +class nova::cell_v2::map_cell_and_hosts ( + $extra_params = '', +) { + + include ::nova::deps + + exec { 'nova-cell_v2-map_cell_and_hosts': + path => ['/bin', '/usr/bin'], + command => "nova-manage ${extra_params} cell_v2 map_cell_and_hosts", + refreshonly => true, + } +} diff --git a/manifests/cell_v2/map_instances.pp b/manifests/cell_v2/map_instances.pp new file mode 100644 index 000000000..435753e83 --- /dev/null +++ b/manifests/cell_v2/map_instances.pp @@ -0,0 +1,47 @@ +# == Class: nova::cell_v2::map_instances +# +# Resource to run the map_instances action for cell v2 +# +# === Parameters +# +# [*cell_uuid*] +# (String) Cell UUID to map unmigrated instances to. It is recommended to use +# this rather than cell name. Either cell_uuid or cell_name must be provided. +# Defaults to undef. +# +# [*cell_name*] +# (String) Cell name to map the unmigrated instances to. We will attempt to +# extract the cell uuid using the name as the command requires a cell uuid. +# NOTE: This will not work if you have multiple cells with the same name. +# Defaults to undef. +# +# [*extra_params*] +# (String) Extra parameters to pass to the nova-manage commands. +# Defaults to ''. +# +class nova::cell_v2::map_instances ( + $cell_uuid = undef, + $cell_name = undef, + $extra_params = '', +) { + + include ::nova::deps + + if (!$cell_uuid and !$cell_name) { + fail('Either cell_uuid or cell_name must be provided') + } + + if ($cell_uuid) { + $cell_uuid_real = $cell_uuid + } else { + # NOTE(aschultz): This is what breaks if you have multiple cells with the + # same name. So that's why using cell_uuid is better. + $cell_uuid_real = "$(nova-manage cell_v2 list_cells | sed -e '1,3d' -e '\$d' | awk -F ' *| *' '\$2 == \"${cell_name}\" {print \$4}')" + } + + exec { 'nova-cell_v2-map_instances': + path => ['/bin', '/usr/bin'], + command => "nova-manage ${extra_params} cell_v2 map_instances --cell_uuid=${cell_uuid_real}", + refreshonly => true, + } +} diff --git a/releasenotes/notes/cell_v2-additional-commands-7c2a455c9eb722d1.yaml b/releasenotes/notes/cell_v2-additional-commands-7c2a455c9eb722d1.yaml new file mode 100644 index 000000000..f944c7873 --- /dev/null +++ b/releasenotes/notes/cell_v2-additional-commands-7c2a455c9eb722d1.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Add classes to expose refreshonly versions of the + "nova-manage cell_v2 map_cell_and_hosts" and + "nova-manage cell_v2 map_instances" commands that can be used to manage + cell v2. diff --git a/spec/classes/nova_cell_v2_map_cell_and_hosts_spec.rb b/spec/classes/nova_cell_v2_map_cell_and_hosts_spec.rb new file mode 100644 index 000000000..47aa8aaa2 --- /dev/null +++ b/spec/classes/nova_cell_v2_map_cell_and_hosts_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe 'nova::cell_v2::map_cell_and_hosts' do + + shared_examples_for 'nova::cell_v2::map_cell_and_hosts' do + context 'with defaults' do + + it { + is_expected.to contain_exec('nova-cell_v2-map_cell_and_hosts').with( + :path => ['/bin', '/usr/bin'], + :command => 'nova-manage cell_v2 map_cell_and_hosts', + :refreshonly => true, + ) + } + end + + context "overriding extra_params" do + let :params do + { + :extra_params => '--config-file /etc/nova/nova.conf' + } + end + + it { + is_expected.to contain_exec('nova-cell_v2-map_cell_and_hosts').with( + :path => ['/bin', '/usr/bin'], + :command => 'nova-manage --config-file /etc/nova/nova.conf cell_v2 map_cell_and_hosts', + :refreshonly => true, + ) + } + end + end + + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + it_configures 'nova::cell_v2::map_cell_and_hosts' + end + end + +end diff --git a/spec/classes/nova_cell_v2_map_instances.rb b/spec/classes/nova_cell_v2_map_instances.rb new file mode 100644 index 000000000..4c0c148ab --- /dev/null +++ b/spec/classes/nova_cell_v2_map_instances.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'nova::cell_v2::map_instances' do + + shared_examples_for 'nova::cell_v2::map_instances' do + context 'with defaults' do + let (:params) { { :cell_uuid => 'uuid' } } + + it { + is_expected.to contain_exec('nova-cell_v2-map_instances').with( + :path => ['/bin', '/usr/bin'], + :command => 'nova-manage cell_v2 map_instances --cell_uuid=uuid', + :refreshonly => true, + ) + } + end + + context "overriding extra_params" do + let :params do + { + :extra_params => '--config-file /etc/nova/nova.conf', + :cell_uuid => 'uuid' + } + end + + it { + is_expected.to contain_exec('nova-cell_v2-map_instances').with( + :path => ['/bin', '/usr/bin'], + :command => 'nova-manage --config-file /etc/nova/nova.conf cell_v2 map_instances --cell_uuid=uuid', + :refreshonly => true, + ) + } + end + end + + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + it_configures 'nova::cell_v2::map_instances' + end + end + +end