Add metering agent support

The Ceilometer project is able to get meters from Neutron via the
notifications system on how much bandwidth the projects are using.
The idea is to meter this as the L3 routers levels.

The feature exists since Havana.

Signed-off-by: Emilien Macchi <emilien.macchi@enovance.com>
implement blueprint metering-agent

Change-Id: I62ad9b7455e5f2bc3455b55a346f2515ca1040a3
This commit is contained in:
Emilien Macchi
2013-11-21 23:33:09 +01:00
parent 37d1c5b810
commit bf34f8631c
7 changed files with 265 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ class { 'neutron':
rabbit_password => 'password',
rabbit_user => 'guest',
rabbit_host => 'localhost',
service_plugins => ['neutron.services.metering.metering_plugin.MeteringPlugin']
}
# The API server talks to keystone for authorisation
@@ -21,6 +22,7 @@ class { 'neutron::agents::dhcp': }
class { 'neutron::agents::l3': }
class { 'neutron::agents::lbaas': }
class { 'neutron::agents::vpnaas': }
class { 'neutron::agents::metering': }
# This plugin configures Neutron for OVS on the server
# Agent

View File

@@ -0,0 +1,22 @@
Puppet::Type.type(:neutron_metering_agent_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def separator
'='
end
def file_path
'/etc/neutron/metering_agent.ini'
end
end

View File

@@ -0,0 +1,18 @@
Puppet::Type.newtype(:neutron_metering_agent_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from metering_agent.ini'
newvalues(/\S+\/\S+/)
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
end
end

View File

@@ -0,0 +1,106 @@
#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@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.
#
# == Class: neutron::agents:metering
#
# Setups Neutron metering agent.
#
# === Parameters
#
# [*package_ensure*]
# (optional) Ensure state for package. Defaults to 'present'.
#
# [*enabled*]
# (optional) Enable state for service. Defaults to 'true'.
#
# [*debug*]
# (optional) Show debugging output in log. Defaults to false.
#
# [*interface_driver*]
# (optional) Defaults to 'neutron.agent.linux.interface.OVSInterfaceDriver'.
#
# [*use_namespaces*]
# (optional) Allow overlapping IP (Must have kernel build with
# CONFIG_NET_NS=y and iproute2 package that supports namespaces).
# Defaults to true.
#
# [*measure_interval*]
# (optional) Interval between two metering measures.
# Defaults to 30.
#
# [*report_interval*]
# (optional) Interval between two metering reports.
# Defaults to 300.
#
class neutron::agents::metering (
$package_ensure = present,
$enabled = true,
$debug = false,
$interface_driver = 'neutron.agent.linux.interface.OVSInterfaceDriver',
$use_namespaces = true,
$measure_interval = '30',
$report_interval = '300'
) {
include neutron::params
Neutron_config<||> ~> Service['neutron-metering-service']
Neutron_metering_agent_config<||> ~> Service['neutron-metering-service']
# The metering agent loads both neutron.ini and its own file.
# This only lists config specific to the agent. neutron.ini supplies
# the rest.
neutron_metering_agent_config {
'DEFAULT/debug': value => $debug;
'DEFAULT/interface_driver': value => $interface_driver;
'DEFAULT/use_namespaces': value => $use_namespaces;
'DEFAULT/measure_interval': value => $measure_interval;
'DEFAULT/report_interval': value => $report_interval;
}
if $::neutron::params::metering_agent_package {
Package['neutron'] -> Package['neutron-metering-agent']
Package['neutron-metering-agent'] -> Neutron_config<||>
Package['neutron-metering-agent'] -> Neutron_metering_agent_config<||>
package { 'neutron-metering-agent':
ensure => $package_ensure,
name => $::neutron::params::metering_agent_package,
}
} else {
# Some platforms (RedHat) do not provide a neutron metering agent package.
# The neutron metering agent config file is provided by the neutron package.
Package['neutron'] -> Neutron_metering_agent_config<||>
}
if $enabled {
$ensure = 'running'
} else {
$ensure = 'stopped'
}
service { 'neutron-metering-service':
ensure => $ensure,
name => $::neutron::params::metering_agent_service,
enable => $enabled,
require => Class['neutron'],
}
if $::neutron::service_plugins !~ /neutron\.services\.metering\.metering_plugin\.MeteringPlugin/ {
fail('metering_plugin class should be part of service_plugins in neutron.conf')
}
}

View File

@@ -39,6 +39,7 @@
# neutron.services.firewall.fwaas_plugin.FirewallPlugin
# neutron.services.loadbalancer.plugin.LoadBalancerPlugin
# neutron.services.vpn.plugin.VPNDriverPlugin
# neutron.services.metering.metering_plugin.MeteringPlugin
# Defaults to empty
#
# [*auth_strategy*]

View File

@@ -30,6 +30,9 @@ class neutron::params {
$haproxy_package = 'haproxy'
$metering_agent_package = false
$metering_agent_service = 'neutron-metering-agent'
$vpnaas_agent_package = false
$vpnaas_agent_service = 'neutron-vpnaas-agent'
$openswan_package = 'openswan'
@@ -71,6 +74,9 @@ class neutron::params {
$haproxy_package = 'haproxy'
$metering_agent_package = 'neutron-metering-agent'
$metering_agent_service = 'neutron-metering-agent'
$vpnaas_agent_package = 'neutron-plugin-vpn-agent'
$vpnaas_agent_service = 'neutron-vpnaas-agent'
$openswan_package = 'openswan'

View File

@@ -0,0 +1,110 @@
#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@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.
#
# Unit tests for neutron::plugins::metering class
#
require 'spec_helper'
describe 'neutron::agents::metering' do
let :pre_condition do
"class { 'neutron':
rabbit_password => 'passw0rd',
service_plugins => ['neutron.services.metering.metering_plugin.MeteringPlugin'] }"
end
let :params do
{}
end
let :default_params do
{ :package_ensure => 'present',
:enabled => true,
:debug => false,
:interface_driver => 'neutron.agent.linux.interface.OVSInterfaceDriver',
:use_namespaces => true,
:measure_interval => '30',
:report_interval => '300'
}
end
shared_examples_for 'neutron metering agent' do
let :p do
default_params.merge(params)
end
it { should include_class('neutron::params') }
it 'configures metering_agent.ini' do
should contain_neutron_metering_agent_config('DEFAULT/debug').with_value(p[:debug]);
should contain_neutron_metering_agent_config('DEFAULT/interface_driver').with_value(p[:interface_driver]);
should contain_neutron_metering_agent_config('DEFAULT/use_namespaces').with_value(p[:use_namespaces]);
should contain_neutron_metering_agent_config('DEFAULT/measure_interval').with_value(p[:measure_interval]);
should contain_neutron_metering_agent_config('DEFAULT/report_interval').with_value(p[:report_interval]);
end
it 'installs neutron metering agent package' do
if platform_params.has_key?(:metering_agent_package)
should contain_package('neutron-metering-agent').with(
:name => platform_params[:metering_agent_package],
:ensure => p[:package_ensure]
)
should contain_package('neutron').with_before(/Package\[neutron-metering-agent\]/)
should contain_package('neutron-metering-agent').with_before(/Neutron_metering_agent_config\[.+\]/)
should contain_package('neutron-metering-agent').with_before(/Neutron_config\[.+\]/)
else
should contain_package('neutron').with_before(/Neutron_metering_agent_config\[.+\]/)
end
end
it 'configures neutron metering agent service' do
should contain_service('neutron-metering-service').with(
:name => platform_params[:metering_agent_service],
:enable => true,
:ensure => 'running',
:require => 'Class[Neutron]'
)
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
let :platform_params do
{ :metering_agent_package => 'neutron-metering-agent',
:metering_agent_service => 'neutron-metering-agent' }
end
it_configures 'neutron metering agent'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
let :platform_params do
{ :metering_agent_service => 'neutron-metering-agent' }
end
it_configures 'neutron metering agent'
end
end