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.Interfaces import Interface, Interfaces
7 from PLC.Auth import Auth
9 can_update = lambda (field, value): field not in \
10 ['interface_id','node_id']
12 class UpdateInterface(Method):
14 Updates an existing node network. Any values specified in
15 interface_fields are used, otherwise defaults are
16 used. Acceptable values for method are dhcp and static. If type is
17 static, then ip, gateway, network, broadcast, netmask, and dns1
18 must all be specified in interface_fields. If type is dhcp,
19 these parameters, even if specified, are ignored.
21 PIs and techs may only update networks associated with their own
22 nodes. Admins may update any node network.
24 Returns 1 if successful, faults otherwise.
27 roles = ['admin', 'pi', 'tech']
29 interface_fields = dict(filter(can_update, Interface.fields.items()))
33 Interface.fields['interface_id'],
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, interface_id, interface_fields):
40 interface_fields = dict(filter(can_update, interface_fields.items()))
42 # Get node network information
43 interfaces = Interfaces(self.api, [interface_id])
45 raise PLCInvalidArgument, "No such node network"
47 interface = interfaces[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, [interface['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 interface.update(interface_fields)
66 self.event_objects = {'Interface': [interface['interface_id']]}
67 self.message = "Node network %d updated: %s " % \
68 (interface['interface_id'], ", ".join(interface_fields.keys()))