- make Add() calling convention consistent among all functions that
[plcapi.git] / PLC / Methods / AddNodeNetwork.py
index 16e3782..da08581 100644 (file)
@@ -5,9 +5,7 @@ from PLC.Nodes import Node, Nodes
 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
 from PLC.Auth import PasswordAuth
 
-can_update = lambda (field, value): field in \
-             ['ip', 'mac', 'gateway', 'network', 'broadcast', 'netmask',
-              'dns1', 'dns2', 'hostname', 'bwlimit', 'is_primary']
+can_update = lambda (field, value): field not in ['nodenetwork_id']
 
 class AddNodeNetwork(Method):
     """
@@ -27,14 +25,11 @@ class AddNodeNetwork(Method):
 
     roles = ['admin', 'pi', 'tech']
 
-    update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
+    nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items()))
 
     accepts = [
         PasswordAuth(),
-        Node.fields['node_id'],
-        NodeNetwork.fields['method'],
-        NodeNetwork.fields['type'],
-        update_fields
+        nodenetwork_fields
         ]
 
     returns = Parameter(int, 'New nodenetwork_id (> 0) if successful')
@@ -43,11 +38,11 @@ class AddNodeNetwork(Method):
     object_type = 'NodeNetwork'
     object_ids = []
 
-    def call(self, auth, node_id, method, type, nodenetwork_fields = {}):
+    def call(self, auth, nodenetwork_fields = {}):
         nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
 
         # Check if node exists
-        nodes = Nodes(self.api, [node_id]).values()
+        nodes = Nodes(self.api, [nodenetwork_fields['node_id']]).values()
         if not nodes:
             raise PLCInvalidArgument, "No such node"
        node = nodes[0]
@@ -63,10 +58,8 @@ class AddNodeNetwork(Method):
 
         # Add node network
        nodenetwork = NodeNetwork(self.api, nodenetwork_fields)
-        nodenetwork['node_id'] = node_id
-       nodenetwork['method'] = method
-        nodenetwork['type'] = type
         nodenetwork.sync()
-       self.object_ids = [nodenetwork['nodenetwork_id']]       
+
+       self.object_ids = [node['node_id'], nodenetwork['nodenetwork_id']]      
 
         return nodenetwork['nodenetwork_id']