- removed 'Adm' prefix
authorTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 18:01:00 +0000 (18:01 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 18:01:00 +0000 (18:01 +0000)
PLC/Methods/AddNodeGroup.py [new file with mode: 0644]
PLC/Methods/AddNodeNetwork.py [new file with mode: 0644]

diff --git a/PLC/Methods/AddNodeGroup.py b/PLC/Methods/AddNodeGroup.py
new file mode 100644 (file)
index 0000000..74ba222
--- /dev/null
@@ -0,0 +1,30 @@
+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 PasswordAuth
+
+class AddNodeGroup(Method):
+    """
+    Adds a new node group. Any values specified in optional_vals are used,
+    otherwise defaults are used.
+
+    Returns the new nodegroup_id (> 0) if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        PasswordAuth(),
+        NodeGroup.fields['name'],
+        NodeGroup.fields['description']
+        ]
+
+    returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
+
+    def call(self, auth, name, description):
+       # Create node group
+        nodegroup = NodeGroup(self.api, {'name': name, 'description': description})
+        nodegroup.sync()
+
+        return nodegroup['nodegroup_id']
diff --git a/PLC/Methods/AddNodeNetwork.py b/PLC/Methods/AddNodeNetwork.py
new file mode 100644 (file)
index 0000000..693e5dd
--- /dev/null
@@ -0,0 +1,67 @@
+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.Auth import PasswordAuth
+
+class AddNodeNetwork(Method):
+    """
+    Adds a new network for a node. Any values specified in
+    optional_vals 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 optional_vals. If type is dhcp, these parameters,
+    even if specified, are ignored.
+
+    PIs and techs may only add networks to their own nodes. ins may
+    add networks to any node.
+
+    Returns the new nodenetwork_id (> 0) if successful, faults otherwise.
+    """
+
+    roles = ['admin', 'pi', 'tech']
+
+    can_update = lambda (field, value): field in \
+                 ['ip', 'mac', 'gateway', 'network', 'broadcast', 'netmask',
+                  'dns1', 'dns2', 'hostname', 'bwlimit', 'is_primary']
+    update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
+
+    accepts = [
+        PasswordAuth(),
+        Node.fields['node_id'],
+        NodeNetwork.fields['method'],
+        NodeNetwork.fields['type'],
+        update_fields
+        ]
+
+    returns = Parameter(int, 'New nodenetwork_id (> 0) if successful')
+
+    def call(self, auth, node_id, method, type, optional_vals = {}):
+        if filter(lambda field: field not in self.update_fields, optional_vals):
+            raise PLCInvalidArgument, "Invalid fields specified"
+
+        # Check if node exists
+        nodes = Nodes(self.api, [node_id]).values()
+        if not nodes:
+            raise PLCInvalidArgument, "No such node"
+       node = nodes[0]
+
+        # Authenticated function
+        assert self.caller is not None
+
+        # If we are not an admin, make sure that the caller is a
+        # member of the site where the node exists.
+        if 'admin' not in self.caller['roles']:
+            if node['site_id'] not in self.caller['site_ids']:
+                raise PLCPermissionDenied, "Not allowed to add node network for specified node"
+
+        # Add node network
+       nodenetwork = NodeNetwork(self.api, optional_vals)
+        nodenetwork['node_id'] = node_id
+       nodenetwork['method'] = method
+        nodenetwork['type'] = type
+        nodenetwork.sync()
+
+        return nodenetwork['nodenetwork_id']