first draft for node tags & new node groups:
[plcapi.git] / PLC / Methods / AddInterface.py
similarity index 58%
rename from PLC/Methods/AddNodeNetwork.py
rename to PLC/Methods/AddInterface.py
index 6e24bce..6bfb4e5 100644 (file)
@@ -2,46 +2,46 @@ from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
+from PLC.Interfaces import Interface, Interfaces
 from PLC.Auth import Auth
 
-can_update = lambda (field, value): field not in ['nodenetwork_id', 'node_id']
+can_update = lambda (field, value): field not in ['interface_id', 'node_id']
 
-class AddNodeNetwork(Method):
+class AddInterface(Method):
     """
 
     Adds a new network for a node. Any values specified in
-    nodenetwork_fields are used, otherwise defaults are
+    interface_fields are used, otherwise defaults are
     used. Acceptable values for method may be retrieved via
     GetNetworkMethods. Acceptable values for type may be retrieved via
     GetNetworkTypes.
 
     If type is static, ip, gateway, network, broadcast, netmask, and
-    dns1 must all be specified in nodenetwork_fields. If type is dhcp,
+    dns1 must all be specified in interface_fields. If type is dhcp,
     these parameters, even if specified, are ignored.
 
     PIs and techs may only add networks to their own nodes. Admins may
     add networks to any node.
 
-    Returns the new nodenetwork_id (> 0) if successful, faults otherwise.
+    Returns the new interface_id (> 0) if successful, faults otherwise.
     """
 
     roles = ['admin', 'pi', 'tech']
 
-    nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items()))
+    interface_fields = dict(filter(can_update, Interface.fields.items()))
 
     accepts = [
         Auth(),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname']),
-        nodenetwork_fields
+        interface_fields
         ]
 
-    returns = Parameter(int, 'New nodenetwork_id (> 0) if successful')
+    returns = Parameter(int, 'New interface_id (> 0) if successful')
 
     
-    def call(self, auth, node_id_or_hostname, nodenetwork_fields):
-        nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
+    def call(self, auth, node_id_or_hostname, interface_fields):
+        interface_fields = dict(filter(can_update, interface_fields.items()))
 
         # Check if node exists
         nodes = Nodes(self.api, [node_id_or_hostname])
@@ -59,15 +59,15 @@ class AddNodeNetwork(Method):
                 raise PLCPermissionDenied, "Not allowed to add node network for specified node"
 
         # Add node network
-       nodenetwork = NodeNetwork(self.api, nodenetwork_fields)
-        nodenetwork['node_id'] = node['node_id']
+       interface = Interface(self.api, interface_fields)
+        interface['node_id'] = node['node_id']
        # if this is the first node network, make it primary
-       if not node['nodenetwork_ids']:
-               nodenetwork['is_primary'] = True
-        nodenetwork.sync()
+       if not node['interface_ids']:
+               interface['is_primary'] = True
+        interface.sync()
        
        # Logging variables
-       self.object_ids = [node['node_id'], nodenetwork['nodenetwork_id']]      
-       self.messgage = "Node network %d added" % nodenetwork['nodenetwork_id']
+       self.object_ids = [node['node_id'], interface['interface_id']]  
+       self.messgage = "Node network %d added" % interface['interface_id']
 
-        return nodenetwork['nodenetwork_id']
+        return interface['interface_id']