diff --git a/gso/services/_ipam.py b/gso/services/_ipam.py index 1347b17c09660789ee7a940d04be29196c2845de..01dc0b0957b175ecb9cc1509db241e269c0cfa38 100644 --- a/gso/services/_ipam.py +++ b/gso/services/_ipam.py @@ -147,6 +147,7 @@ def _allocate_network( infoblox_params: settings.InfoBloxParams, network_params: Union[settings.V4NetworkParams, settings.V6NetworkParams], ip_version=4, + comment="", extattrs={} ) -> Union[V4ServiceNetwork, V6ServiceNetwork]: assert ip_version in [4, 6] @@ -168,6 +169,7 @@ def _allocate_network( }, "_result_field": "networks", }, + "comment": comment, "extattrs": extattrs } @@ -203,7 +205,7 @@ def _allocate_network( return V6ServiceNetwork(v6=allocated_network) -def allocate_service_ipv4_network(service_type, extattrs={} +def allocate_service_ipv4_network(service_type, comment="", extattrs={} ) -> V4ServiceNetwork: """ Allocate IPv4 network within the container of the specified service type. @@ -216,10 +218,11 @@ def allocate_service_ipv4_network(service_type, extattrs={} return _allocate_network(ipam_params.INFOBLOX, getattr(ipam_params, service_type).V4, 4, + comment, extattrs) -def allocate_service_ipv6_network(service_type, extattrs={} +def allocate_service_ipv6_network(service_type, comment="", extattrs={} ) -> V6ServiceNetwork: """ Allocate IPv6 network within the container of the specified service type. @@ -232,6 +235,7 @@ def allocate_service_ipv6_network(service_type, extattrs={} return _allocate_network(ipam_params.INFOBLOX, getattr(ipam_params, service_type).V6, 6, + comment, extattrs) @@ -619,13 +623,14 @@ if __name__ == '__main__': 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( - service_type=service_type) + comment=comment, service_type=service_type) elif ip_version == 6: new_network = allocate_service_ipv6_network( - service_type=service_type) + comment=comment, service_type=service_type) else: print("Invalid IP version. Please enter either 4 or 6.") continue diff --git a/gso/services/ipam.py b/gso/services/ipam.py index 1c846be89f60668448b247c34b0e77b7d738a843..44b75bacbe6ff9387f742e9ecbde0e9e5b4a2029 100644 --- a/gso/services/ipam.py +++ b/gso/services/ipam.py @@ -1,7 +1,7 @@ import ipaddress from pydantic import BaseSettings -import _ipam +from gso.services import _ipam class V4ServiceNetwork(BaseSettings): @@ -30,11 +30,13 @@ class HostAddresses(BaseSettings): v6: ipaddress.IPv6Address -def new_service_networks(service_type, extattrs={}) -> ServiceNetworks: +def new_service_networks(service_type, + comment="", + extattrs={}) -> ServiceNetworks: v4_service_network = _ipam.allocate_service_ipv4_network( - service_type=service_type, extattrs=extattrs) + service_type=service_type, comment=comment, extattrs=extattrs) v6_service_network = _ipam.allocate_service_ipv6_network( - service_type=service_type, extattrs=extattrs) + service_type=service_type, comment=comment, extattrs=extattrs) return ServiceNetworks( v4=v4_service_network.v4, v6=v6_service_network.v6) @@ -66,7 +68,10 @@ if __name__ == '__main__': hostname_B = 'h2' # h1 LO (loopback) - lo1_service_networks = new_service_networks(service_type='LO') + lo1_service_networks = new_service_networks( + service_type='LO', + comment="Network for h1 LO" + ) lo1_v4_host_address = lo1_service_networks.v4.network_address lo1_v6_host_address = lo1_service_networks.v6.network_address lo1_host_addresses = HostAddresses(v4=lo1_v4_host_address, @@ -83,14 +88,19 @@ if __name__ == '__main__': "Site": {"value": "dummy_site"}, } lo2_service_networks = \ - new_service_networks(service_type='LO', extattrs=lo2_network_extattrs) + new_service_networks(service_type='LO', + comment="Network for h2 LO", + extattrs=lo2_network_extattrs) new_service_host(hostname=hostname_B, service_type='LO', service_networks=lo2_service_networks, extattrs=lo2_host_extattrs) # h1-h2 TRUNK - trunk12_service_networks = new_service_networks(service_type='TRUNK') + trunk12_service_networks = new_service_networks( + service_type='TRUNK', + comment="Network for h1-h2 TRUNK" + ) new_service_host(hostname=hostname_A, service_type='TRUNK', service_networks=trunk12_service_networks)