X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FLegacy%2FDeleteInterface.py;fp=PLC%2FMethods%2FLegacy%2FDeleteInterface.py;h=82d0f7ebf505dbf8692272b54b1e4b9fbc30fa94;hb=f1b4415be5ba4be9941d25b531c46696b377fa3a;hp=0000000000000000000000000000000000000000;hpb=cb77137d884be296fe1e0b15eabe69d18ba443ae;p=plcapi.git diff --git a/PLC/Methods/Legacy/DeleteInterface.py b/PLC/Methods/Legacy/DeleteInterface.py new file mode 100644 index 0000000..82d0f7e --- /dev/null +++ b/PLC/Methods/Legacy/DeleteInterface.py @@ -0,0 +1,63 @@ +from PLC.Faults import * +from PLC.Auth import Auth +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Table import Row + +from PLC.Nodes import Node, Nodes +from PLC.Interfaces import Interface, Interfaces +from PLC.Methods.DeleteIpAddress import DeleteIpAddress + +class DeleteInterface(Method): + """ + Deletes an existing interface. + + Admins may delete any interface. PIs and techs may only delete + interface interfaces associated with nodes at their sites. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin', 'pi', 'tech'] + + accepts = [ + Auth(), + Interface.fields['interface_id'] + ] + + returns = Parameter(int, '1 if successful') + + + def call(self, auth, interface_id): + + # Get interface information + interfaces = Interfaces(self.api, [interface_id]) + if not interfaces: + raise PLCInvalidArgument, "No such interface %r"%interface_id + interface = interfaces[0] + + # Get node information + nodes = Nodes(self.api, [interface['node_id']]) + if not nodes: + raise PLCInvalidArgument, "No such node %r"%node_id + node = nodes[0] + + # Authenticated functino + assert self.caller is not None + + # If we are not an admin, make sure that the caller is a + # member of the site at which the node is located. + if 'admin' not in self.caller['roles']: + if node['site_id'] not in self.caller['site_ids']: + raise PLCPermissionDenied, "Not allowed to delete this interface" + + for ip_address_id in interface['ip_address_ids']: + DeleteIpAddress(self.api).__call__(auth, ip_address_id) + + interface.delete() + + # Logging variables + self.event_objects = {'Interface': [interface['interface_id']]} + self.message = "Interface %d deleted" % interface['interface_id'] + + return 1