def cni_ipam(host_cidrv4: str, host_gateway: str):
"""
With the class variables provide a way to generate a static host-local ipam
:param host_cidrv4:
:param host_gateway:
:return: dict
"""
host = ipaddr.IPNetwork(host_cidrv4)
subnet = host
ip_cut = int(host.ip.__str__().split(".")[-1])
if ConfigSyncSchedules.sub_ips:
sub = ipaddr.IPNetwork(host.network).ip + (ip_cut * ConfigSyncSchedules.sub_ips)
host = ipaddr.IPNetwork(sub)
range_start = host.ip + ConfigSyncSchedules.skip_ips
range_end = range_start + ConfigSyncSchedules.range_nb_ips
ipam = {
"type": "host-local",
"subnet": "%s/%s" % (subnet.network.__str__(), subnet.prefixlen),
"rangeStart": range_start.__str__(),
"rangeEnd": range_end.__str__(),
"gateway": host_gateway,
"routes": [
{"dst": "%s/32" % EC.perennial_local_host_ip, "gw": ipaddr.IPNetwork(host_cidrv4).ip.__str__()},
{"dst": "0.0.0.0/0"},
],
"dataDir": "/var/lib/cni/networks"
}
return ipam
评论列表
文章目录