from bundlewrap.metadata import atomic

defaults = {
    'apt': {
        'packages': {
            'nfs-kernel-server': {}
        },
    },
}


@metadata_reactor.provides(
    'firewall/port_rules',
)
def firewall(metadata):
    ips = set()

    for share_items in metadata.get('nfs-server/shares', {}).values():
        for share_target in share_items:
            ips.add(share_target)

    return {
        'firewall': {
            'port_rules': {
                '111': atomic(ips),
                '111/udp': atomic(ips),
                '2049': atomic(ips),
                '35295': atomic(ips),
            },
        },
    }
