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

Update IPAM README.md

parent ea0a9a97
Branches
Tags
2 merge requests!27Merge develop into NAT-185,!15Nat 185
## IPAM ## IPAM
### Example configuration ### Example configuration
The following kind of configuration file needs to be exported in the variable OSS_PARAMS_FILENAME: The following kind of configuration file needs to be exported in the variable `OSS_PARAMS_FILENAME`.
``` ```
"LO": { "LO": {
"V4": {"containers": [], "networks": ["10.255.255.32/32", "10.255.255.0/28", "10.255.255.16/28"], "mask": 0}, "V4": {"containers": [], "networks": ["10.255.255.32/32", "10.255.255.0/28", "10.255.255.16/28"], "mask": 0},
"V6": {"containers": [], "networks": ["dead:beef::/80", "dead:beef:0:1::/80"], "mask": 0}, "V6": {"containers": [], "networks": ["dead:beef::/80", "dead:beef:0:1::/80"], "mask": 0},
"domain_name": ".gso" "domain_name": ".gso"
}, },
"TRUNK": { "TRUNK": {
"V4": {"containers": ["10.255.255.0/24", "10.255.254.0/24"], "networks": [], "mask": 31}, "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}, "V6": {"containers": ["dead:beef::/64", "dead:beee::/64"], "networks": [], "mask": 126},
"domain_name": ".gso" "domain_name": ".gso"
}, },
``` ```
Either a non-empty list of `networks` or a non-empty list of `containers` is required in the params file per service type. Having both is redundant, but in that case containers take precedence. The `mask` parameter is irrelevant if the service type uses networks instead of containers. Either a non-empty list of `networks` or a non-empty list of `containers` is required in the params file per service type. Having both is redundant, but in that case containers take precedence. The `mask` parameter is irrelevant if the service type uses networks instead of containers.
### Host/network allocation ### Host/network allocation
Hosts can be allocated through `ipam.new_service_host()` resulting in a host record (IPv4, IPv6, A, AAAA) and zero or more cname records. This function can be called by passing domain name, hostname, and service type (mandatory). Optinally, you can pass either ipv4/ipv6 addresses, ipv4/ipv6 networks, or nothing. Passing nothing is considered default. In that case: Hosts can be allocated through `ipam.new_service_host()` resulting in a host record (IPv4, IPv6, A, AAAA) and zero or more cname records. This function can be called by passing domain name, hostname, and service type (mandatory). Optinally, you can pass either ipv4/ipv6 addresses, ipv4/ipv6 networks, or nothing. Passing nothing is considered default. In that case:
- If the service type has any container specified in the params file, networks have to be allocated before allocating hosts (through `ipam.new_service_networks()`). The mask parameter is used to create the new networks. Containers are filled up in the order that they appear in the params file. - If the service type has any container specified in the params file, networks have to be allocated before allocating hosts (through `ipam.new_service_networks()`). The mask parameter is used to create the new networks. Containers are filled up in the order that they appear in the params file.
- If the service type has any network specified in the params file, those networks are used directly to allocate hosts. Networks are filled up in the order that they appear in the params file. - If the service type has any network specified in the params file, those networks are used directly to allocate hosts. Networks are filled up in the order that they appear in the params file.
If you pass addresses or networks, the module will always attempt to use those, but will fail if they don't match the configuration in the params file for the service type (i.e. if you request an address or network that places outside of the configured containers/networks). If you pass addresses or networks, the module will always attempt to use those, but will fail if they don't match the configuration in the params file for the service type (i.e. if you request an address or network that places outside of the configured containers/networks).
Networks and hosts can be allocated with extensible attributes. Networks can be created with a comment. CNAME records can be optionally created. Networks and hosts can be allocated with extensible attributes. Networks can be created with a comment. CNAME records can be optionally created.
### Host/network deletion ### Host/network deletion
The code checks that the resource you are trying to delete is allocated (in terms of IP address space) to the service as per `containers` or `networks` in the service's configuration. If not, you are not allowed to delete it. The code checks that the resource you are trying to delete is allocated (in terms of IP address space) to the service as per `containers` or `networks` in the service's configuration. If not, you are not allowed to delete it.
No host or cname records are deleted via the `delete_service_host()` function until all passed arguments match the hostname, IP, and CNAME data of the host. If anything doesn't match, no record is deleted. No host or cname records are deleted via the `delete_service_host()` function until all passed arguments match the hostname, IP, and CNAME data of the host. If anything doesn't match, no record is deleted.
### Usage examples ### Usage examples
#### Host/network allocation #### Host/network allocation
The following is a sample call flow to allocate two loopback interfaces and a trunk service. new_service_host() can be called passing networks, addresses, or nothing. The following is a sample call flow to allocate two loopback interfaces and a trunk service. It assumes the _Example configuration_ from the above section is used, where TRUNK has configured containers, and LO has configured networks.
- Host hA for service TRUNK uses a specific ipv4/ipv6 address pair.
- Host hB for service TRUNK uses the ipv4/ipv6 network pair. In this example:
- Service LO uses nothing. - Host hA for service LO uses specific ipv4/ipv6 address pair.
- Host hB for service LO uses nothing (just the service type).
``` - Host hA for service TRUNK uses a specific ipv4/ipv6 address pair.
hostname_A = 'hA' - Host hB for service TRUNK uses the ipv4/ipv6 network pair.
hostname_B = 'hB'
Because TRUNK has configured containers rather than networks, `new_service_networks()` must be called first to create a network for the hA-hB TRUNK. This is not needed for LO, which automatically uses the first configured network with available space to allocate new hosts.
# hA LO (loopback)
loA_v4_host_address = ipaddress.ip_address('10.255.255.0') ```
loA_v6_host_address = ipaddress.ip_address('dead:beef::0') hostname_A = 'hA'
loA_host_addresses = HostAddresses(v4=loA_v4_host_address, hostname_B = 'hB'
v6=loA_v6_host_address)
new_service_host(hostname=hostname_A+"_LO", # hA LO (loopback)
host_addresses=loA_host_addresses, loA_v4_host_address = ipaddress.ip_address('10.255.255.0')
cname_aliases=["alias1.hA", "alias2.hA"], loA_v6_host_address = ipaddress.ip_address('dead:beef::0')
service_type='LO') loA_host_addresses = HostAddresses(v4=loA_v4_host_address,
v6=loA_v6_host_address)
# hB LO (loopback) new_service_host(hostname=hostname_A+"_LO",
new_service_host(hostname=hostname_B+"_LO", host_addresses=loA_host_addresses,
cname_aliases=["alias1.hB"], cname_aliases=["alias1.hA", "alias2.hA"],
service_type='LO') service_type='LO')
# hA-hB TRUNK # hB LO (loopback)
trunkAB_network_extattrs = { new_service_host(hostname=hostname_B+"_LO",
"vrf_name": {"value": "dummy_vrf"}, cname_aliases=["alias1.hB"],
} service_type='LO')
trunkAB_host_extattrs = {
"Site": {"value": "dummy_site"}, # hA-hB TRUNK
} trunkAB_network_extattrs = {
trunkAB_service_networks = new_service_networks( "vrf_name": {"value": "dummy_vrf"},
service_type='TRUNK', }
extattrs=trunkAB_network_extattrs, trunkAB_host_extattrs = {
comment="Network for hA-hB TRUNK" "Site": {"value": "dummy_site"},
) }
trunkAB_service_networks = new_service_networks(
trunkAB_v4_host_address = trunkAB_service_networks.v4.network_address service_type='TRUNK',
trunkAB_v6_host_address = trunkAB_service_networks.v6.network_address extattrs=trunkAB_network_extattrs,
trunkAB_host_addresses = HostAddresses(v4=trunkAB_v4_host_address, comment="Network for hA-hB TRUNK"
v6=trunkAB_v6_host_address) )
new_service_host(hostname=hostname_A+"_TRUNK", trunkAB_v4_host_address = trunkAB_service_networks.v4.network_address
service_type='TRUNK', trunkAB_v6_host_address = trunkAB_service_networks.v6.network_address
host_addresses=trunkAB_host_addresses, trunkAB_host_addresses = HostAddresses(v4=trunkAB_v4_host_address,
extattrs=trunkAB_host_extattrs) v6=trunkAB_v6_host_address)
new_service_host(hostname=hostname_B+"_TRUNK", new_service_host(hostname=hostname_A+"_TRUNK",
service_type='TRUNK', service_type='TRUNK',
service_networks=trunkAB_service_networks, host_addresses=trunkAB_host_addresses,
extattrs=trunkAB_host_extattrs) extattrs=trunkAB_host_extattrs)
```
new_service_host(hostname=hostname_B+"_TRUNK",
#### Host/network deletion service_type='TRUNK',
``` service_networks=trunkAB_service_networks,
# Delete network extattrs=trunkAB_host_extattrs)
service_network = ipam.delete_service_network( ```
network=ipaddress.ip_network('10.255.255.0/26'), service_type='LO'
) #### Host/network deletion
```
# Delete host # Delete network
input_host_addresses = ipam.HostAddresses( service_network = ipam.delete_service_network(
v4=ipaddress.ip_address('10.255.255.1'), network=ipaddress.ip_network('10.255.255.0/26'), service_type='LO'
v6=ipaddress.ip_address('dead:beef::1') )
)
host_addresses = ipam.delete_service_host( # Delete host
hostname='ha_lo', input_host_addresses = ipam.HostAddresses(
host_addresses=input_host_addresses, v4=ipaddress.ip_address('10.255.255.1'),
cname_aliases=['alias1.ha', 'alias2.ha'], v6=ipaddress.ip_address('dead:beef::1')
service_type='LO' )
) host_addresses = ipam.delete_service_host(
``` hostname='ha_lo',
host_addresses=input_host_addresses,
cname_aliases=['alias1.ha', 'alias2.ha'],
service_type='LO'
)
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment