Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a528b035 authored by Damien Saucez's avatar Damien Saucez
Browse files

get IPs from API

parent 22f60ee8
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,24 @@ import os ...@@ -2,7 +2,24 @@ import os
import yaml import yaml
from jinja2 import Environment, FileSystemLoader, BaseLoader from jinja2 import Environment, FileSystemLoader, BaseLoader
import ipaddr import ipaddr
import requests
def getIP(cluster="central"):
url = f"http://192.0.2.1:8000/ip/{cluster}"
headers = {
'Accept': 'application/json',
'Bearer': os.environ['token']
}
response = requests.request("GET", url, headers=headers, data={})
if response.status_code != requests.codes.OK:
raise Exception(response.json()["detail"])
info = response.json()
return info['ip'], info['prefixlen']
def to_yaml(data): def to_yaml(data):
return yaml.safe_dump(data).strip() return yaml.safe_dump(data).strip()
...@@ -12,46 +29,53 @@ def createFile(content, filename): ...@@ -12,46 +29,53 @@ def createFile(content, filename):
########### ###########
def genIPs(gcn): def genIPs(gcn):
net = ipaddr.IPNetwork(gcn['multus']['network']) # net = ipaddr.IPNetwork(gcn['multus']['network'])
base_ip = net.ip + 2 # base_ip = net.ip + 2
hostInterface = gcn['multus']['hostInterface'] hostInterface = gcn['multus']['hostInterface']
reserved = list()
for i in range(0, 18):
reserved.append(getIP())
prefixlen = reserved[0][1]
ips = { ips = {
"amf": { "amf": {
"n2": {'ip': str(base_ip), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "n2": {'ip': reserved[0][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
# "n2": {'ip': str(base_ip), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}
}, },
"smf": { "smf": {
"n4": {'ip': str(base_ip + 1), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "n4": {'ip': reserved[1][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, },
"upf": { "upf": {
"n3": {'ip': str(base_ip + 2), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n3": {'ip': reserved[2][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n4": {'ip': str(base_ip + 3), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n4": {'ip': reserved[3][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n6": {'ip': str(base_ip + 4), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "n6": {'ip': reserved[4][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, },
"gnb": { "gnb": {
"n2": {'ip': str(base_ip + 5), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n2": {'ip': reserved[5][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n3": {'ip': str(base_ip + 6), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n3": {'ip': reserved[6][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
}, },
"du": { "du": {
"f1": {'ip': str(base_ip + 7), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "f1": {'ip': reserved[7][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, # }, #
"cu": { "cu": {
"f1": {'ip': str(base_ip + 8), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "f1": {'ip': reserved[8][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n2": {'ip': str(base_ip + 9), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n2": {'ip': reserved[9][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n3": {'ip': str(base_ip + 10), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "n3": {'ip': reserved[10][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, },
"cucp": { "cucp": {
"e1": {'ip': str(base_ip + 11), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "e1": {'ip': reserved[11][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n2": {'ip': str(base_ip + 12), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n2": {'ip': reserved[12][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"f1": {'ip': str(base_ip + 8), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "f1": {'ip': reserved[8][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, },
"cuup": { "cuup": {
"e1": {'ip': str(base_ip + 14), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "e1": {'ip': reserved[14][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"n3": {'ip': str(base_ip + 15), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface}, "n3": {'ip': reserved[15][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface},
"f1": {'ip': str(base_ip + 16), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface} "f1": {'ip': reserved[16][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface}
}, },
"trafficserver": { "trafficserver": {
'ip': str(base_ip + 17), 'prefixlen': net.prefixlen, 'hostInterface': hostInterface 'ip': reserved[17][0], 'prefixlen': prefixlen, 'hostInterface': hostInterface
}, },
"nrf": { "nrf": {
"loadBalancerIP": gcn['core']['nrfLoadBalancerIP'] "loadBalancerIP": gcn['core']['nrfLoadBalancerIP']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment