nova_manage.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
  3. #
  4. # Author: Emilien Macchi <emilien.macchi@enovance.com>
  5. # Francois Charlier <francois.charlier@enovance.com>
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License. You may obtain
  9. # a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. #
  20. # nova_cells provider
  21. #
  22. Puppet::Type.type(:nova_cells).provide(:nova_manage) do
  23. desc "Manage nova cells"
  24. optional_commands :nova_manage => 'nova-manage'
  25. def self.instances
  26. begin
  27. cells_list = nova_manage("cell", "list")
  28. rescue Exception => e
  29. if e.message =~ /No cells defined/
  30. return []
  31. else
  32. raise(e)
  33. end
  34. end
  35. cells_list.split("\n")[1..-1].collect do |net|
  36. if net =~ /^(\S+)\s+(\S+)/
  37. new(:name => $2 )
  38. end
  39. end.compact
  40. end
  41. def create
  42. optional_opts = []
  43. {
  44. :name => '--name',
  45. :cell_type => '--cell_type',
  46. :rabbit_username => '--username',
  47. :rabbit_password => '--password',
  48. :rabbit_hosts => '--hostname',
  49. :rabbit_port => '--port',
  50. :rabbit_virtual_host => '--virtual_host',
  51. :weight_offset => '--woffset',
  52. :weight_scale => '--wscale'
  53. }.each do |param, opt|
  54. if resource[param]
  55. optional_opts.push(opt).push(resource[param])
  56. end
  57. end
  58. nova_manage('cell', 'create',
  59. optional_opts
  60. )
  61. end
  62. def exists?
  63. begin
  64. cells_list = nova_manage("cell", "list")
  65. return cells_list.split("\n")[1..-1].detect do |n|
  66. n =~ /^(\S+)\s+(#{resource[:cells].split('/').first})/
  67. end
  68. rescue
  69. return false
  70. end
  71. end
  72. def destroy
  73. nova_manage("cell", "delete", resource[:name])
  74. end
  75. end