1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import Auth
5 from PLC.Nodes import Node, Nodes
6 from PLC.Interfaces import Interface, Interfaces
7 from PLC.IpAddresses import IpAddress, IpAddresses
9 class DeleteIpAddress(Method):
11 Deletes an existing ip address.
13 Admins may delete any ip address. PIs and techs may only delete
14 ip addresses associated with interfaces on nodes at their sites.
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi', 'tech']
23 IpAddress.fields['ip_address_id']
26 returns = Parameter(int, '1 if successful')
29 def call(self, auth, ip_address_id):
31 # Get interface information
32 ip_addresses = IpAddresses(self.api, [ip_address_id])
34 raise PLCInvalidArgument, "No such ip_address %r"%ip_address_id
35 ip_address = ip_addresses[0]
37 # Authenticated functino
38 assert self.caller is not None
40 # If we are not an admin, make sure that the caller is a
41 # member of the site at which the node is located.
42 if 'admin' not in self.caller['roles']:
43 # Get interface information
44 interfaces = Interfaces(self.api, [ip_address['interface_id']])
46 raise PLCInvalidArgument, "No such interface %r"%ip_address['interface_id']
47 interface = interfaces[0]
49 # Get node information
50 nodes = Nodes(self.api, [interface['node_id']])
52 raise PLCInvalidArgument, "No such node %r"%node_id
55 if node['site_id'] not in self.caller['site_ids']:
56 raise PLCPermissionDenied, "Not allowed to delete this ip address"
61 self.event_objects = {'IpAddress': [ip_address['ip_address_id']]}
62 self.message = "IpAddress %d deleted" % ip_address['ip_address_id']