mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Merge pull request #105 from sschneid/tag_filtering
(QENG-2518) Tag-filtering
This commit is contained in:
commit
ccede2780e
4 changed files with 42 additions and 2 deletions
|
|
@ -37,6 +37,12 @@ module Vmpooler
|
|||
parsed_config[:graphite]['prefix'] ||= 'vmpooler'
|
||||
end
|
||||
|
||||
if parsed_config[:tagfilter]
|
||||
parsed_config[:tagfilter].keys.each do |tag|
|
||||
parsed_config[:tagfilter][tag] = Regexp.new(parsed_config[:tagfilter][tag])
|
||||
end
|
||||
end
|
||||
|
||||
parsed_config[:uptime] = Time.now
|
||||
|
||||
parsed_config
|
||||
|
|
|
|||
|
|
@ -542,8 +542,13 @@ module Vmpooler
|
|||
backend.hset('vmpooler__vm__' + params[:hostname], param, arg)
|
||||
when 'tags'
|
||||
arg.keys.each do |tag|
|
||||
backend.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag])
|
||||
backend.hset('vmpooler__tag__' + Date.today.to_s, params[:hostname] + ':' + tag, arg[tag])
|
||||
if Vmpooler::API.settings.config[:tagfilter] and Vmpooler::API.settings.config[:tagfilter][tag]
|
||||
filter = Vmpooler::API.settings.config[:tagfilter][tag]
|
||||
arg[tag] = arg[tag].match(filter).captures.join
|
||||
end
|
||||
|
||||
backend.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag])
|
||||
backend.hset('vmpooler__tag__' + Date.today.to_s, params[:hostname] + ':' + tag, arg[tag])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -332,6 +332,23 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.status).to eq(400)
|
||||
end
|
||||
|
||||
context '(tagfilter configured)' do
|
||||
let(:config) { {
|
||||
tagfilter: { 'url' => '(.*)\/' },
|
||||
} }
|
||||
|
||||
it 'correctly filters tags' do
|
||||
expect(redis).to receive(:hset).with("vmpooler__vm__testhost", "tag:url", "foo.com")
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"url":"foo.com/something.html"}}'
|
||||
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
expect(last_response.body).to eq(JSON.pretty_generate({'ok' => true}))
|
||||
expect(last_response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
let(:config) { { auth: false } }
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,18 @@
|
|||
base: 'ou=users,dc=company,dc=com'
|
||||
user_object: 'uid'
|
||||
|
||||
# :tagfilter:
|
||||
#
|
||||
# Filter tags by regular expression.
|
||||
|
||||
# Example:
|
||||
#
|
||||
# This example demonstrates discarding everything after a '/' character for
|
||||
# the 'url' tag, transforming 'foo.com/something.html' to 'foo.com'.
|
||||
|
||||
:tagfilter:
|
||||
url: '(.*)\/'
|
||||
|
||||
# :config:
|
||||
#
|
||||
# This section contains global configuration information.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue