map_instances.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # == Class: nova::cell_v2::map_instances
  2. #
  3. # Resource to run the map_instances action for cell v2
  4. #
  5. # === Parameters
  6. #
  7. # [*cell_uuid*]
  8. # (String) Cell UUID to map unmigrated instances to. It is recommended to use
  9. # this rather than cell name. Either cell_uuid or cell_name must be provided.
  10. # Defaults to undef.
  11. #
  12. # [*cell_name*]
  13. # (String) Cell name to map the unmigrated instances to. We will attempt to
  14. # extract the cell uuid using the name as the command requires a cell uuid.
  15. # NOTE: This will not work if you have multiple cells with the same name.
  16. # Defaults to undef.
  17. #
  18. # [*extra_params*]
  19. # (String) Extra parameters to pass to the nova-manage commands.
  20. # Defaults to ''.
  21. #
  22. class nova::cell_v2::map_instances (
  23. $cell_uuid = undef,
  24. $cell_name = undef,
  25. $extra_params = '',
  26. ) {
  27. include ::nova::deps
  28. if (!$cell_uuid and !$cell_name) {
  29. fail('Either cell_uuid or cell_name must be provided')
  30. }
  31. if ($cell_uuid) {
  32. $cell_uuid_real = $cell_uuid
  33. } else {
  34. # NOTE(aschultz): This is what breaks if you have multiple cells with the
  35. # same name. So that's why using cell_uuid is better.
  36. $cell_uuid_real = "$(nova-manage cell_v2 list_cells | sed -e '1,3d' -e '\$d' | awk -F ' *| *' '\$2 == \"${cell_name}\" {print \$4}')"
  37. }
  38. exec { 'nova-cell_v2-map_instances':
  39. path => ['/bin', '/usr/bin'],
  40. command => "nova-manage ${extra_params} cell_v2 map_instances --cell_uuid=${cell_uuid_real}",
  41. refreshonly => true,
  42. }
  43. }