Skip to content
Snippets Groups Projects
Commit c6b5ba88 authored by JORGE SASIAIN's avatar JORGE SASIAIN
Browse files

NAT-152: update oss params and fix tests

parent 9a0d795d
No related branches found
No related tags found
2 merge requests!27Merge develop into NAT-185,!15Nat 185
......@@ -12,18 +12,18 @@
"password": "robot-user-password"
},
"LO": {
"V4": {"containers": ["1.1.0.0/24"], "mask": 32},
"V6": {"containers": ["dead:beef::/64"], "mask": 128},
"V4": {"containers": [], "networks": ["1.1.0.0/28"], "mask": 0},
"V6": {"containers": [], "networks": ["dead:beef::/80"], "mask": 0},
"domain_name": ".lo"
},
"TRUNK": {
"V4": {"containers": ["1.1.1.0/24"], "mask": 31},
"V6": {"containers": ["dead:beef::/64"], "mask": 126},
"V4": {"containers": ["1.1.1.0/24"], "networks": [], "mask": 31},
"V6": {"containers": ["dead:beef::/64"], "networks": [], "mask": 126},
"domain_name": ".trunk"
},
"GEANT_IP": {
"V4": {"containers": ["1.1.2.0/24"], "mask": 31},
"V6": {"containers": ["dead:beef::/64"], "mask": 126},
"V4": {"containers": ["1.1.2.0/24"], "networks": [], "mask": 31},
"V6": {"containers": ["dead:beef::/64"], "networks": [], "mask": 126},
"domain_name": ".geantip"
}
},
......
......@@ -391,8 +391,8 @@ def allocate_service_host(hostname=None,
if not service_networks and not host_addresses:
if oss_ipv4_containers and oss_ipv6_containers:
# This service has configured containers.
# Use them to allocate new networks that can allocate the hosts.
# This service has configured containers.
# Use them to allocate new networks that can allocate the hosts.
# IPv4
ipv4_network = str(allocate_service_ipv4_network(
......@@ -407,8 +407,8 @@ def allocate_service_host(hostname=None,
"No available space for IPv6 networks for this service type."
elif oss_ipv4_networks and oss_ipv6_networks:
# This service has configured networks.
# Allocate a host inside an ipv4 and ipv6 network from among them.
# This service has configured networks.
# Allocate a host inside an ipv4 and ipv6 network from among them.
ipv4_network = str(oss_ipv4_networks[0])
ipv6_network = str(oss_ipv6_networks[0])
......@@ -428,7 +428,7 @@ def allocate_service_host(hostname=None,
assert ipv4_network_index < len(oss_ipv4_networks), \
"No available space in any IPv4 network for this service."
ipv4_network = str(oss_ipv4_networks[ipv4_network_index])
else: # IPV6 in host
else: # IPV6 in host
ipv6_network_index += 1
assert ipv6_network_index < len(oss_ipv6_networks), \
"No available space in any IPv6 network for this service."
......@@ -676,101 +676,3 @@ def _get_network_usage_status(network):
f"HTTP error {r.status_code}: {r.reason}\n\n{r.text}"
return r.json()
'''
'''
if __name__ == '__main__':
while True:
print("1. Find all containers")
print("2. Find all networks")
print("3. Get network capacity")
print("4. Create new network")
print("5. Delete network")
print("6. Allocate host by IP")
print("7. Allocate host by network CIDR")
print("8. Allocate host by service type")
print("9. Delete host by IP")
print("10. Get network usage status")
print("11. Exit")
choice = input("Enter your choice: ")
if choice == '1':
ip_version = int(input("Enter IP version (4 or 6): "))
containers = _find_containers(ip_version=ip_version)
print(json.dumps(containers, indent=2))
elif choice == '2':
ip_version = int(input("Enter IP version (4 or 6): "))
networks = _find_networks(ip_version=ip_version)
print(json.dumps(networks, indent=2))
elif choice == '3':
network = input("Enter network (in CIDR notation): ")
network_capacity = _get_network_capacity(network=network)
print(json.dumps(network_capacity, indent=2))
elif choice == '4':
service_type = input("Enter service type: ")
comment = input("Enter a comment for the network: ")
ip_version = int(input("Enter IP version (4 or 6): "))
if ip_version == 4:
new_network = allocate_service_ipv4_network(
comment=comment, service_type=service_type)
elif ip_version == 6:
new_network = allocate_service_ipv6_network(
comment=comment, service_type=service_type)
else:
print("Invalid IP version. Please enter either 4 or 6.")
continue
print(json.dumps(str(new_network), indent=2))
elif choice == '5':
network = input("Enter network to delete (in CIDR notation): ")
deleted_network = _delete_network(network=network)
print(json.dumps(str(deleted_network), indent=2))
elif choice == '6':
hostname = input("Enter host name (full name w/ domain name): ")
addrv4 = input("Enter IPv4 address to allocate: ")
addrv6 = input("Enter IPv6 address to allocate: ")
alloc_ip = _allocate_host(hostname=hostname,
addrs=(addrv4,addrv6))
print(json.dumps(str(alloc_ip), indent=2))
elif choice == '7':
hostname = input("Enter host name (full name w/ domain name): ")
networkv4 = input(
"Enter existing ipv4 network to use (CIDR notation): ")
networkv6 = input(
"Enter existing ipv6 network to use (CIDR notation): ")
alloc_ip = _allocate_host(
hostname=hostname,
networks=(networkv4, networkv6)
)
print(json.dumps(str(alloc_ip), indent=2))
elif choice == '8':
hostname = input("Enter host name (w/o domain name): ")
service_type = input("Enter service type: ")
alloc_ip = allocate_service_host(
hostname=hostname,
service_type=service_type)
print(json.dumps(str(alloc_ip), indent=2))
elif choice == '9':
addr = input("Enter IP address of host to delete: ")
deleted_host = _delete_host_by_ip(addr=addr)
print(json.dumps(str(deleted_host), indent=2))
elif choice == '10':
network = input(
"Enter network to get host usage status (CIDR notation): ")
usage_status_info = _get_network_usage_status(network=network)
print(json.dumps(usage_status_info, indent=2))
elif choice == '11':
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
'''
......@@ -57,7 +57,6 @@ def new_service_host(hostname,
extattrs=extattrs)
if __name__ == '__main__':
# sample call flow to allocate two loopback interfaces and a trunk service
# new_service_host can be called passing networks, addresses, or nothing.
......@@ -68,17 +67,19 @@ if __name__ == '__main__':
# networks can be created with a comment
# CNAME records can be optionally created
hostname_A = 'h9'
hostname_B = 'h10'
'''
hostname_A = 'hA'
hostname_B = 'hB'
# h1 LO (loopback)
new_service_host(hostname=hostname_A+"_LO",
cname_aliases=["alias1.hA", "alias2.hA"],
service_type='LO')
# h2 LO (loopback)
new_service_host(hostname=hostname_B+"_LO",
cname_aliases=["alias1.hB"],
service_type='LO')
'''
# h1-h2 TRUNK
trunk12_network_extattrs = {
"vrf_name": {"value": "dummy_vrf"},
......@@ -100,11 +101,9 @@ if __name__ == '__main__':
new_service_host(hostname=hostname_A+"_TRUNK",
service_type='TRUNK',
host_addresses=trunk12_host_addresses,
cname_aliases=["alias1.h1", "alias2.h1"],
extattrs=trunk12_host_extattrs)
new_service_host(hostname=hostname_B+"_TRUNK",
service_type='TRUNK',
service_networks=trunk12_service_networks,
cname_aliases=["alias1.h2"],
extattrs=trunk12_host_extattrs)
......@@ -26,17 +26,27 @@ def configuration_data():
"password": "robot-user-password"
},
"LO": {
"V4": {"containers": ["10.255.255.0/24"], "mask": 32},
"V6": {"containers": ["dead:beef::/64"], "mask": 128},
"V4": {
"containers": [],
"networks": ["10.255.255.0/26"],
"mask": 32
},
"V6": {
"containers": [],
"networks": ["dead:beef::/80"],
"mask": 128
},
"domain_name": ".lo"
},
"TRUNK": {
"V4": {
"containers": ["10.255.255.0/24", "10.255.254.0/24"],
"networks": [],
"mask": 31
},
"V6": {
"containers": ["dead:beef::/64", "dead:beee::/64"],
"networks": [],
"mask": 126
},
"domain_name": ".trunk"
......@@ -44,10 +54,12 @@ def configuration_data():
"GEANT_IP": {
"V4": {
"containers": ["10.255.255.0/24", "10.255.254.0/24"],
"networks": [],
"mask": 31
},
"V6": {
"containers": ["dead:beef::/64", "dead:beee::/64"],
"networks": [],
"mask": 126
},
"domain_name": ".geantip"
......
......@@ -26,7 +26,7 @@ def test_new_service_networks(data_config_filename):
}
)
service_networks = ipam.new_service_networks(service_type='LO')
service_networks = ipam.new_service_networks(service_type='TRUNK')
assert service_networks == ipam.ServiceNetworks(
v4=ipaddress.ip_network('10.255.255.20/32'),
v6=ipaddress.ip_network('dead:beef::18/128')
......@@ -111,7 +111,7 @@ def test_new_service_host(data_config_filename):
service_hosts = ipam.new_service_host(
hostname='test',
service_type='LO',
service_type='TRUNK',
host_addresses=ipam.HostAddresses(
v4=ipaddress.ip_address('10.255.255.20'),
v6=ipaddress.ip_address('dead:beef::18')
......@@ -124,7 +124,7 @@ def test_new_service_host(data_config_filename):
service_hosts = ipam.new_service_host(
hostname='test',
service_type='LO',
service_type='TRUNK',
service_networks=ipam.ServiceNetworks(
v4=ipaddress.ip_network('10.255.255.20/32'),
v6=ipaddress.ip_network('dead:beef::18/128')
......@@ -143,3 +143,12 @@ def test_new_service_host(data_config_filename):
v4=ipaddress.ip_address('10.255.255.20'),
v6=ipaddress.ip_address('dead:beef::18')
)
service_hosts = ipam.new_service_host(
hostname='test',
service_type='TRUNK'
)
assert service_hosts == ipam.HostAddresses(
v4=ipaddress.ip_address('10.255.255.20'),
v6=ipaddress.ip_address('dead:beef::18')
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment