From: Tony Mack Date: Tue, 12 Sep 2006 18:04:02 +0000 (+0000) Subject: 1- addes validate_description function X-Git-Tag: pycurl-7_13_1~762 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=09ff846b56dd358c70adc8f7e24e663ca41bb940;p=plcapi.git 1- addes validate_description function 2- modified validate_name function to remove trailing/leading spaces --- diff --git a/PLC/NodeGroups.py b/PLC/NodeGroups.py index b2d4024..1a02200 100644 --- a/PLC/NodeGroups.py +++ b/PLC/NodeGroups.py @@ -4,7 +4,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: NodeGroups.py,v 1.3 2006/09/07 23:44:49 mlhuang Exp $ +# $Id: NodeGroups.py,v 1.4 2006/09/12 16:08:50 tmack Exp $ # from types import StringTypes @@ -40,12 +40,30 @@ class NodeGroup(Row): self.api = api def validate_name(self, name): + #remove leading and trailing spaces + name = name.strip() + + #make sure name is not blank after we removed the spaces + if not len(name) > 0: + raise PLCInvalidArgument, "Invalid Node Group Name" + + #make sure name doenst alredy exist conflicts = NodeGroups(self.api, [name]) for nodegroup_id in conflicts: if 'nodegroup_id' not in self or self['nodegroup_id'] != nodegroup_id: raise PLCInvalidArgument, "Node group name already in use" - return name + + return name + def validate_description(self, description): + #remove trailing and leading spaces + description = description.strip() + + #make sure decription is not blank after we removed the spaces + if not len(description) > 0: + raise PLCInvalidArgument, "Invalid Node Group Description" + + return description def add_node(self, node, commit = True): """