Created
June 4, 2020 19:45
-
-
Save hteibler/8210e61eca256254eb4e403fed174638 to your computer and use it in GitHub Desktop.
get_free_ip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_my_reservations(tid): | |
reservations = j.sal.zosv2.reservation_list(tid=130,next_action="DEPLOY") | |
#do some checks | |
return reservations | |
def get_free_ip(reservations,node,networkname): | |
# find netork reservation | |
# find all IPs | |
ips=[] | |
for reservation in sorted(reservations, key=lambda r: r.id, reverse=True): | |
if reservation.next_action != "DEPLOY": | |
continue | |
rnetworks = reservation.data_reservation.networks | |
for network in rnetworks: | |
if network.name == networkname: | |
for netres in network.network_resources: | |
if netres.node_id == node: | |
iprange = netres.iprange | |
rcontainer = reservation.data_reservation.containers | |
for container in rcontainer: | |
if container.node_id == node: | |
for netcon in container.network_connection: | |
if netcon.network_id == networkname: | |
ips.append(netcon.ipaddress) | |
rkubernetes = reservation.data_reservation.kubernetes | |
for kubernetes in rkubernetes: | |
if kubernetes.node_id == node: | |
ips.append(kubernetes.ipaddress) | |
# asuming /24 | |
nodenet = iprange[0:-4] | |
#search first free IP | |
i=1 | |
while i<254: | |
i+=1 | |
fip = nodenet+str(i) | |
if fip not in ips: | |
break | |
return fip | |
tid = me.id | |
overlay_network_name="Net-17-vie" | |
myres = get_my_reservations(tid) | |
node_id="DAENgzAf2WSQzYtBwDxQ8ZwYdhkzLhekHx5B2PYrMMn9" | |
ip_address = get_free_ip(myres,node_id,overlay_network_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment