2
# network.py - lookup functions for network names and addresses
4
# Copyright (C) 2011 Arthur de Jong
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Lesser General Public
8
# License as published by the Free Software Foundation; either
9
# version 2.1 of the License, or (at your option) any later version.
11
# This library is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public
17
# License along with this library; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27
attmap = common.Attributes(cn='cn',
28
ipNetworkNumber='ipNetworkNumber')
29
filter = '(objectClass=ipNetwork)'
32
class NetworkRequest(common.Request):
34
def write(self, dn, attributes, parameters):
35
networkname = common.get_rdn_value(dn, attmap['cn'])
36
networknames = attributes['cn']
38
print 'Error: entry %s does not contain %s value' % (dn, attmap['cn'])
40
networkname = networknames.pop(0)
41
elif networkname in networknames:
42
networknames.remove(networkname)
43
addresses = attributes['ipNetworkNumber']
45
print 'Error: entry %s does not contain %s value' % (dn, attmap['ipNetworkNumber'])
47
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
48
self.fp.write_string(networkname)
49
self.fp.write_stringlist(networknames)
50
self.fp.write_int32(len(addresses))
51
for address in addresses:
52
self.fp.write_address(address)
55
class NetworkByNameRequest(NetworkRequest):
57
action = constants.NSLCD_ACTION_NETWORK_BYNAME
59
def read_parameters(self, fp):
60
return dict(cn=fp.read_string())
63
class NetworkByAddressRequest(NetworkRequest):
65
action = constants.NSLCD_ACTION_NETWORK_BYADDR
67
def read_parameters(self, fp):
68
return dict(ipNetworkNumber=fp.read_address())
71
class NetworkAllRequest(NetworkRequest):
73
action = constants.NSLCD_ACTION_NETWORK_ALL