Added Check Modulation

Change-Id: I4796892b1a8af06c65ee014c796a3d46a38e0ae6
This commit is contained in:
flavien.peyre
2015-05-08 10:22:40 -04:00
parent 20c7af4675
commit c65cc89422
4 changed files with 155 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
# Copyright 2015 - Savoir-Faire Linux inc.
#
# 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.
import json
import httpretty
from surveilclient.tests.v2_0 import clienttest
class TestCheckModulations(clienttest.ClientTest):
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.POST, "http://localhost:8080/v2/config/checkmodulations",
body='{"message": "Ack received!"}')
self.client.config.checkmodulations.create(
check_command='test',
check_period='test',
checkmodulation_name='test'
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{"checkmodulation_name": "test",
"check_command": "test",
"check_period": "test"}
)
@httpretty.activate
def test_list(self):
httpretty.register_uri(
httpretty.GET, "http://localhost:8080/v2/config/checkmodulations",
body='[{"checkmodulation_name": "test","check_command": "test",'
'"check_period": "test"}]'
)
self.assertEqual(
self.client.config.checkmodulations.list(),
[{"checkmodulation_name": "test",
"check_command": "test", "check_period": "test"}]
)
@httpretty.activate
def test_delete(self):
httpretty.register_uri(
httpretty.DELETE, "http://localhost:8080/v2/config/"
"checkmodulations/checkmodulation_to_delete",
body='body')
body = self.client.config.checkmodulations.delete(
checkmodulation_name='checkmodulation_to_delete'
)
self.assertEqual(
body,
"body"
)

View File

@@ -13,6 +13,7 @@
# under the License.
from surveilclient.common import surveil_manager
from surveilclient.v2_0.config import checkmodulations
from surveilclient.v2_0.config import hosts
from surveilclient.v2_0.config import services
@@ -24,6 +25,8 @@ class ConfigManager(surveil_manager.SurveilManager):
super(ConfigManager, self).__init__(http_client)
self.hosts = hosts.HostsManager(self.http_client)
self.services = services.ServicesManager(self.http_client)
self.checkmodulations = checkmodulations.CheckModulationsManager(
self.http_client)
def reload_config(self):
resp, body = self.http_client.json_request(
@@ -31,4 +34,4 @@ class ConfigManager(surveil_manager.SurveilManager):
'POST',
body='' # Must send empty body
)
return body
return body

View File

@@ -0,0 +1,43 @@
# Copyright 2014-2015 - Savoir-Faire Linux inc.
#
# 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.
from surveilclient.common import surveil_manager
class CheckModulationsManager(surveil_manager.SurveilManager):
base_url = '/config/checkmodulations'
def list(self):
"""Get a list of checkmodulations."""
resp, body = self.http_client.json_request(
CheckModulationsManager.base_url, 'GET'
)
return body
def create(self, **kwargs):
"""Create a new checkmodulation."""
resp, body = self.http_client.json_request(
CheckModulationsManager.base_url, 'POST',
body=kwargs
)
return body
def delete(self, checkmodulation_name):
"""Delete a checkmodulation."""
resp, body = self.http_client.request(
CheckModulationsManager.base_url+"/" + checkmodulation_name,
'DELETE',
body=''
)
return body

View File

@@ -135,6 +135,45 @@ def do_config_service_delete(sc, args):
args.service_description)
def do_config_checkmodulation_list(sc, args):
"""List all config check modulations."""
checkmodulations = sc.config.checkmodulations.list()
if args.json:
print(utils.json_formatter(checkmodulations))
else:
cols = [
'check_command',
'check_period',
'checkmodulation_name'
]
formatters = {
'check_command': lambda x: x['check_command'],
'check_period': lambda x: x['check_period'],
'checkmodulation_name': lambda x: x['checkmodulation_name']
}
utils.print_list(checkmodulations, cols, formatters=formatters)
@cliutils.arg("--check_command")
@cliutils.arg("--check_period")
@cliutils.arg("--checkmodulation_name")
def do_config_checkmodulation_create(sc, args):
"""Create a config check modulation."""
arg_names = ['check_command',
'check_period',
'checkmodulation_name']
checkmodulation = _dict_from_args(args, arg_names)
sc.config.checkmodulations.create(**checkmodulation)
@cliutils.arg("--checkmodulation_name", help="Name of the check modulation")
def do_config_checkmodulation_delete(sc, args):
"""Create a config check modulation."""
sc.config.checkmodulations.delete(args.checkmodulation_name)
def do_config_reload(sc, args):
"""Trigger a config reload."""
print(sc.config.reload_config()['message'])