1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Nodes import Node, Nodes
5 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
6 from PLC.Auth import Auth
8 can_update = lambda (field, value): field not in \
9 ['nodenetwork_id','node_id']
11 class UpdateNodeNetwork(Method):
13 Updates an existing node network. Any values specified in
14 nodenetwork_fields are used, otherwise defaults are
15 used. Acceptable values for method are dhcp and static. If type is
16 static, then ip, gateway, network, broadcast, netmask, and dns1
17 must all be specified in nodenetwork_fields. If type is dhcp,
18 these parameters, even if specified, are ignored.
20 PIs and techs may only update networks associated with their own
21 nodes. Admins may update any node network.
23 Returns 1 if successful, faults otherwise.
26 roles = ['admin', 'pi', 'tech']
28 nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items()))
32 NodeNetwork.fields['nodenetwork_id'],
36 returns = Parameter(int, '1 if successful')
38 def call(self, auth, nodenetwork_id, nodenetwork_fields):
39 nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
41 # Get node network information
42 nodenetworks = NodeNetworks(self.api, [nodenetwork_id])
44 raise PLCInvalidArgument, "No such node network"
46 nodenetwork = nodenetworks[0]
48 # Authenticated function
49 assert self.caller is not None
51 # If we are not an admin, make sure that the caller is a
52 # member of the site where the node exists.
53 if 'admin' not in self.caller['roles']:
54 nodes = Nodes(self.api, [nodenetwork['node_id']])
56 raise PLCPermissionDenied, "Node network is not associated with a node"
58 if node['site_id'] not in self.caller['site_ids']:
59 raise PLCPermissionDenied, "Not allowed to update node network"
62 nodenetwork.update(nodenetwork_fields)
65 self.event_objects = {'NodeNetwork': [nodenetwork['nodenetwork_id']]}
66 self.message = "Node network %d updated: %s " % \
67 (nodenetwork['nodenetwork_id'], ", ".join(nodenetwork_fields.keys()))