diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index aed366da..bf2ede82 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -28,10 +28,23 @@ from __future__ import unicode_literals, absolute_import from rattail_tempmon.db import model as tempmon +import formalchemy as fa + from tailbone import forms +from tailbone.db import TempmonSession from tailbone.views.tempmon import MasterView, ClientFieldRenderer +def unique_config_key(value, field): + probe = field.parent.model + query = TempmonSession.query(tempmon.Probe)\ + .filter(tempmon.Probe.config_key == value) + if probe.uuid: + query = query.filter(tempmon.Probe.uuid != probe.uuid) + if query.count(): + raise fa.ValidationError("Config key must be unique") + + class TempmonProbeView(MasterView): """ Master view for tempmon probes. @@ -63,6 +76,7 @@ class TempmonProbeView(MasterView): readonly=True) def _preconfigure_fieldset(self, fs): + fs.config_key.set(validate=unique_config_key) fs.client.set(label="TempMon Client", renderer=ClientFieldRenderer) fs.appliance_type.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_APPLIANCE_TYPE)) fs.status.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_PROBE_STATUS))