Create config object use now PUT

Change-Id: Id339b36e202c09c3b2eaa43674a4a5a2319be2a6
This commit is contained in:
flavien peyre 2015-07-29 12:08:42 -04:00 committed by aviau
parent 4ee06a6c93
commit 4b2538b37e
29 changed files with 327 additions and 235 deletions

View File

@ -10,7 +10,7 @@ keystonemiddleware
PasteDeploy PasteDeploy
influxdb==2.7.3 influxdb==2.7.3
pika pika
python-surveilclient==0.12.0 python-surveilclient==0.13.2
six six
docker-py docker-py
mongoengine mongoengine

View File

@ -46,5 +46,5 @@ class ConfigController(rest.RestController):
BusinessImpactModulationsController()) BusinessImpactModulationsController())
notificationways = notificationways.NotificationWaysController() notificationways = notificationways.NotificationWaysController()
checkmodulations = checkmodulations.CheckModulationsController() checkmodulations = checkmodulations.CheckModulationsController()
macromodulations = macromodulations.MacroModulationController() macromodulations = macromodulations.MacroModulationsController()
# engine = EngineController() # engine = EngineController()

View File

@ -15,7 +15,6 @@
import pecan import pecan
from pecan import rest from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import businessimpactmodulation as mod from surveil.api.datamodel.config import businessimpactmodulation as mod
@ -25,6 +24,11 @@ from surveil.common import util
class BusinessImpactModulationsController(rest.RestController): class BusinessImpactModulationsController(rest.RestController):
@pecan.expose()
def _lookup(self, businessimpactmodulation_name, *remainder):
return BusinessImpactModulationController(
businessimpactmodulation_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([mod.BusinessImpactModulation]) @wsme_pecan.wsexpose([mod.BusinessImpactModulation])
def get_all(self): def get_all(self):
@ -34,18 +38,10 @@ class BusinessImpactModulationsController(rest.RestController):
return modulations return modulations
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, wtypes.text) @wsme_pecan.wsexpose(mod.BusinessImpactModulation,
def get_one(self, modulation_name): body=mod.BusinessImpactModulation,
"""Returns a specific business impact modulation.""" status_code=201)
handler = bh.BusinessImpactModulationHandler(pecan.request) def put(self, data):
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):
"""Create a new business impact modulation. """Create a new business impact modulation.
:param data: a business impact modulation within the request body. :param data: a business impact modulation within the request body.
@ -53,26 +49,41 @@ class BusinessImpactModulationsController(rest.RestController):
handler = bh.BusinessImpactModulationHandler(pecan.request) handler = bh.BusinessImpactModulationHandler(pecan.request)
handler.create(data) 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, @wsme_pecan.wsexpose(mod.BusinessImpactModulation)
wtypes.text, def get(self):
status_code=204)
def delete(self, modulation_name):
"""Returns a specific business impact modulation.""" """Returns a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request) 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( handler.delete(
{"business_impact_modulation_name": modulation_name} {"business_impact_modulation_name": self._id}
) )
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, @wsme_pecan.wsexpose(None,
wtypes.text,
body=mod.BusinessImpactModulation, body=mod.BusinessImpactModulation,
status_code=204) status_code=204)
def put(self, modulaion_name, modulation): def put(self, modulation):
"""Update a specific business impact modulation.""" """Update a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request) handler = bh.BusinessImpactModulationHandler(pecan.request)
handler.update( handler.update(
{"business_impact_modulation_name": modulaion_name}, {"business_impact_modulation_name": self._id},
modulation modulation
) )

View File

