mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
26 lines
465 B
Python
26 lines
465 B
Python
#
|
|
#
|
|
#
|
|
|
|
import ipaddress
|
|
|
|
|
|
class Subnets(object):
|
|
@classmethod
|
|
def validate(cls, subnet, prefix):
|
|
'''
|
|
Validates an octoDNS subnet making sure that it is valid
|
|
'''
|
|
reasons = []
|
|
|
|
try:
|
|
cls.parse(subnet)
|
|
except ValueError:
|
|
reasons.append(f'{prefix}invalid subnet "{subnet}"')
|
|
|
|
return reasons
|
|
|
|
@classmethod
|
|
def parse(cls, subnet):
|
|
return ipaddress.ip_network(subnet)
|