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 \
11 class UpdateNodeNetwork(Method):
13 Updates an existing node network. Any values specified in update_fields
14 are used, otherwise defaults are used. Acceptable values for method are
15 dhcp and static. If type is static, the parameter update_fields must
16 be present and ip, gateway, network, broadcast, netmask, and dns1 must
17 all be specified. If type is dhcp, these parameters, even if
18 specified, are ignored.
20 PIs and techs may only update networks associated with their own
21 nodes. ins 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 Mixed(NodeNetwork.fields['nodenetwork_id'],
33 NodeNetwork.fields['ip']),
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, nodenetwork_id_or_ip, nodenetwork_fields):
40 nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
42 # Get node network information
43 nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_ip])
45 raise PLCInvalidArgument, "No such node network"
47 nodenetwork = nodenetworks[0]
49 # Authenticated function
50 assert self.caller is not None
52 # If we are not an admin, make sure that the caller is a
53 # member of the site where the node exists.
54 if 'admin' not in self.caller['roles']:
55 nodes = Nodes(self.api, [nodenetwork['node_id']])
57 raise PLCPermissionDenied, "Node network is not associated with a node"
59 if node['site_id'] not in self.caller['site_ids']:
60 raise PLCPermissionDenied, "Not allowed to update node network"
63 nodenetwork.update(nodenetwork_fields)