- change calling convention for Add slightly; if the Add function for
[plcapi.git] / PLC / Methods / AddNodeNetwork.py
index da08581..1ffebfc 100644 (file)
@@ -5,19 +5,22 @@ from PLC.Nodes import Node, Nodes
 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
 from PLC.Auth import PasswordAuth
 
-can_update = lambda (field, value): field not in ['nodenetwork_id']
+can_update = lambda (field, value): field not in ['nodenetwork_id', 'node_id']
 
 class AddNodeNetwork(Method):
     """
+
     Adds a new network for a node. Any values specified in
-    nodenetwork_fields are used, otherwise defaults are used. Acceptable
-    values for method are dhcp, static, proxy, tap, and
-    ipmi. Acceptable value for type is ipv4. If type is static, ip,
-    gateway, network, broadcast, netmask, and dns1 must all be
-    specified in nodenetwork_fields. If type is dhcp, these parameters,
-    even if specified, are ignored.
-
-    PIs and techs may only add networks to their own nodes. ins may
+    nodenetwork_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,
+    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.
@@ -29,6 +32,8 @@ class AddNodeNetwork(Method):
 
     accepts = [
         PasswordAuth(),
+        Mixed(Node.fields['node_id'],
+              Node.fields['hostname']),
         nodenetwork_fields
         ]
 
@@ -38,11 +43,11 @@ class AddNodeNetwork(Method):
     object_type = 'NodeNetwork'
     object_ids = []
 
-    def call(self, auth, nodenetwork_fields = {}):
+    def call(self, auth, node_id_or_hostname, nodenetwork_fields):
         nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
 
         # Check if node exists
-        nodes = Nodes(self.api, [nodenetwork_fields['node_id']]).values()
+        nodes = Nodes(self.api, [node_id_or_hostname]).values()
         if not nodes:
             raise PLCInvalidArgument, "No such node"
        node = nodes[0]
@@ -58,6 +63,7 @@ class AddNodeNetwork(Method):
 
         # Add node network
        nodenetwork = NodeNetwork(self.api, nodenetwork_fields)
+        nodenetwork['node_id'] = node['node_id']
         nodenetwork.sync()
 
        self.object_ids = [node['node_id'], nodenetwork['nodenetwork_id']]