'Create subnets and saves subnet id in data'

def _create_subnets(self, engine, data):

    networks = db_utils.get_table(engine, 'networks')
    subnets = db_utils.get_table(engine, 'subnets')
    pools = db_utils.get_table(engine, 'ipallocationpools')
    allocations = db_utils.get_table(engine, 'ipallocations')
    for cidr in data:
        ip_version = (6 if (':' in cidr) else 4)
        network_id = uuidutils.generate_uuid()
        network_dict = dict(id=network_id, standard_attr_id=self._gen_attr_id(engine, 'networks'))
        engine.execute(networks.insert().values(network_dict))
        data[cidr]['id'] = uuidutils.generate_uuid()
        subnet_dict = dict(id=data[cidr]['id'], cidr=cidr, ip_version=ip_version, standard_attr_id=self._gen_attr_id(engine, 'subnets'))
        engine.execute(subnets.insert().values(subnet_dict))
        if data[cidr].get('pools'):
            for pool in data[cidr]['pools']:
                pool_dict = dict(id=uuidutils.generate_uuid(), first_ip=pool['first_ip'], last_ip=pool['last_ip'], subnet_id=data[cidr]['id'])
                engine.execute(pools.insert().values(pool_dict))
        if data[cidr].get('allocations'):
            for ip in data[cidr]['allocations']:
                ip_dict = dict(ip_address=ip, subnet_id=data[cidr]['id'], network_id=network_id)
                engine.execute(allocations.insert().values(ip_dict))
