Files
puppet-nova/lib/puppet/provider/nova_cells/nova_manage.rb
Javier Pena 682174b778 Sanitize nova_manage output in provider
nova-manage can output a warning message in some cases (see [1] for
an example with the latest oslo.db), and that confuses the nova_manage
provider.

Since the command in a provider cannot separate stdout and stderr[2],
we use a workaround with Puppet::Util::Execution.execute, and
use that instead of the provider command in the nova_cells and
nova_cell_v2 providers.

[1] - https://logs.rdoproject.org/23/9323/2/experimental/gate-weirdo-dlrn-master-puppet-scenario001/Z6a290513d2904561a2adc60ddbfd7084/weirdo-project/puppet.txt.gz
[2] - https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb#L14-L16

Change-Id: I79f76592672d968b96338b3e0f6a86c9b7faeb93
2017-09-14 13:14:01 +00:00

91 lines
2.2 KiB
Ruby

#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
# Francois Charlier <francois.charlier@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#
# nova_cells provider
#
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/nova')
Puppet::Type.type(:nova_cells).provide(
:nova_manage,
:parent => Puppet::Provider::Nova
) do
desc "Manage nova cells"
def self.instances
begin
cells_list = nova_manage_request("cell", "list")
rescue Exception => e
if e.message =~ /No cells defined/
return []
else
raise(e)
end
end
cells_list.split("\n")[1..-1].collect do |net|
if net =~ /^(\S+)\s+(\S+)/
new(:name => $2 )
end
end.compact
end
def create
optional_opts = []
{
:name => '--name',
:cell_type => '--cell_type',
:rabbit_username => '--username',
:rabbit_password => '--password',
:rabbit_hosts => '--hostname',
:rabbit_port => '--port',
:rabbit_virtual_host => '--virtual_host',
:weight_offset => '--woffset',
:weight_scale => '--wscale'
}.each do |param, opt|
if resource[param]
optional_opts.push(opt).push(resource[param])
end
end
nova_manage_request('cell', 'create',
optional_opts
)
end
def exists?
begin
cells_list = nova_manage_request("cell", "list")
return cells_list.split("\n")[1..-1].detect do |n|
n =~ /^(\S+)\s+(#{resource[:cells].split('/').first})/
end
rescue
return false
end
end
def destroy
nova_manage_request("cell", "delete", resource[:name])
end
end