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 AdmUpdateNodeNetwork(Method):
11 Updates an existing node network. Any values specified in optional_vals
12 are used, otherwise defaults are used. Acceptable values for method are
13 dhcp and static. If type is static, the parameter optional_vals 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 add networks to their own nodes. Admins may
19 add networks to any node.
21 Returns 1 if successful, faults otherwise.
24 roles = ['admin', 'pi', 'tech']
26 cant_update = lambda (field, value): field not in \
28 update_fields = dict(filter(cant_update, NodeNetwork.all_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, optional_vals=None):
40 if filter(lambda field: field not in self.update_fields, optional_vals):
41 raise PLCInvalidArgument, "Invalid fields specified"
43 # Authenticated function
44 assert self.caller is not None
46 # Get nodenetwork information
47 nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
49 raise PLCInvalidArgument, "No such node network"
50 nodenetwork = nodenetworks[0]
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']]).values()
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(optional_vals)