Exemplo n.º 1
0
    def create(self, subnet, mask, start_ip=None, stop_ip=None):
        """Create a DHCP subnet; return DHCP subnet objects."""
        subnet = common.validate_ip_address(subnet)
        filter = 'cn=%s' % subnet
        if not common.is_number(mask):
            msg = 'Subnet mask must be an integer, dotted decimal (or any other\
 notation) is not allowed'

            self.log.error(msg)
            raise error.InputError(msg)
        mask = str(mask)
        if start_ip and not stop_ip:
            msg = 'A range must include a start and stop IP address'
            self.log.error(msg)
            raise error.InputError(msg)
        if start_ip is not None:
            start_ip = common.validate_ip_address(start_ip)
            stop_ip = common.validate_ip_address(stop_ip)
            start_ip, stop_ip = self._is_greater_ip_than(start_ip, stop_ip)

        dn = 'cn=%s,%s' % (subnet, self.dhcp_service_dn)
        dn_attr = {
            'objectClass': ['top', self.dhcp_subnet_class],
            'cn': [subnet],
            'dhcpNetMask': [mask]
        }
        if start_ip is not None:
            dn_attr['dhcpRange'] = start_ip + ' ' + stop_ip
        dn_info = [(k, v) for (k, v) in dn_attr.items()]
        result = self._create_object(dn, dn_info)
        self.log.debug('Result: %s' % result)
        return result
Exemplo n.º 2
0
Arquivo: dhcp.py Projeto: mattmb/spoke
    def create(self, subnet, mask, start_ip=None, stop_ip=None):
        """Create a DHCP subnet; return DHCP subnet objects."""
        subnet = common.validate_ip_address(subnet)
        filter = 'cn=%s' % subnet
        if not common.is_number(mask):
            msg = 'Subnet mask must be an integer, dotted decimal (or any other\
 notation) is not allowed'
            self.log.error(msg)
            raise error.InputError(msg)
        mask = str(mask)
        if start_ip and not stop_ip:
            msg = 'A range must include a start and stop IP address'
            self.log.error(msg)
            raise error.InputError(msg)
        if start_ip is not None:
            start_ip = common.validate_ip_address(start_ip)
            stop_ip = common.validate_ip_address(stop_ip)
            start_ip, stop_ip = self._is_greater_ip_than(start_ip, stop_ip)
            
        dn = 'cn=%s,%s' % (subnet, self.dhcp_service_dn)
        dn_attr = {'objectClass': ['top', self.dhcp_subnet_class],
                   'cn': [subnet],
                   'dhcpNetMask': [mask]}
        if start_ip is not None:
            dn_attr['dhcpRange'] = start_ip + ' ' + stop_ip
        dn_info = [(k, v) for (k, v) in dn_attr.items()]
        result = self._create_object(dn, dn_info)
        self.log.debug('Result: %s' % result)
        return result
Exemplo n.º 3
0
 def get(self, subnet):
     """Search for a DHCP subnet; return a results list."""
     subnet = common.validate_ip_address(subnet)
     filter = 'cn=%s' % subnet
     dn = 'cn=%s,%s' % (subnet, self.dhcp_service_dn)
     result = self._get_object(dn, self.search_scope, filter)
     self.log.debug('Result: %s' % result)
     return result
Exemplo n.º 4
0
Arquivo: dhcp.py Projeto: mattmb/spoke
 def get(self, subnet):
     """Search for a DHCP subnet; return a results list."""
     subnet = common.validate_ip_address(subnet)
     filter = 'cn=%s' % subnet
     dn = 'cn=%s,%s' % (subnet, self.dhcp_service_dn)
     result = self._get_object(dn, self.search_scope, filter)
     self.log.debug('Result: %s' % result)
     return result