@ -25,6 +25,10 @@ from surveil.common import util
class CheckModulationsController(rest.RestController): class CheckModulationsController(rest.RestController):
@pecan.expose()
def _lookup(self, checkmodulation_name, *remainder):
return CheckModulationController(checkmodulation_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([checkmodulation.CheckModulation]) @wsme_pecan.wsexpose([checkmodulation.CheckModulation])
def get_all(self): def get_all(self):
@ -33,19 +37,9 @@ class CheckModulationsController(rest.RestController):
checkmodulations = handler.get_all() checkmodulations = handler.get_all()
return checkmodulations 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=checkmodulation.CheckModulation, status_code=201) @wsme_pecan.wsexpose(body=checkmodulation.CheckModulation, status_code=201)
def post(self, data): def put(self, data):
"""Create a new check modulation. """Create a new check modulation.
:param data: a check modulation within the request body. :param data: a check modulation within the request body.
@ -53,23 +47,38 @@ class CheckModulationsController(rest.RestController):
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation, class CheckModulationController(rest.RestController):
wtypes.text, status_code=204)
def delete(self, checkmodulation_name): def __init__(self, check_modulation_name):
"""Returns a specific check modulation.""" pecan.request.context['check_modulation_name'] = check_modulation_name
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) self._id = check_modulation_name
handler.delete({"checkmodulation_name": checkmodulation_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=checkmodulation.CheckModulation,
status_code=204) status_code=204)
def put(self, checkmodulation_name, checkmodulation): def put(self, checkmodulation):
"""Update a specific check modulation.""" """Update a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
handler.update( handler.update(
{"checkmodulation_name": checkmodulation_name}, {"checkmodulation_name": self._id},
checkmodulation checkmodulation
) )
@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

View File

@ -71,7 +71,7 @@ class CommandsController(rest.RestController):
@wsme_pecan.wsexpose(command.Command, @wsme_pecan.wsexpose(command.Command,
body=command.Command, body=command.Command,
status_code=201) status_code=201)
def post(self, data): def put(self, data):
"""Create a new command. """Create a new command.
:param data: a command within the request body. :param data: a command within the request body.

View File

@ -25,6 +25,10 @@ from surveil.common import util
class ContactGroupsController(rest.RestController): class ContactGroupsController(rest.RestController):
@pecan.expose()
def _lookup(self, contactgroup_name, *remainder):
return ContactGroupController(contactgroup_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([contactgroup.ContactGroup]) @wsme_pecan.wsexpose([contactgroup.ContactGroup])
def get_all(self): def get_all(self):
@ -33,17 +37,9 @@ class ContactGroupsController(rest.RestController):
contact_groups = handler.get_all() contact_groups = handler.get_all()
return contact_groups 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=contactgroup.ContactGroup, status_code=201) @wsme_pecan.wsexpose(body=contactgroup.ContactGroup, status_code=201)
def post(self, data): def put(self, data):
"""Create a new contact group. """Create a new contact group.
:param data: a contact group within the request body. :param data: a contact group within the request body.
@ -51,20 +47,33 @@ class ContactGroupsController(rest.RestController):
handler = contactgroup_handler.ContactGroupHandler(pecan.request) handler = contactgroup_handler.ContactGroupHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text, class ContactGroupController(rest.RestController):
status_code=204)
def delete(self, group_name): def __init__(self, contactgroup_name):
"""Delete a specific contact group.""" pecan.request.context['contactgroup_name'] = contactgroup_name
handler = contactgroup_handler.ContactGroupHandler(pecan.request) self._id = contactgroup_name
handler.delete({"contactgroup_name": group_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=contactgroup.ContactGroup,
status_code=204) status_code=204)
def put(self, group_name, contactgroup): def put(self, contactgroup):
"""Update a specific contact group.""" """Update a specific contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request) 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

View File

