From 4b2538b37e8d5b06541c33488577ad0d02fc8856 Mon Sep 17 00:00:00 2001 From: flavien peyre Date: Wed, 29 Jul 2015 12:08:42 -0400 Subject: [PATCH] Create config object use now PUT Change-Id: Id339b36e202c09c3b2eaa43674a4a5a2319be2a6 --- requirements.txt | 2 +- surveil/api/controllers/v2/config/__init__.py | 2 +- .../v2/config/businessimpactmodulations.py | 55 +++++++++++------- .../controllers/v2/config/checkmodulations.py | 55 ++++++++++-------- surveil/api/controllers/v2/config/commands.py | 2 +- .../controllers/v2/config/contactgroups.py | 49 +++++++++------- surveil/api/controllers/v2/config/contacts.py | 54 +++++++++++------- .../api/controllers/v2/config/hostgroups.py | 48 +++++++++------- surveil/api/controllers/v2/config/hosts.py | 2 +- .../controllers/v2/config/macromodulations.py | 57 +++++++++++-------- .../controllers/v2/config/notificationways.py | 56 ++++++++++-------- surveil/api/controllers/v2/config/realms.py | 48 +++++++++------- .../api/controllers/v2/config/servicegroup.py | 49 +++++++++------- surveil/api/controllers/v2/config/services.py | 2 +- .../api/controllers/v2/config/timeperiods.py | 49 +++++++++------- .../config/test_businessimpactmodulations.py | 2 +- .../v2/config/test_checkmodulation.py | 2 +- .../controllers/v2/config/test_commands.py | 2 +- .../v2/config/test_contactgroup.py | 2 +- .../controllers/v2/config/test_contacts.py | 2 +- .../controllers/v2/config/test_hostgroup.py | 2 +- .../api/controllers/v2/config/test_hosts.py | 2 +- .../v2/config/test_macromodulations.py | 2 +- .../v2/config/test_notificationways.py | 2 +- .../api/controllers/v2/config/test_realms.py | 2 +- .../v2/config/test_servicegroup.py | 2 +- .../controllers/v2/config/test_services.py | 2 +- .../controllers/v2/config/test_timeperiods.py | 2 +- tools/docker/alignak_container/Dockerfile | 6 +- 29 files changed, 327 insertions(+), 235 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6bbdec8..e2c5cf0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ keystonemiddleware PasteDeploy influxdb==2.7.3 pika -python-surveilclient==0.12.0 +python-surveilclient==0.13.2 six docker-py mongoengine diff --git a/surveil/api/controllers/v2/config/__init__.py b/surveil/api/controllers/v2/config/__init__.py index ed9fccb..0cc075b 100644 --- a/surveil/api/controllers/v2/config/__init__.py +++ b/surveil/api/controllers/v2/config/__init__.py @@ -46,5 +46,5 @@ class ConfigController(rest.RestController): BusinessImpactModulationsController()) notificationways = notificationways.NotificationWaysController() checkmodulations = checkmodulations.CheckModulationsController() - macromodulations = macromodulations.MacroModulationController() + macromodulations = macromodulations.MacroModulationsController() # engine = EngineController() diff --git a/surveil/api/controllers/v2/config/businessimpactmodulations.py b/surveil/api/controllers/v2/config/businessimpactmodulations.py index fd4ea9b..2b7bf33 100644 --- a/surveil/api/controllers/v2/config/businessimpactmodulations.py +++ b/surveil/api/controllers/v2/config/businessimpactmodulations.py @@ -15,7 +15,6 @@ import pecan from pecan import rest -import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import businessimpactmodulation as mod @@ -25,6 +24,11 @@ from surveil.common import util class BusinessImpactModulationsController(rest.RestController): + @pecan.expose() + def _lookup(self, businessimpactmodulation_name, *remainder): + return BusinessImpactModulationController( + businessimpactmodulation_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([mod.BusinessImpactModulation]) def get_all(self): @@ -34,18 +38,10 @@ class BusinessImpactModulationsController(rest.RestController): return modulations @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(mod.BusinessImpactModulation, wtypes.text) - def get_one(self, modulation_name): - """Returns a specific business impact modulation.""" - handler = bh.BusinessImpactModulationHandler(pecan.request) - modulation = handler.get( - {"business_impact_modulation_name": modulation_name} - ) - return modulation - - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(body=mod.BusinessImpactModulation, status_code=201) - def post(self, data): + @wsme_pecan.wsexpose(mod.BusinessImpactModulation, + body=mod.BusinessImpactModulation, + status_code=201) + def put(self, data): """Create a new business impact modulation. :param data: a business impact modulation within the request body. @@ -53,26 +49,41 @@ class BusinessImpactModulationsController(rest.RestController): handler = bh.BusinessImpactModulationHandler(pecan.request) handler.create(data) + +class BusinessImpactModulationController(rest.RestController): + + def __init__(self, business_impact_modulation_name): + pecan.request.context['business_impact_modulation_name'] = ( + business_impact_modulation_name) + self._id = business_impact_modulation_name + @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(mod.BusinessImpactModulation, - wtypes.text, - status_code=204) - def delete(self, modulation_name): + @wsme_pecan.wsexpose(mod.BusinessImpactModulation) + def get(self): """Returns a specific business impact modulation.""" handler = bh.BusinessImpactModulationHandler(pecan.request) + modulation = handler.get( + {"business_impact_modulation_name": self._id} + ) + return modulation + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Delete this business impact modulation.""" + handler = bh.BusinessImpactModulationHandler(pecan.request) handler.delete( - {"business_impact_modulation_name": modulation_name} + {"business_impact_modulation_name": self._id} ) @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(mod.BusinessImpactModulation, - wtypes.text, + @wsme_pecan.wsexpose(None, body=mod.BusinessImpactModulation, status_code=204) - def put(self, modulaion_name, modulation): + def put(self, modulation): """Update a specific business impact modulation.""" handler = bh.BusinessImpactModulationHandler(pecan.request) handler.update( - {"business_impact_modulation_name": modulaion_name}, + {"business_impact_modulation_name": self._id}, modulation ) diff --git a/surveil/api/controllers/v2/config/checkmodulations.py b/surveil/api/controllers/v2/config/checkmodulations.py index ac5adfb..1007977 100644 --- a/surveil/api/controllers/v2/config/checkmodulations.py +++ b/surveil/api/controllers/v2/config/checkmodulations.py @@ -25,6 +25,10 @@ from surveil.common import util class CheckModulationsController(rest.RestController): + @pecan.expose() + def _lookup(self, checkmodulation_name, *remainder): + return CheckModulationController(checkmodulation_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([checkmodulation.CheckModulation]) def get_all(self): @@ -33,19 +37,9 @@ class CheckModulationsController(rest.RestController): checkmodulations = handler.get_all() return checkmodulations - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(checkmodulation.CheckModulation, wtypes.text) - def get_one(self, checkmodulation_name): - """Returns a specific check modulation.""" - handler = checkmodulation_handler.CheckModulationHandler(pecan.request) - checkmodulation = handler.get( - {"checkmodulation_name": checkmodulation_name} - ) - return checkmodulation - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=checkmodulation.CheckModulation, status_code=201) - def post(self, data): + def put(self, data): """Create a new check modulation. :param data: a check modulation within the request body. @@ -53,23 +47,38 @@ class CheckModulationsController(rest.RestController): handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(checkmodulation.CheckModulation, - wtypes.text, status_code=204) - def delete(self, checkmodulation_name): - """Returns a specific check modulation.""" - handler = checkmodulation_handler.CheckModulationHandler(pecan.request) - handler.delete({"checkmodulation_name": checkmodulation_name}) + +class CheckModulationController(rest.RestController): + + def __init__(self, check_modulation_name): + pecan.request.context['check_modulation_name'] = check_modulation_name + self._id = check_modulation_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(checkmodulation.CheckModulation, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Returns a specific check modulation.""" + handler = checkmodulation_handler.CheckModulationHandler(pecan.request) + handler.delete({"checkmodulation_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=checkmodulation.CheckModulation, status_code=204) - def put(self, checkmodulation_name, checkmodulation): + def put(self, checkmodulation): """Update a specific check modulation.""" handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler.update( - {"checkmodulation_name": checkmodulation_name}, + {"checkmodulation_name": self._id}, checkmodulation - ) \ No newline at end of file + ) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(checkmodulation.CheckModulation, wtypes.text) + def get(self): + """Returns a specific check modulation.""" + handler = checkmodulation_handler.CheckModulationHandler(pecan.request) + checkmodulation = handler.get( + {"checkmodulation_name": self._id} + ) + return checkmodulation \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/commands.py b/surveil/api/controllers/v2/config/commands.py index 7c5db1d..b38d937 100644 --- a/surveil/api/controllers/v2/config/commands.py +++ b/surveil/api/controllers/v2/config/commands.py @@ -71,7 +71,7 @@ class CommandsController(rest.RestController): @wsme_pecan.wsexpose(command.Command, body=command.Command, status_code=201) - def post(self, data): + def put(self, data): """Create a new command. :param data: a command within the request body. diff --git a/surveil/api/controllers/v2/config/contactgroups.py b/surveil/api/controllers/v2/config/contactgroups.py index c0728ce..6fd1daf 100644 --- a/surveil/api/controllers/v2/config/contactgroups.py +++ b/surveil/api/controllers/v2/config/contactgroups.py @@ -25,6 +25,10 @@ from surveil.common import util class ContactGroupsController(rest.RestController): + @pecan.expose() + def _lookup(self, contactgroup_name, *remainder): + return ContactGroupController(contactgroup_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([contactgroup.ContactGroup]) def get_all(self): @@ -33,17 +37,9 @@ class ContactGroupsController(rest.RestController): contact_groups = handler.get_all() return contact_groups - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text) - def get_one(self, group_name): - """Returns a contact group.""" - handler = contactgroup_handler.ContactGroupHandler(pecan.request) - contactgroup = handler.get({"contactgroup_name": group_name}) - return contactgroup - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=contactgroup.ContactGroup, status_code=201) - def post(self, data): + def put(self, data): """Create a new contact group. :param data: a contact group within the request body. @@ -51,20 +47,33 @@ class ContactGroupsController(rest.RestController): handler = contactgroup_handler.ContactGroupHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text, - status_code=204) - def delete(self, group_name): - """Delete a specific contact group.""" - handler = contactgroup_handler.ContactGroupHandler(pecan.request) - handler.delete({"contactgroup_name": group_name}) + +class ContactGroupController(rest.RestController): + + def __init__(self, contactgroup_name): + pecan.request.context['contactgroup_name'] = contactgroup_name + self._id = contactgroup_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contactgroup.ContactGroup, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Delete a specific contact group.""" + handler = contactgroup_handler.ContactGroupHandler(pecan.request) + handler.delete({"contactgroup_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=contactgroup.ContactGroup, status_code=204) - def put(self, group_name, contactgroup): + def put(self, contactgroup): """Update a specific contact group.""" handler = contactgroup_handler.ContactGroupHandler(pecan.request) - handler.update({"contactgroup_name": group_name}, contactgroup) + handler.update({"contactgroup_name": self._id}, contactgroup) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text) + def get(self): + """Returns a contact group.""" + handler = contactgroup_handler.ContactGroupHandler(pecan.request) + contactgroup = handler.get({"contactgroup_name": self._id}) + return contactgroup diff --git a/surveil/api/controllers/v2/config/contacts.py b/surveil/api/controllers/v2/config/contacts.py index 36354af..78c6ff1 100644 --- a/surveil/api/controllers/v2/config/contacts.py +++ b/surveil/api/controllers/v2/config/contacts.py @@ -25,25 +25,21 @@ from surveil.common import util class ContactsController(rest.RestController): + @pecan.expose() + def _lookup(self, contact_name, *remainder): + return ContactController(contact_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([contact.Contact]) def get_all(self): - """Returns all hosts.""" + """Returns all contacts.""" handler = contact_handler.ContactHandler(pecan.request) hosts = handler.get_all() return hosts - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contact.Contact, wtypes.text) - def get_one(self, contact_name): - """Returns a specific contact.""" - handler = contact_handler.ContactHandler(pecan.request) - contact = handler.get({"contact_name": contact_name}) - return contact - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=contact.Contact, status_code=201) - def post(self, data): + def put(self, data): """Create a new contact. :param data: a contact within the request body. @@ -51,19 +47,33 @@ class ContactsController(rest.RestController): handler = contact_handler.ContactHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contact.Contact, wtypes.text, status_code=204) - def delete(self, contact_name): - """Returns a specific contact.""" - handler = contact_handler.ContactHandler(pecan.request) - handler.delete({"contact_name": contact_name}) + +class ContactController(rest.RestController): + + def __init__(self, contact_name): + pecan.request.context['contact_name'] = contact_name + self._id = contact_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(contact.Contact, - wtypes.text, - body=contact.Contact, - status_code=204) - def put(self, contact_name, contact): + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): """Returns a specific contact.""" handler = contact_handler.ContactHandler(pecan.request) - handler.update({"contact_name": contact_name}, contact) + handler.delete({"contact_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, + body=contact.Contact, + status_code=204) + def put(self, contact): + """Returns a specific contact.""" + handler = contact_handler.ContactHandler(pecan.request) + handler.update({"contact_name": self._id}, contact) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(contact.Contact, wtypes.text) + def get(self): + """Returns a specific contact.""" + handler = contact_handler.ContactHandler(pecan.request) + contact = handler.get({"contact_name": self._id}) + return contact \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/hostgroups.py b/surveil/api/controllers/v2/config/hostgroups.py index 25db403..fab910b 100644 --- a/surveil/api/controllers/v2/config/hostgroups.py +++ b/surveil/api/controllers/v2/config/hostgroups.py @@ -25,6 +25,10 @@ from surveil.common import util class HostGroupsController(rest.RestController): + @pecan.expose() + def _lookup(self, hostgroup_name, *remainder): + return HostGroupController(hostgroup_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([hostgroup.HostGroup]) def get_all(self): @@ -33,17 +37,9 @@ class HostGroupsController(rest.RestController): host_groups = handler.get_all() return host_groups - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text) - def get_one(self, group_name): - """Returns a host group.""" - handler = hostgroup_handler.HostGroupHandler(pecan.request) - hostgroup = handler.get({"hostgroup_name": group_name}) - return hostgroup - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=hostgroup.HostGroup, status_code=201) - def post(self, data): + def put(self, data): """Create a new host group. :param data: a host group within the request body. @@ -51,19 +47,33 @@ class HostGroupsController(rest.RestController): handler = hostgroup_handler.HostGroupHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text, status_code=204) - def delete(self, group_name): - """Returns a specific host group.""" - handler = hostgroup_handler.HostGroupHandler(pecan.request) - handler.delete({"hostgroup_name": group_name}) + +class HostGroupController(rest.RestController): + + def __init__(self, hostgroup_name): + pecan.request.context['hostgroup_name'] = hostgroup_name + self._id = hostgroup_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(hostgroup.HostGroup, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Returns a specific host group.""" + handler = hostgroup_handler.HostGroupHandler(pecan.request) + handler.delete({"hostgroup_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=hostgroup.HostGroup, status_code=204) - def put(self, group_name, hostgroup): + def put(self, hostgroup): """Update a specific host group.""" handler = hostgroup_handler.HostGroupHandler(pecan.request) - handler.update({"hostgroup_name": group_name}, hostgroup) + handler.update({"hostgroup_name": self._id}, hostgroup) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text) + def get(self): + """Returns a host group.""" + handler = hostgroup_handler.HostGroupHandler(pecan.request) + hostgroup = handler.get({"hostgroup_name": self._id}) + return hostgroup \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/hosts.py b/surveil/api/controllers/v2/config/hosts.py index 8e7516a..da195cf 100644 --- a/surveil/api/controllers/v2/config/hosts.py +++ b/surveil/api/controllers/v2/config/hosts.py @@ -134,7 +134,7 @@ class HostsController(rest.RestController): @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(host.Host, body=host.Host, status_code=201) - def post(self, data): + def put(self, data): """Create a new host. :param data: a host within the request body. diff --git a/surveil/api/controllers/v2/config/macromodulations.py b/surveil/api/controllers/v2/config/macromodulations.py index 51d7be9..912456e 100644 --- a/surveil/api/controllers/v2/config/macromodulations.py +++ b/surveil/api/controllers/v2/config/macromodulations.py @@ -23,7 +23,11 @@ from surveil.api.handlers.config import macromodulation_handler from surveil.common import util -class MacroModulationController(rest.RestController): +class MacroModulationsController(rest.RestController): + + @pecan.expose() + def _lookup(self, macromodulation_name, *remainder): + return MacroModulationController(macromodulation_name), remainder @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([macromodulation.MacroModulation]) @@ -33,19 +37,9 @@ class MacroModulationController(rest.RestController): modulations = handler.get_all() return modulations - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(macromodulation.MacroModulation, wtypes.text) - def get_one(self, macromodulation_name): - """Returns a specific macro modulation.""" - handler = macromodulation_handler.MacroModulationHandler(pecan.request) - modulation = handler.get( - {"macromodulation_name": macromodulation_name} - ) - return modulation - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=macromodulation.MacroModulation, status_code=201) - def post(self, data): + def put(self, data): """Create a new macro modulation object. :param data: a macro modulation within the request body. @@ -53,21 +47,36 @@ class MacroModulationController(rest.RestController): handler = macromodulation_handler.MacroModulationHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(macromodulation.MacroModulation, - wtypes.text, - status_code=204) - def delete(self, modulation_name): - """Returns a specific macro modulation.""" - handler = macromodulation_handler.MacroModulationHandler(pecan.request) - handler.delete({"macromodulation_name": modulation_name}) + +class MacroModulationController(rest.RestController): + + def __init__(self, macromodulation_name): + pecan.request.context['macromodulation_name'] = macromodulation_name + self._id = macromodulation_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(macromodulation.MacroModulation, - wtypes.text, + @wsme_pecan.wsexpose(None, + status_code=204) + def delete(self): + """Returns a specific macro modulation.""" + handler = macromodulation_handler.MacroModulationHandler(pecan.request) + handler.delete({"macromodulation_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=macromodulation.MacroModulation, status_code=204) - def put(self, modulation_name, modulation): + def put(self, modulation): """Update a specific macro modulation.""" handler = macromodulation_handler.MacroModulationHandler(pecan.request) - handler.update({"macromodulation_name": modulation_name}, modulation) + handler.update({"macromodulation_name": self._id}, modulation) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(macromodulation.MacroModulation, wtypes.text) + def get(self): + """Returns a specific macro modulation.""" + handler = macromodulation_handler.MacroModulationHandler(pecan.request) + modulation = handler.get( + {"macromodulation_name": self._id} + ) + return modulation \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/notificationways.py b/surveil/api/controllers/v2/config/notificationways.py index 6cbfffd..9995e3b 100644 --- a/surveil/api/controllers/v2/config/notificationways.py +++ b/surveil/api/controllers/v2/config/notificationways.py @@ -25,6 +25,10 @@ from surveil.common import util class NotificationWaysController(rest.RestController): + @pecan.expose() + def _lookup(self, notificationway_name, *remainder): + return NotificationWayController(notificationway_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([notificationway.NotificationWay]) def get_all(self): @@ -33,19 +37,9 @@ class NotificationWaysController(rest.RestController): notificationsway = handler.get_all() return notificationsway - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(notificationway.NotificationWay, wtypes.text) - def get_one(self, notificationway_name): - """Returns a specific notification way.""" - handler = notificationway_handler.NotificationWayHandler(pecan.request) - notificationway = handler.get( - {"notificationway_name": notificationway_name} - ) - return notificationway - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=notificationway.NotificationWay, status_code=201) - def post(self, data): + def put(self, data): """Create a new notification way. :param data: a notification way within the request body. @@ -53,26 +47,38 @@ class NotificationWaysController(rest.RestController): handler = notificationway_handler.NotificationWayHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose( - notificationway.NotificationWay, - wtypes.text, - status_code=204 - ) - def delete(self, notificationway_name): - """Returns a specific notification way.""" - handler = notificationway_handler.NotificationWayHandler(pecan.request) - handler.delete({"notificationway_name": notificationway_name}) + +class NotificationWayController(rest.RestController): + + def __init__(self, notificationway_name): + pecan.request.context['notificationway_name'] = notificationway_name + self._id = notificationway_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(notificationway.NotificationWay, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Returns a specific notification way.""" + handler = notificationway_handler.NotificationWayHandler(pecan.request) + handler.delete({"notificationway_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=notificationway.NotificationWay, status_code=204) - def put(self, notificationway_name, notificationway): + def put(self, notificationway): """Update a specific notification way.""" handler = notificationway_handler.NotificationWayHandler(pecan.request) handler.update( - {"notificationway_name": notificationway_name}, + {"notificationway_name": self._id}, notificationway ) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(notificationway.NotificationWay, wtypes.text) + def get(self): + """Returns a specific notification way.""" + handler = notificationway_handler.NotificationWayHandler(pecan.request) + notificationway = handler.get( + {"notificationway_name": self._id} + ) + return notificationway \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/realms.py b/surveil/api/controllers/v2/config/realms.py index 6d4abbd..ef15983 100644 --- a/surveil/api/controllers/v2/config/realms.py +++ b/surveil/api/controllers/v2/config/realms.py @@ -25,6 +25,10 @@ from surveil.common import util class RealmsController(rest.RestController): + @pecan.expose() + def _lookup(self, realm_name, *remainder): + return RealmController(realm_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([realm.Realm]) def get_all(self): @@ -33,17 +37,9 @@ class RealmsController(rest.RestController): realms = handler.get_all() return realms - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(realm.Realm, wtypes.text) - def get_one(self, realm_name): - """Returns a specific realm.""" - handler = realm_handler.RealmHandler(pecan.request) - realm = handler.get({"realm_name": realm_name}) - return realm - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=realm.Realm, status_code=201) - def post(self, data): + def put(self, data): """Create a new realm. :param data: a realm within the request body. @@ -51,22 +47,36 @@ class RealmsController(rest.RestController): handler = realm_handler.RealmHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(realm.Realm, wtypes.text, status_code=204) - def delete(self, realm_name): - """Deletes a specific realm.""" - handler = realm_handler.RealmHandler(pecan.request) - handler.delete({"realm_name": realm_name}) + +class RealmController(rest.RestController): + + def __init__(self, realm_name): + pecan.request.context['realm_name'] = realm_name + self._id = realm_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(realm.Realm, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Deletes a specific realm.""" + handler = realm_handler.RealmHandler(pecan.request) + handler.delete({"realm_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=realm.Realm, status_code=204) - def put(self, realm_name, realm): + def put(self, realm): """Updates a specific realm.""" handler = realm_handler.RealmHandler(pecan.request) handler.update( - {"realm_name": realm_name}, + {"realm_name": self._id}, realm ) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(realm.Realm, wtypes.text) + def get(self): + """Returns a specific realm.""" + handler = realm_handler.RealmHandler(pecan.request) + realm = handler.get({"realm_name": self._id}) + return realm \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/servicegroup.py b/surveil/api/controllers/v2/config/servicegroup.py index 1074c5b..b03653f 100644 --- a/surveil/api/controllers/v2/config/servicegroup.py +++ b/surveil/api/controllers/v2/config/servicegroup.py @@ -25,6 +25,10 @@ from surveil.common import util class ServiceGroupsController(rest.RestController): + @pecan.expose() + def _lookup(self, servicegroup_name, *remainder): + return ServiceGroupController(servicegroup_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([servicegroup.ServiceGroup]) def get_all(self): @@ -33,17 +37,9 @@ class ServiceGroupsController(rest.RestController): service_groups = handler.get_all() return service_groups - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text) - def get_one(self, group_name): - """Returns a service group.""" - handler = servicegroup_handler.ServiceGroupHandler(pecan.request) - servicegroup = handler.get({"servicegroup_name": group_name}) - return servicegroup - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=servicegroup.ServiceGroup, status_code=201) - def post(self, data): + def put(self, data): """Create a new service group. :param data: a service group within the request body. @@ -51,20 +47,33 @@ class ServiceGroupsController(rest.RestController): handler = servicegroup_handler.ServiceGroupHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text, - status_code=204) - def delete(self, group_name): - """Returns a specific service group.""" - handler = servicegroup_handler.ServiceGroupHandler(pecan.request) - handler.delete({"servicegroup_name": group_name}) + +class ServiceGroupController(rest.RestController): + + def __init__(self, servicegroup_name): + pecan.request.context['servicegroup_name'] = servicegroup_name + self._id = servicegroup_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(servicegroup.ServiceGroup, - wtypes.text, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Returns a specific service group.""" + handler = servicegroup_handler.ServiceGroupHandler(pecan.request) + handler.delete({"servicegroup_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=servicegroup.ServiceGroup, status_code=204) - def put(self, group_name, servicegroup): + def put(self, servicegroup): """Update a specific service group.""" handler = servicegroup_handler.ServiceGroupHandler(pecan.request) - handler.update({"servicegroup_name": group_name}, servicegroup) + handler.update({"servicegroup_name": self._id}, servicegroup) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text) + def get(self): + """Returns a service group.""" + handler = servicegroup_handler.ServiceGroupHandler(pecan.request) + servicegroup = handler.get({"servicegroup_name": self._id}) + return servicegroup \ No newline at end of file diff --git a/surveil/api/controllers/v2/config/services.py b/surveil/api/controllers/v2/config/services.py index 3220fe5..3fc4bc8 100644 --- a/surveil/api/controllers/v2/config/services.py +++ b/surveil/api/controllers/v2/config/services.py @@ -37,7 +37,7 @@ class ServicesController(rest.RestController): @wsme_pecan.wsexpose(service.Service, body=service.Service, status_code=201) - def post(self, data): + def put(self, data): """Create a new service. :param data: a service within the request body. diff --git a/surveil/api/controllers/v2/config/timeperiods.py b/surveil/api/controllers/v2/config/timeperiods.py index 815aad6..d417c22 100644 --- a/surveil/api/controllers/v2/config/timeperiods.py +++ b/surveil/api/controllers/v2/config/timeperiods.py @@ -25,6 +25,10 @@ from surveil.common import util class TimePeriodsController(rest.RestController): + @pecan.expose() + def _lookup(self, timeperiod_name, *remainder): + return TimePeriodController(timeperiod_name), remainder + @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose([timeperiod.TimePeriod]) def get_all(self): @@ -33,17 +37,9 @@ class TimePeriodsController(rest.RestController): time_periods = handler.get_all() return time_periods - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text) - def get_one(self, timeperiod_name): - """Returns a specific time period.""" - handler = timeperiod_handler.TimePeriodHandler(pecan.request) - timeperiod = handler.get({"timeperiod_name": timeperiod_name}) - return timeperiod - @util.policy_enforce(['authenticated']) @wsme_pecan.wsexpose(body=timeperiod.TimePeriod, status_code=201) - def post(self, data): + def put(self, data): """Create a new time period. :param data: a time period within the request body. @@ -51,19 +47,32 @@ class TimePeriodsController(rest.RestController): handler = timeperiod_handler.TimePeriodHandler(pecan.request) handler.create(data) - @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text, status_code=204) - def delete(self, timeperiod_name): - """Returns a specific time period.""" - handler = timeperiod_handler.TimePeriodHandler(pecan.request) - handler.delete({"timeperiod_name": timeperiod_name}) + +class TimePeriodController(rest.RestController): + + def __init__(self, timeperiod_name): + pecan.request.context['timeperiod_name'] = timeperiod_name + self._id = timeperiod_name @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose(timeperiod.TimePeriod, - wtypes.text, - body=timeperiod.TimePeriod, + @wsme_pecan.wsexpose(None, status_code=204) + def delete(self): + """Returns a specific time period.""" + handler = timeperiod_handler.TimePeriodHandler(pecan.request) + handler.delete({"timeperiod_name": self._id}) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(None, body=timeperiod.TimePeriod, status_code=204) - def put(self, timeperiod_name, timeperiod): + def put(self, timeperiod): """Update a specific time period.""" handler = timeperiod_handler.TimePeriodHandler(pecan.request) - handler.update({"timeperiod_name": timeperiod_name}, timeperiod) + handler.update({"timeperiod_name": self._id}, timeperiod) + + @util.policy_enforce(['authenticated']) + @wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text) + def get(self): + """Returns a specific time period.""" + handler = timeperiod_handler.TimePeriodHandler(pecan.request) + timeperiod = handler.get({"timeperiod_name": self._id}) + return timeperiod \ No newline at end of file diff --git a/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py b/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py index 49a09c4..66d56d7 100644 --- a/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py +++ b/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py @@ -76,7 +76,7 @@ class TestBusinessImpactModulationController(functionalTest.FunctionalTest): self.mongoconnection.shinken.businessimpactmodulations.find_one(m) ) - self.post_json('/v2/config/businessimpactmodulations', m) + self.put_json('/v2/config/businessimpactmodulations', m) self.assertIsNotNone( self.mongoconnection.shinken.businessimpactmodulations.find_one(m) diff --git a/surveil/tests/api/controllers/v2/config/test_checkmodulation.py b/surveil/tests/api/controllers/v2/config/test_checkmodulation.py index e7d1456..42ddcdf 100644 --- a/surveil/tests/api/controllers/v2/config/test_checkmodulation.py +++ b/surveil/tests/api/controllers/v2/config/test_checkmodulation.py @@ -71,7 +71,7 @@ class TestCheckModulationsController(functionalTest.FunctionalTest): "check_period": "evening" } - self.post_json('/v2/config/checkmodulations', t) + self.put_json('/v2/config/checkmodulations', t) self.assertIsNotNone( self.mongoconnection.shinken.checkmodulations.find_one( {"checkmodulation_name": 'ping_evening', diff --git a/surveil/tests/api/controllers/v2/config/test_commands.py b/surveil/tests/api/controllers/v2/config/test_commands.py index 1e2fa40..ec5c06f 100644 --- a/surveil/tests/api/controllers/v2/config/test_commands.py +++ b/surveil/tests/api/controllers/v2/config/test_commands.py @@ -89,7 +89,7 @@ class TestCommandController(functionalTest.FunctionalTest): "command_name": "newcommand", "command_line": "/usr/bin/newcommand -hello" } - response = self.post_json( + response = self.put_json( "/v2/config/commands", params=new_command ) diff --git a/surveil/tests/api/controllers/v2/config/test_contactgroup.py b/surveil/tests/api/controllers/v2/config/test_contactgroup.py index 1238280..076b31e 100644 --- a/surveil/tests/api/controllers/v2/config/test_contactgroup.py +++ b/surveil/tests/api/controllers/v2/config/test_contactgroup.py @@ -71,7 +71,7 @@ class TestContactGroupsController(functionalTest.FunctionalTest): members=["bob", "alice"], ) - self.post_json('/v2/config/contactgroups', g.as_dict()) + self.put_json('/v2/config/contactgroups', g.as_dict()) self.assertIsNotNone( self.mongoconnection.shinken.contactgroups.find_one(g.as_dict()) diff --git a/surveil/tests/api/controllers/v2/config/test_contacts.py b/surveil/tests/api/controllers/v2/config/test_contacts.py index 5510668..a8b4c85 100644 --- a/surveil/tests/api/controllers/v2/config/test_contacts.py +++ b/surveil/tests/api/controllers/v2/config/test_contacts.py @@ -68,7 +68,7 @@ class TestContactsController(functionalTest.FunctionalTest): contact_name='John' ) - self.post_json('/v2/config/contacts', c.as_dict()) + self.put_json('/v2/config/contacts', c.as_dict()) self.assertIsNotNone( self.mongoconnection.shinken.contacts.find_one(c.as_dict()) diff --git a/surveil/tests/api/controllers/v2/config/test_hostgroup.py b/surveil/tests/api/controllers/v2/config/test_hostgroup.py index 04e0323..d948bf7 100644 --- a/surveil/tests/api/controllers/v2/config/test_hostgroup.py +++ b/surveil/tests/api/controllers/v2/config/test_hostgroup.py @@ -71,7 +71,7 @@ class TestHostGroupsController(functionalTest.FunctionalTest): members=['host1', 'host2'], ) - self.post_json('/v2/config/hostgroups', s.as_dict()) + self.put_json('/v2/config/hostgroups', s.as_dict()) self.assertIsNotNone( self.mongoconnection.shinken.hostgroups.find_one(s.as_dict()) diff --git a/surveil/tests/api/controllers/v2/config/test_hosts.py b/surveil/tests/api/controllers/v2/config/test_hosts.py index 861d527..5d5bdbf 100644 --- a/surveil/tests/api/controllers/v2/config/test_hosts.py +++ b/surveil/tests/api/controllers/v2/config/test_hosts.py @@ -189,7 +189,7 @@ class TestHostController(functionalTest.FunctionalTest): "custom_fields": {}, "use": [] } - response = self.post_json("/v2/config/hosts", params=new_host) + response = self.put_json("/v2/config/hosts", params=new_host) hosts = [host.Host(**h).as_dict() for h in self.mongoconnection.shinken.hosts.find(None, {'_id': 0})] diff --git a/surveil/tests/api/controllers/v2/config/test_macromodulations.py b/surveil/tests/api/controllers/v2/config/test_macromodulations.py index 1bdd53e..e27d040 100644 --- a/surveil/tests/api/controllers/v2/config/test_macromodulations.py +++ b/surveil/tests/api/controllers/v2/config/test_macromodulations.py @@ -97,7 +97,7 @@ class TestMacroModulationController(functionalTest.FunctionalTest): } } - self.post_json('/v2/config/macromodulations', m) + self.put_json('/v2/config/macromodulations', m) self.assertIsNotNone( self.mongoconnection.shinken.macromodulations.find_one( diff --git a/surveil/tests/api/controllers/v2/config/test_notificationways.py b/surveil/tests/api/controllers/v2/config/test_notificationways.py index eeb980e..196fb35 100644 --- a/surveil/tests/api/controllers/v2/config/test_notificationways.py +++ b/surveil/tests/api/controllers/v2/config/test_notificationways.py @@ -106,7 +106,7 @@ class TestNotificationWayController(functionalTest.FunctionalTest): 'min_business_impact': 5 } - self.post_json('/v2/config/notificationways', notificationway) + self.put_json('/v2/config/notificationways', notificationway) self.assertIsNotNone( self.mongoconnection. diff --git a/surveil/tests/api/controllers/v2/config/test_realms.py b/surveil/tests/api/controllers/v2/config/test_realms.py index 65a6851..65f6910 100644 --- a/surveil/tests/api/controllers/v2/config/test_realms.py +++ b/surveil/tests/api/controllers/v2/config/test_realms.py @@ -64,7 +64,7 @@ class TestRealmsController(functionalTest.FunctionalTest): default=1 ) - self.post_json('/v2/config/realms', r.as_dict()) + self.put_json('/v2/config/realms', r.as_dict()) self.assertIsNotNone( self.mongoconnection.shinken.realms.find_one(r.as_dict()) diff --git a/surveil/tests/api/controllers/v2/config/test_servicegroup.py b/surveil/tests/api/controllers/v2/config/test_servicegroup.py index 20a378f..cd8cf5e 100644 --- a/surveil/tests/api/controllers/v2/config/test_servicegroup.py +++ b/surveil/tests/api/controllers/v2/config/test_servicegroup.py @@ -72,7 +72,7 @@ class TestServiceGroupsController(functionalTest.FunctionalTest): members=['service1'], ) - self.post_json('/v2/config/servicegroups', s.as_dict()) + self.put_json('/v2/config/servicegroups', s.as_dict()) self.assertIsNotNone( self.mongoconnection.shinken.servicegroups.find_one(s.as_dict()) diff --git a/surveil/tests/api/controllers/v2/config/test_services.py b/surveil/tests/api/controllers/v2/config/test_services.py index 2e1e1d7..857c5de 100644 --- a/surveil/tests/api/controllers/v2/config/test_services.py +++ b/surveil/tests/api/controllers/v2/config/test_services.py @@ -135,7 +135,7 @@ class TestServiceController(functionalTest.FunctionalTest): "contact_groups": ["linux-admins"], "use": [] } - response = self.post_json( + response = self.put_json( "/v2/config/services", params=new_service ) diff --git a/surveil/tests/api/controllers/v2/config/test_timeperiods.py b/surveil/tests/api/controllers/v2/config/test_timeperiods.py index 13033dc..91862f4 100644 --- a/surveil/tests/api/controllers/v2/config/test_timeperiods.py +++ b/surveil/tests/api/controllers/v2/config/test_timeperiods.py @@ -76,7 +76,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest): "tuesday": "pizza day" }} - self.post_json('/v2/config/timeperiods', t) + self.put_json('/v2/config/timeperiods', t) self.assertIsNotNone( self.mongoconnection.shinken.timeperiods.find_one( diff --git a/tools/docker/alignak_container/Dockerfile b/tools/docker/alignak_container/Dockerfile index 568010f..b549bd4 100644 --- a/tools/docker/alignak_container/Dockerfile +++ b/tools/docker/alignak_container/Dockerfile @@ -32,7 +32,7 @@ RUN cd /tmp && \ rm -rfv /tmp/mod-booster-nrpe* # mod-surveil -RUN pip install python-surveilclient==0.11.0 +RUN pip install python-surveilclient==0.13.2 RUN cd /tmp && \ wget -O mod-surveil-config.tar.gz https://github.com/Alignak-monitoring/mod-surveil/archive/fdc98b4fc036aa483ecb58459f11f9a87cf2254a.tar.gz && \ tar -zxvf mod-surveil-config.tar.gz && \ @@ -78,7 +78,7 @@ RUN chmod u+s /bin/ping RUN chmod u+s /bin/ping6 # Download plugins -ENV MONITORING_TOOLS_VERSION 0.3.2 +ENV MONITORING_TOOLS_VERSION 0.4.1 RUN apt-get update && apt-get install -y subversion && \ svn checkout https://github.com/savoirfairelinux/monitoring-tools/tags/${MONITORING_TOOLS_VERSION}/plugins/check-glance /plugins/check_glance && \ svn checkout https://github.com/savoirfairelinux/monitoring-tools/tags/${MONITORING_TOOLS_VERSION}/plugins/check-keystone /plugins/check_keystone && \ @@ -92,7 +92,7 @@ RUN apt-get update && apt-get install -y subversion && \ RUN mkdir -p /opt/surveilplugins RUN virtualenv /opt/surveilplugins/env ENV PATH=$PATH:/opt/surveilplugins/env/bin -RUN /opt/surveilplugins/env/bin/pip install "pbr>=1.3,<2.0" shinkenplugins python-keystoneclient python-glanceclient +RUN /opt/surveilplugins/env/bin/pip install -U "pbr>=1.3,<2.0" shinkenplugins python-keystoneclient python-glanceclient ## Install Plugins RUN mkdir -p /usr/lib/monitoring/plugins/sfl