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



from ipaddress import ip_interface
from ..schema import schema
from .base import OpenWrtConverter
        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']

    def __netjson_route(self, route, i):
        _name = route.pop('.name')
        if _name != self.__get_auto_name(i):
            route['name'] = _name
        network = route.pop('target')
        if 'netmask' in route:
            network = '{0}/{1}'.format(network, route.pop('netmask'))
        route.update(
            {
                "device": route.pop('interface'),
                "destination": str(ip_interface(network)),
                "next": route.pop('gateway'),
                "cost": route.pop(
                    'metric', self._schema['properties']['cost']['default']
                ),
            }
        )

# 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

        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']

    def __netjson_route(self, route, i):
        _name = route.pop('.name')
        if _name != self.__get_auto_name(i):
            route['name'] = _name
        network = route.pop('target')
        if 'netmask' in route:
            network = '{0}/{1}'.format(network, route.pop('netmask'))
        route.update(
            {
                "device": route.pop('interface'),
                "destination": str(ip_interface(network)),
                "next": route.pop('gateway'),
                "cost": route.pop(
                    'metric', self._schema['properties']['cost']['default']
                ),
            }
        )

        del route['.type']