from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
-from PLC.NodeGroups import NodeGroup, NodeGroups
from PLC.Auth import Auth
+from PLC.NodeGroups import NodeGroup, NodeGroups
+from PLC.NodeTagTypes import NodeTagType, NodeTagTypes
+from PLC.NodeTags import NodeTag, NodeTags
+
can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
class AddNodeGroup(Method):
accepts = [
Auth(),
- nodegroup_fields
+ NodeGroup.fields['groupname'],
+ Mixed(NodeTagType.fields['node_tag_type_id'],
+ NodeTagType.fields['tagname']),
+ NodeTag.fields['tagvalue'],
]
returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
- def call(self, auth, nodegroup_fields):
- nodegroup_fields = dict([f for f in nodegroup_fields.items() if can_update(f)])
+ def call(self, auth, groupname, node_tag_type_id_or_tagname, tagvalue):
+ # locate tag type
+ tag_types = NodeTagTypes (self.api,node_tag_type_id_or_tagname)
+ if not(tag_types):
+ raise PLCInvalidArgument, "No such tag type %r"%node_tag_type_id_or_tagname
+ tag_type=tag_types[0]
+
+ nodegroup_fields = { 'groupname' : groupname,
+ 'node_tag_type_id' : tag_type['node_tag_type_id'],
+ 'tagvalue' : tagvalue }
nodegroup = NodeGroup(self.api, nodegroup_fields)
nodegroup.sync()
from PLC.NodeGroups import NodeGroup, NodeGroups
from PLC.Auth import Auth
-related_fields = NodeGroup.related_fields.keys()
-can_update = lambda (field, value): field in \
- ['groupname', 'tagname','tagvalue'] + \
- related_fields
+can_update = lambda (field, value): field in ['groupname','tagvalue']
class UpdateNodeGroup(Method):
"""
roles = ['admin']
- nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items() + NodeGroup.related_fields.items()))
+ nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items())
accepts = [
Auth(),
# Get nodegroup information
nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
if not nodegroups:
- raise PLCInvalidArgument, "No such nodegroup"
+ raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
nodegroup = nodegroups[0]
- # Make requested associations
- for field in related_fields:
- if field in nodegroup_fields:
- nodegroup.associate(auth, field, nodegroup_fields[field])
- nodegroup_fields.pop(field)
-
nodegroup.update(nodegroup_fields)
nodegroup.sync()