@ -25,25 +25,21 @@ from surveil.common import util
class ContactsController(rest.RestController): class ContactsController(rest.RestController):
@pecan.expose()
def _lookup(self, contact_name, *remainder):
return ContactController(contact_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([contact.Contact]) @wsme_pecan.wsexpose([contact.Contact])
def get_all(self): def get_all(self):
"""Returns all hosts.""" """Returns all contacts."""
handler = contact_handler.ContactHandler(pecan.request) handler = contact_handler.ContactHandler(pecan.request)
hosts = handler.get_all() hosts = handler.get_all()
return hosts 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=contact.Contact, status_code=201) @wsme_pecan.wsexpose(body=contact.Contact, status_code=201)
def post(self, data): def put(self, data):
"""Create a new contact. """Create a new contact.
:param data: a contact within the request body. :param data: a contact within the request body.
@ -51,19 +47,33 @@ class ContactsController(rest.RestController):
handler = contact_handler.ContactHandler(pecan.request) handler = contact_handler.ContactHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact, wtypes.text, status_code=204) class ContactController(rest.RestController):
def delete(self, contact_name):
"""Returns a specific contact.""" def __init__(self, contact_name):
handler = contact_handler.ContactHandler(pecan.request) pecan.request.context['contact_name'] = contact_name
handler.delete({"contact_name": contact_name}) self._id = contact_name
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, def delete(self):
body=contact.Contact,
status_code=204)
def put(self, contact_name, contact):
"""Returns a specific contact.""" """Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request) 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

View File

@ -25,6 +25,10 @@ from surveil.common import util
class HostGroupsController(rest.RestController): class HostGroupsController(rest.RestController):
@pecan.expose()
def _lookup(self, hostgroup_name, *remainder):
return HostGroupController(hostgroup_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([hostgroup.HostGroup]) @wsme_pecan.wsexpose([hostgroup.HostGroup])
def get_all(self): def get_all(self):
@ -33,17 +37,9 @@ class HostGroupsController(rest.RestController):
host_groups = handler.get_all() host_groups = handler.get_all()
return host_groups 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=hostgroup.HostGroup, status_code=201) @wsme_pecan.wsexpose(body=hostgroup.HostGroup, status_code=201)
def post(self, data): def put(self, data):
"""Create a new host group. """Create a new host group.
:param data: a host group within the request body. :param data: a host group within the request body.
@ -51,19 +47,33 @@ class HostGroupsController(rest.RestController):
handler = hostgroup_handler.HostGroupHandler(pecan.request) handler = hostgroup_handler.HostGroupHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text, status_code=204) class HostGroupController(rest.RestController):
def delete(self, group_name):
"""Returns a specific host group.""" def __init__(self, hostgroup_name):
handler = hostgroup_handler.HostGroupHandler(pecan.request) pecan.request.context['hostgroup_name'] = hostgroup_name
handler.delete({"hostgroup_name": group_name}) self._id = hostgroup_name
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=hostgroup.HostGroup,
status_code=204) status_code=204)
def put(self, group_name, hostgroup): def put(self, hostgroup):
"""Update a specific host group.""" """Update a specific host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request) 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

View File

@ -134,7 +134,7 @@ class HostsController(rest.RestController):
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(host.Host, body=host.Host, status_code=201) @wsme_pecan.wsexpose(host.Host, body=host.Host, status_code=201)
def post(self, data): def put(self, data):
"""Create a new host. """Create a new host.
:param data: a host within the request body. :param data: a host within the request body.

View File

