from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
+from PLC.Interfaces import Interface, Interfaces
from PLC.Auth import Auth
can_update = lambda (field, value): field not in \
- ['nodenetwork_id','node_id']
+ ['interface_id','node_id']
-class UpdateNodeNetwork(Method):
+class UpdateInterface(Method):
"""
Updates an existing node network. Any values specified in
- nodenetwork_fields are used, otherwise defaults are
+ interface_fields are used, otherwise defaults are
used. Acceptable values for method are dhcp and static. If type is
static, then ip, gateway, network, broadcast, netmask, and dns1
- must all be specified in nodenetwork_fields. If type is dhcp,
+ must all be specified in interface_fields. If type is dhcp,
these parameters, even if specified, are ignored.
PIs and techs may only update networks associated with their own
roles = ['admin', 'pi', 'tech']
- nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items()))
+ interface_fields = dict(filter(can_update, Interface.fields.items()))
accepts = [
Auth(),
- NodeNetwork.fields['nodenetwork_id'],
- nodenetwork_fields
+ Interface.fields['interface_id'],
+ interface_fields
]
returns = Parameter(int, '1 if successful')
- def call(self, auth, nodenetwork_id, nodenetwork_fields):
- nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
+ def call(self, auth, interface_id, interface_fields):
+ interface_fields = dict(filter(can_update, interface_fields.items()))
# Get node network information
- nodenetworks = NodeNetworks(self.api, [nodenetwork_id])
- if not nodenetworks:
+ interfaces = Interfaces(self.api, [interface_id])
+ if not interfaces:
raise PLCInvalidArgument, "No such node network"
- nodenetwork = nodenetworks[0]
+ interface = interfaces[0]
# Authenticated function
assert self.caller is not None
# If we are not an admin, make sure that the caller is a
# member of the site where the node exists.
if 'admin' not in self.caller['roles']:
- nodes = Nodes(self.api, [nodenetwork['node_id']])
+ nodes = Nodes(self.api, [interface['node_id']])
if not nodes:
raise PLCPermissionDenied, "Node network is not associated with a node"
node = nodes[0]
raise PLCPermissionDenied, "Not allowed to update node network"
# Update node network
- nodenetwork.update(nodenetwork_fields)
- nodenetwork.sync()
+ interface.update(interface_fields)
+ interface.sync()
- self.event_objects = {'NodeNetwork': [nodenetwork['nodenetwork_id']]}
+ self.event_objects = {'Interface': [interface['interface_id']]}
self.message = "Node network %d updated: %s " % \
- (nodenetwork['nodenetwork_id'], ", ".join(nodenetwork_fields.keys()))
+ (interface['interface_id'], ", ".join(interface_fields.keys()))
return 1