Exemplo n.º 5
0
Arquivo: ip.py Projeto: mattmb/spoke
    def __init__(self, ip=None, mask=None, dc=None):
        """Get config, setup logging and Redis connection."""
        SpokeKV.__init__(self)
        self.config = config.setup()
        self.log = logger.setup(__name__)
        self.max_mask = 16  # This is the largest network we can work with
        # Check our subnet is well formatted in dotted decimal
        if ip and mask:
            common.validate_ip_address(ip)
            # Check our netmask is well formatted and NOT in dotted decimal
            try:
                common.validate_ip_address(mask)
            except:
                pass  # It's not a dotted decimal format subnet, good
            else:
                # It validated as a dotted decimal, but we need an integer
                msg = 'IPv4 subnet mask must be between %s and 32' % self.max_mask
                raise error.InputError(msg)

            self.subnet = ip_helper.Network(ip, int(mask))
            self.network = self.subnet.network()
            self.mask = self.subnet.mask

            if dc is not None:
                self.kv_name = dc + str(self.network)
                self.kv_free = '%s:%s:%s:free' % (dc, self.network, self.mask)
                self.kv_aloc = '%s:%s:%s:aloc' % (dc, self.network, self.mask)
            else:
                self.kv_name = str(self.network)
                self.kv_free = '%s:%s:free' % (self.network, self.mask)
                self.kv_aloc = '%s:%s:aloc' % (self.network, self.mask)
            self.ip_ldap_enabled = self.config.get('IP', 'ip_ldap_enabled',
                                                   False)
            self.ip_ldap_attr = self.config.get('IP', 'ip_ldap_attr',
                                                'dhcpStatements')
            self.ip_ldap_key = self.config.get('IP', 'ip_ldap_key',
                                               'fixed-address')
            self.ip_ldap_search_base = self.config.get('IP',
                                                       'ip_ldap_search_base',
                                                       False)
        else:
            (self.network, self.mask) = (None, None)
Exemplo n.º 6
0
Arquivo: ip.py Projeto: mattmb/spoke
 def __init__(self, ip=None, mask=None, dc=None):   
     """Get config, setup logging and Redis connection."""
     SpokeKV.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.max_mask = 16 # This is the largest network we can work with
     # Check our subnet is well formatted in dotted decimal
     if ip and mask:
         common.validate_ip_address(ip)
         # Check our netmask is well formatted and NOT in dotted decimal
         try:
             common.validate_ip_address(mask)
         except:
             pass # It's not a dotted decimal format subnet, good
         else:
             # It validated as a dotted decimal, but we need an integer
             msg = 'IPv4 subnet mask must be between %s and 32' % self.max_mask
             raise error.InputError(msg)
         
         self.subnet = ip_helper.Network(ip, int(mask))
         self.network = self.subnet.network()
         self.mask = self.subnet.mask
     
         if dc is not None:
             self.kv_name = dc + str(self.network)
             self.kv_free = '%s:%s:%s:free' % (dc, self.network, self.mask)
             self.kv_aloc = '%s:%s:%s:aloc' % (dc, self.network, self.mask)
         else:
             self.kv_name = str(self.network)
             self.kv_free = '%s:%s:free' % (self.network, self.mask)
             self.kv_aloc = '%s:%s:aloc' % (self.network, self.mask)
         self.ip_ldap_enabled = self.config.get('IP', 'ip_ldap_enabled', False)
         self.ip_ldap_attr = self.config.get('IP', 'ip_ldap_attr', 'dhcpStatements')
         self.ip_ldap_key = self.config.get('IP', 'ip_ldap_key', 'fixed-address')
         self.ip_ldap_search_base = self.config.get('IP', 'ip_ldap_search_base', False)
     else:
         (self.network, self.mask) = (None, None)
Exemplo n.º 7
0
Arquivo: ip.py Projeto: mattmb/spoke
 def _release_ip(self, ip):
     """Release an IP from the pool of allocated IPs"""
     ip = common.validate_ip_address(ip)
     self.KV.srem(self.kv_aloc, ip)
     self.KV.sadd(self.kv_free, ip)
     return True
Exemplo n.º 8
0
Arquivo: ip.py Projeto: mattmb/spoke
 def _release_ip(self, ip):
     """Release an IP from the pool of allocated IPs"""
     ip = common.validate_ip_address(ip)
     self.KV.srem(self.kv_aloc, ip)
     self.KV.sadd(self.kv_free, ip)
     return True