dhcp.py
changeset 4 8b633782f02d
parent 1 2223ade4f259
equal deleted inserted replaced
3:ff98fa9b84ce 4:8b633782f02d
     8     """
     8     """
     9         A full configuration file
     9         A full configuration file
    10     """
    10     """
    11 
    11 
    12     def __init__ (self, name=dhcpc.ConfFile.DEFAULT_NAME, path=dhcpc.ConfFile.DEFAULT_PATH, 
    12     def __init__ (self, name=dhcpc.ConfFile.DEFAULT_NAME, path=dhcpc.ConfFile.DEFAULT_PATH, 
    13             settings=None, options=None, shared_network=False, subnets=None, hosts=None
    13             settings=None, options=None, shared_network=False, subnets=None, hosts=None, comment=None
    14     ) :
    14     ) :
    15         """
    15         """
    16             Create a full configuration file for the given settings:
    16             Create a full configuration file for the given settings:
    17             
    17             
    18             settings:       a { name: value } mappping of general settings to set
    18             settings:       a { name: value } mappping of general settings to set
    21             subnets:        an iterable of Subnet's to define
    21             subnets:        an iterable of Subnet's to define
    22             hosts:          an iterable of Host's to define
    22             hosts:          an iterable of Host's to define
    23 
    23 
    24         """
    24         """
    25 
    25 
    26         dhcpc.ConfFile.__init__(self, name, path)
    26         dhcpc.ConfFile.__init__(self, name, path, comment=comment)
    27 
    27 
    28         # define global settings
    28         # define global settings
    29         if settings :
    29         if settings :
    30             self.add_params(dhcpc.Parameter(setting, value) for setting, value in settings.iteritems())
    30             self.add_params(dhcpc.Parameter(setting, value) for setting, value in settings.iteritems())
    31         
    31         
    47 class Subnet (dhcpc.Subnet) :
    47 class Subnet (dhcpc.Subnet) :
    48     """
    48     """
    49         A subnet declaration with a router, and optionally a dynamic address pool, and allow/deny unknown clients
    49         A subnet declaration with a router, and optionally a dynamic address pool, and allow/deny unknown clients
    50     """
    50     """
    51 
    51 
    52     def __init__ (self, subnet, router_idx=1, range=None, unknown_clients=None) :
    52     def __init__ (self, subnet, router_idx=1, range=None, unknown_clients=None, comment=None) :
    53         """
    53         """
    54             @param subnet the addr.IP representing the subnet
    54             @param subnet the addr.IP representing the subnet
    55             @param router_idx the subnet[index] of the default gateway
    55             @param router_idx the subnet[index] of the default gateway
    56             @param range optional (from_idx, to_idx) to define a dhcp pool
    56             @param range optional (from_idx, to_idx) to define a dhcp pool
    57             @param unknown_clients optional 'allow'/'deny' to set a policy for unknown clients
    57             @param unknown_clients optional 'allow'/'deny' to set a policy for unknown clients
    63 
    63 
    64         super(Subnet, self).__init__(subnet, params=[
    64         super(Subnet, self).__init__(subnet, params=[
    65             dhcpc.Option("routers", subnet[router_idx]),
    65             dhcpc.Option("routers", subnet[router_idx]),
    66             dhcpc.Parameter("range", subnet[range[0]], subnet[range[1]]) if range else None,
    66             dhcpc.Parameter("range", subnet[range[0]], subnet[range[1]]) if range else None,
    67             dhcpc.Parameter(unknown_clients, "unknown-clients") if unknown_clients else None,
    67             dhcpc.Parameter(unknown_clients, "unknown-clients") if unknown_clients else None,
    68         ])
    68         ], comment=comment)
    69 
    69 
    70 
    70 
    71 class Host (dhcpc.Host) :
    71 class Host (dhcpc.Host) :
    72     """
    72     """
    73         A host declaration with a hardware address and a IP address
    73         A host declaration with a hardware address and a IP address
    74     """
    74     """
    75 
    75 
    76     def __init__ (self, hostname, mac_addr, ip_addr) :
    76     def __init__ (self, hostname, mac_addr, ip_addr, comment=None) :
    77         super(Host, self).__init__(hostname, params=[
    77         super(Host, self).__init__(hostname, params=[
    78             dhcpc.Parameter("hardware ethernet", mac_addr),
    78             dhcpc.Parameter("hardware ethernet", mac_addr),
    79             dhcpc.Parameter("fixed-address", ip_addr)
    79             dhcpc.Parameter("fixed-address", ip_addr)
    80         ])
    80         ], comment=comment)
    81 
    81