# Path: netjsonconfig/backends/openwrt/schema.py



from ipaddress import ip_interface
from ..schema import schema
from .base import OpenWrtConverter
        result.setdefault('network', [])
        result['network'].append(route)
        return result

    def __intermediate_route(self, route, index):
        network = ip_interface(route.pop('destination'))
        target = network.ip if network.version == 4 else network.network
        route.update(
            {
                '.type': 'route{0}'.format('6' if network.version == 6 else ''),
                '.name': route.pop('name', None) or self.__get_auto_name(index),
                'interface': route.pop('device'),
                'target': str(target),
                'gateway': route.pop('next'),
                'metric': route.pop('cost'),
            }
        )
        if network.version == 4:
            route['netmask'] = str(network.netmask)
        return self.sorted_dict(route)

    def __get_auto_name(self, i):
        return 'route{0}'.format(i)

    def to_netjson_loop(self, block, result, index):
        rule = self.__netjson_route(block, index)
        result.setdefault('routes', [])
        result['routes'].append(rule)
        return result


# Path: netjsonconfig/backends/openwrt/schema.py



# Path: netjsonconfig/backends/openwrt/converters/routes.py
from ipaddress import ip_interface
from ..schema import schema
from .base import OpenWrtConverter

        result.setdefault('network', [])
        result['network'].append(route)
        return result

    def __intermediate_route(self, route, index):
        network = ip_interface(route.pop('destination'))
        target = network.ip if network.version == 4 else network.network
        route.update(
            {
                '.type': 'route{0}'.format('6' if network.version == 6 else ''),
                '.name': route.pop('name', None) or self.__get_auto_name(index),
                'interface': route.pop('device'),
                'target': str(target),
                'gateway': route.pop('next'),
                'metric': route.pop('cost'),
            }
        )
        if network.version == 4:
            route['netmask'] = str(network.netmask)
        return self.sorted_dict(route)

    def __get_auto_name(self, i):
        return 'route{0}'.format(i)

    def to_netjson_loop(self, block, result, index):
        rule = self.__netjson_route(block, index)
        result.setdefault('routes', [])
        result['routes'].append(rule)
        return result


    _schema = schema['properties']['routes']['items']