@ -23,7 +23,11 @@ from surveil.api.handlers.config import macromodulation_handler
from surveil.common import util 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([macromodulation.MacroModulation]) @wsme_pecan.wsexpose([macromodulation.MacroModulation])
@ -33,19 +37,9 @@ class MacroModulationController(rest.RestController):
modulations = handler.get_all() modulations = handler.get_all()
return modulations 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=macromodulation.MacroModulation, status_code=201) @wsme_pecan.wsexpose(body=macromodulation.MacroModulation, status_code=201)
def post(self, data): def put(self, data):
"""Create a new macro modulation object. """Create a new macro modulation object.
:param data: a macro modulation within the request body. :param data: a macro modulation within the request body.
@ -53,21 +47,36 @@ class MacroModulationController(rest.RestController):
handler = macromodulation_handler.MacroModulationHandler(pecan.request) handler = macromodulation_handler.MacroModulationHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation, class MacroModulationController(rest.RestController):
wtypes.text,
status_code=204) def __init__(self, macromodulation_name):
def delete(self, modulation_name): pecan.request.context['macromodulation_name'] = macromodulation_name
"""Returns a specific macro modulation.""" self._id = macromodulation_name
handler = macromodulation_handler.MacroModulationHandler(pecan.request)
handler.delete({"macromodulation_name": modulation_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation, @wsme_pecan.wsexpose(None,
wtypes.text, 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, body=macromodulation.MacroModulation,
status_code=204) status_code=204)
def put(self, modulation_name, modulation): def put(self, modulation):
"""Update a specific macro modulation.""" """Update a specific macro modulation."""
handler = macromodulation_handler.MacroModulationHandler(pecan.request) 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

View File

@ -25,6 +25,10 @@ from surveil.common import util
class NotificationWaysController(rest.RestController): class NotificationWaysController(rest.RestController):
@pecan.expose()
def _lookup(self, notificationway_name, *remainder):
return NotificationWayController(notificationway_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([notificationway.NotificationWay]) @wsme_pecan.wsexpose([notificationway.NotificationWay])
def get_all(self): def get_all(self):
@ -33,19 +37,9 @@ class NotificationWaysController(rest.RestController):
notificationsway = handler.get_all() notificationsway = handler.get_all()
return notificationsway 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=notificationway.NotificationWay, status_code=201) @wsme_pecan.wsexpose(body=notificationway.NotificationWay, status_code=201)
def post(self, data): def put(self, data):
"""Create a new notification way. """Create a new notification way.
:param data: a notification way within the request body. :param data: a notification way within the request body.
@ -53,26 +47,38 @@ class NotificationWaysController(rest.RestController):
handler = notificationway_handler.NotificationWayHandler(pecan.request) handler = notificationway_handler.NotificationWayHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose( class NotificationWayController(rest.RestController):
notificationway.NotificationWay,
wtypes.text, def __init__(self, notificationway_name):
status_code=204 pecan.request.context['notificationway_name'] = notificationway_name
) self._id = notificationway_name
def delete(self, notificationway_name):
"""Returns a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request)
handler.delete({"notificationway_name": notificationway_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(notificationway.NotificationWay, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=notificationway.NotificationWay,
status_code=204) status_code=204)
def put(self, notificationway_name, notificationway): def put(self, notificationway):
"""Update a specific notification way.""" """Update a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request) handler = notificationway_handler.NotificationWayHandler(pecan.request)
handler.update( handler.update(
{"notificationway_name": notificationway_name}, {"notificationway_name": self._id},
notificationway 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

View File

@ -25,6 +25,10 @@ from surveil.common import util
class RealmsController(rest.RestController): class RealmsController(rest.RestController):
@pecan.expose()
def _lookup(self, realm_name, *remainder):
return RealmController(realm_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([realm.Realm]) @wsme_pecan.wsexpose([realm.Realm])
def get_all(self): def get_all(self):
@ -33,17 +37,9 @@ class RealmsController(rest.RestController):
realms = handler.get_all() realms = handler.get_all()
return realms 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=realm.Realm, status_code=201) @wsme_pecan.wsexpose(body=realm.Realm, status_code=201)
def post(self, data): def put(self, data):
"""Create a new realm. """Create a new realm.
:param data: a realm within the request body. :param data: a realm within the request body.
@ -51,22 +47,36 @@ class RealmsController(rest.RestController):
handler = realm_handler.RealmHandler(pecan.request) handler = realm_handler.RealmHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm, wtypes.text, status_code=204) class RealmController(rest.RestController):
def delete(self, realm_name):
"""Deletes a specific realm.""" def __init__(self, realm_name):
handler = realm_handler.RealmHandler(pecan.request) pecan.request.context['realm_name'] = realm_name
handler.delete({"realm_name": realm_name}) self._id = realm_name
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=realm.Realm,
status_code=204) status_code=204)
def put(self, realm_name, realm): def put(self, realm):
"""Updates a specific realm.""" """Updates a specific realm."""
handler = realm_handler.RealmHandler(pecan.request) handler = realm_handler.RealmHandler(pecan.request)
handler.update( handler.update(
{"realm_name": realm_name}, {"realm_name": self._id},
realm 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

View File

@ -25,6 +25,10 @@ from surveil.common import util
class ServiceGroupsController(rest.RestController): class ServiceGroupsController(rest.RestController):
@pecan.expose()
def _lookup(self, servicegroup_name, *remainder):
return ServiceGroupController(servicegroup_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([servicegroup.ServiceGroup]) @wsme_pecan.wsexpose([servicegroup.ServiceGroup])
def get_all(self): def get_all(self):
@ -33,17 +37,9 @@ class ServiceGroupsController(rest.RestController):
service_groups = handler.get_all() service_groups = handler.get_all()
return service_groups 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=servicegroup.ServiceGroup, status_code=201) @wsme_pecan.wsexpose(body=servicegroup.ServiceGroup, status_code=201)
def post(self, data): def put(self, data):
"""Create a new service group. """Create a new service group.
:param data: a service group within the request body. :param data: a service group within the request body.
@ -51,20 +47,33 @@ class ServiceGroupsController(rest.RestController):
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text, class ServiceGroupController(rest.RestController):
status_code=204)
def delete(self, group_name): def __init__(self, servicegroup_name):
"""Returns a specific service group.""" pecan.request.context['servicegroup_name'] = servicegroup_name
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) self._id = servicegroup_name
handler.delete({"servicegroup_name": group_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, 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, body=servicegroup.ServiceGroup,
status_code=204) status_code=204)
def put(self, group_name, servicegroup): def put(self, servicegroup):
"""Update a specific service group.""" """Update a specific service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) 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

View File

@ -37,7 +37,7 @@ class ServicesController(rest.RestController):
@wsme_pecan.wsexpose(service.Service, @wsme_pecan.wsexpose(service.Service,
body=service.Service, body=service.Service,
status_code=201) status_code=201)
def post(self, data): def put(self, data):
"""Create a new service. """Create a new service.
:param data: a service within the request body. :param data: a service within the request body.

View File

@ -25,6 +25,10 @@ from surveil.common import util
class TimePeriodsController(rest.RestController): class TimePeriodsController(rest.RestController):
@pecan.expose()
def _lookup(self, timeperiod_name, *remainder):
return TimePeriodController(timeperiod_name), remainder
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose([timeperiod.TimePeriod]) @wsme_pecan.wsexpose([timeperiod.TimePeriod])
def get_all(self): def get_all(self):
@ -33,17 +37,9 @@ class TimePeriodsController(rest.RestController):
time_periods = handler.get_all() time_periods = handler.get_all()
return time_periods 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']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=timeperiod.TimePeriod, status_code=201) @wsme_pecan.wsexpose(body=timeperiod.TimePeriod, status_code=201)
def post(self, data): def put(self, data):
"""Create a new time period. """Create a new time period.
:param data: a time period within the request body. :param data: a time period within the request body.
@ -51,19 +47,32 @@ class TimePeriodsController(rest.RestController):
handler = timeperiod_handler.TimePeriodHandler(pecan.request) handler = timeperiod_handler.TimePeriodHandler(pecan.request)
handler.create(data) handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text, status_code=204) class TimePeriodController(rest.RestController):
def delete(self, timeperiod_name):
"""Returns a specific time period.""" def __init__(self, timeperiod_name):
handler = timeperiod_handler.TimePeriodHandler(pecan.request) pecan.request.context['timeperiod_name'] = timeperiod_name
handler.delete({"timeperiod_name": timeperiod_name}) self._id = timeperiod_name
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod, @wsme_pecan.wsexpose(None, status_code=204)
wtypes.text, def delete(self):
body=timeperiod.TimePeriod, """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) status_code=204)
def put(self, timeperiod_name, timeperiod): def put(self, timeperiod):
"""Update a specific time period.""" """Update a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request) 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

View File

@ -76,7 +76,7 @@ class TestBusinessImpactModulationController(functionalTest.FunctionalTest):
self.mongoconnection.shinken.businessimpactmodulations.find_one(m) self.mongoconnection.shinken.businessimpactmodulations.find_one(m)
) )
self.post_json('/v2/config/businessimpactmodulations', m) self.put_json('/v2/config/businessimpactmodulations', m)
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.businessimpactmodulations.find_one(m) self.mongoconnection.shinken.businessimpactmodulations.find_one(m)

View File

@ -71,7 +71,7 @@ class TestCheckModulationsController(functionalTest.FunctionalTest):
"check_period": "evening" "check_period": "evening"
} }
self.post_json('/v2/config/checkmodulations', t) self.put_json('/v2/config/checkmodulations', t)
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.checkmodulations.find_one( self.mongoconnection.shinken.checkmodulations.find_one(
{"checkmodulation_name": 'ping_evening', {"checkmodulation_name": 'ping_evening',

View File

@ -89,7 +89,7 @@ class TestCommandController(functionalTest.FunctionalTest):
"command_name": "newcommand", "command_name": "newcommand",
"command_line": "/usr/bin/newcommand -hello" "command_line": "/usr/bin/newcommand -hello"
} }
response = self.post_json( response = self.put_json(
"/v2/config/commands", "/v2/config/commands",
params=new_command params=new_command
) )

View File

@ -71,7 +71,7 @@ class TestContactGroupsController(functionalTest.FunctionalTest):
members=["bob", "alice"], members=["bob", "alice"],
) )
self.post_json('/v2/config/contactgroups', g.as_dict()) self.put_json('/v2/config/contactgroups', g.as_dict())
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.contactgroups.find_one(g.as_dict()) self.mongoconnection.shinken.contactgroups.find_one(g.as_dict())

View File

@ -68,7 +68,7 @@ class TestContactsController(functionalTest.FunctionalTest):
contact_name='John' contact_name='John'
) )
self.post_json('/v2/config/contacts', c.as_dict()) self.put_json('/v2/config/contacts', c.as_dict())
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.contacts.find_one(c.as_dict()) self.mongoconnection.shinken.contacts.find_one(c.as_dict())

View File

@ -71,7 +71,7 @@ class TestHostGroupsController(functionalTest.FunctionalTest):
members=['host1', 'host2'], members=['host1', 'host2'],
) )
self.post_json('/v2/config/hostgroups', s.as_dict()) self.put_json('/v2/config/hostgroups', s.as_dict())
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.hostgroups.find_one(s.as_dict()) self.mongoconnection.shinken.hostgroups.find_one(s.as_dict())

View File

@ -189,7 +189,7 @@ class TestHostController(functionalTest.FunctionalTest):
"custom_fields": {}, "custom_fields": {},
"use": [] "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 hosts = [host.Host(**h).as_dict() for h
in self.mongoconnection.shinken.hosts.find(None, {'_id': 0})] in self.mongoconnection.shinken.hosts.find(None, {'_id': 0})]

View File

@ -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.assertIsNotNone(
self.mongoconnection.shinken.macromodulations.find_one( self.mongoconnection.shinken.macromodulations.find_one(

View File

@ -106,7 +106,7 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
'min_business_impact': 5 'min_business_impact': 5
} }
self.post_json('/v2/config/notificationways', notificationway) self.put_json('/v2/config/notificationways', notificationway)
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection. self.mongoconnection.

View File

@ -64,7 +64,7 @@ class TestRealmsController(functionalTest.FunctionalTest):
default=1 default=1
) )
self.post_json('/v2/config/realms', r.as_dict()) self.put_json('/v2/config/realms', r.as_dict())
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.realms.find_one(r.as_dict()) self.mongoconnection.shinken.realms.find_one(r.as_dict())

View File

@ -72,7 +72,7 @@ class TestServiceGroupsController(functionalTest.FunctionalTest):
members=['service1'], members=['service1'],
) )
self.post_json('/v2/config/servicegroups', s.as_dict()) self.put_json('/v2/config/servicegroups', s.as_dict())
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.servicegroups.find_one(s.as_dict()) self.mongoconnection.shinken.servicegroups.find_one(s.as_dict())

View File

@ -135,7 +135,7 @@ class TestServiceController(functionalTest.FunctionalTest):
"contact_groups": ["linux-admins"], "contact_groups": ["linux-admins"],
"use": [] "use": []
} }
response = self.post_json( response = self.put_json(
"/v2/config/services", "/v2/config/services",
params=new_service params=new_service
) )

View File

@ -76,7 +76,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
"tuesday": "pizza day" "tuesday": "pizza day"
}} }}
self.post_json('/v2/config/timeperiods', t) self.put_json('/v2/config/timeperiods', t)
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.timeperiods.find_one( self.mongoconnection.shinken.timeperiods.find_one(

View File

@ -32,7 +32,7 @@ RUN cd /tmp && \
rm -rfv /tmp/mod-booster-nrpe* rm -rfv /tmp/mod-booster-nrpe*
# mod-surveil # mod-surveil
RUN pip install python-surveilclient==0.11.0 RUN pip install python-surveilclient==0.13.2
RUN cd /tmp && \ RUN cd /tmp && \
wget -O mod-surveil-config.tar.gz https://github.com/Alignak-monitoring/mod-surveil/archive/fdc98b4fc036aa483ecb58459f11f9a87cf2254a.tar.gz && \ 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 && \ tar -zxvf mod-surveil-config.tar.gz && \
@ -78,7 +78,7 @@ RUN chmod u+s /bin/ping
RUN chmod u+s /bin/ping6 RUN chmod u+s /bin/ping6
# Download plugins # 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 && \ 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-glance /plugins/check_glance && \
svn checkout https://github.com/savoirfairelinux/monitoring-tools/tags/${MONITORING_TOOLS_VERSION}/plugins/check-keystone /plugins/check_keystone && \ 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 mkdir -p /opt/surveilplugins
RUN virtualenv /opt/surveilplugins/env RUN virtualenv /opt/surveilplugins/env
ENV PATH=$PATH:/opt/surveilplugins/env/bin 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 ## Install Plugins
RUN mkdir -p /usr/lib/monitoring/plugins/sfl RUN mkdir -p /usr/lib/monitoring/plugins/sfl