X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FNodeGroups.py;h=bbbb6b3027582a248cbc1408cc515ddcc36f179c;hb=1f446bdabf02495a849c8c8d2d5ef6d2eea491af;hp=9292467a2b6ec200ea2bb39d10ad839646f8d808;hpb=eafc0194bc0dde66e31315a72f2cb05775c9800b;p=plcapi.git diff --git a/PLC/NodeGroups.py b/PLC/NodeGroups.py index 9292467..bbbb6b3 100644 --- a/PLC/NodeGroups.py +++ b/PLC/NodeGroups.py @@ -4,8 +4,6 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# from types import StringTypes @@ -31,26 +29,26 @@ class NodeGroup(Row): 'nodegroup_id': Parameter(int, "Node group identifier"), 'groupname': Parameter(str, "Node group name", max = 50), 'tag_type_id': Parameter (int, "Node tag type id"), - 'tagvalue' : Parameter(str, "value that the nodegroup definition is based upon"), + 'value' : Parameter(str, "value that the nodegroup definition is based upon"), 'tagname' : Parameter(str, "Tag name that the nodegroup definition is based upon"), 'conf_file_ids': Parameter([int], "List of configuration files specific to this node group"), 'node_ids' : Parameter([int], "List of node_ids that belong to this nodegroup"), - } + } related_fields = { } def validate_name(self, name): - # Make sure name is not blank + # Make sure name is not blank if not len(name): - raise PLCInvalidArgument, "Invalid node group name" - - # Make sure node group does not alredy exist - conflicts = NodeGroups(self.api, [name]) - for nodegroup in conflicts: + raise PLCInvalidArgument, "Invalid node group name" + + # Make sure node group does not alredy exist + conflicts = NodeGroups(self.api, [name]) + for nodegroup in conflicts: if 'nodegroup_id' not in self or self['nodegroup_id'] != nodegroup['nodegroup_id']: - raise PLCInvalidArgument, "Node group name already in use" + raise PLCInvalidArgument, "Node group name already in use" - return name + return name def associate_conf_files(self, auth, field, value): """ @@ -71,10 +69,10 @@ class NodeGroup(Row): stale_conf_files = set(self['conf_file_ids']).difference(conf_file_ids) for new_conf_file in new_conf_files: - AddConfFileToNodeGroup.__call__(AddConfFileToNodeGroup(self.api), + AddConfFileToNodeGroup.__call__(AddConfFileToNodeGroup(self.api), auth, new_conf_file, self['nodegroup_id']) for stale_conf_file in stale_conf_files: - DeleteConfFileFromNodeGroup.__call__(DeleteConfFileFromNodeGroup(self.api), + DeleteConfFileFromNodeGroup.__call__(DeleteConfFileFromNodeGroup(self.api), auth, stale_conf_file, self['nodegroup_id']) @@ -100,5 +98,13 @@ class NodeGroups(Table): elif isinstance(nodegroup_filter, dict): nodegroup_filter = Filter(NodeGroup.fields, nodegroup_filter) sql += " AND (%s) %s" % nodegroup_filter.sql(api, "AND") + elif isinstance(nodegroup_filter, (int, long)): + nodegroup_filter = Filter(NodeGroup.fields, {'nodegroup_id': nodegroup_filter}) + sql += " AND (%s) %s" % nodegroup_filter.sql(api, "AND") + elif isinstance(nodegroup_filter, StringTypes): + nodegroup_filter = Filter(NodeGroup.fields, {'groupname': nodegroup_filter}) + sql += " AND (%s) %s" % nodegroup_filter.sql(api, "AND") + else: + raise PLCInvalidArgument, "Wrong node group filter %r"%nodegroup_filter self.selectall(sql)