2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Nodes import Node, Nodes
6 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
7 from PLC.Auth import PasswordAuth
9 class UpdateNodeNetwork(Method):
11 Updates an existing node network. Any values specified in update_fields
12 are used, otherwise defaults are used. Acceptable values for method are
13 dhcp and static. If type is static, the parameter update_fields must
14 be present and ip, gateway, network, broadcast, netmask, and dns1 must
15 all be specified. If type is dhcp, these parameters, even if
16 specified, are ignored.
18 PIs and techs may only update networks associated with their own
19 nodes. ins may update any node network.
21 Returns 1 if successful, faults otherwise.
24 roles = ['admin', 'pi', 'tech']
26 can_update = lambda (field, value): field not in \
28 update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
32 Mixed(NodeNetwork.fields['nodenetwork_id'],
33 NodeNetwork.fields['hostname']),
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, nodenetwork_id_or_hostname, update_fields):
40 # Check for invalid fields
41 if filter(lambda field: field not in self.update_fields, update_fields):
42 raise PLCInvalidArgument, "Invalid fields specified"
44 # Get node network information
45 nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
47 raise PLCInvalidArgument, "No such node network"
49 nodenetwork = nodenetworks[0]
51 # Authenticated function
52 assert self.caller is not None
54 # If we are not an admin, make sure that the caller is a
55 # member of the site where the node exists.
56 if 'admin' not in self.caller['roles']:
57 nodes = Nodes(self.api, [nodenetwork['node_id']]).values()
59 raise PLCPermissionDenied, "Node network is not associated with a node"
61 if node['site_id'] not in self.caller['site_ids']:
62 raise PLCPermissionDenied, "Not allowed to update node network"
65 nodenetwork.update(update_fields)