Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
02d113be
Commit
02d113be
authored
1 year ago
by
JORGE SASIAIN
Browse files
Options
Downloads
Patches
Plain Diff
NAT-152: support allocate host by specific ip address in a specific service container
parent
d0387488
No related branches found
No related tags found
1 merge request
!9
Ipam service
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/services/_ipam.py
+16
-7
16 additions, 7 deletions
gso/services/_ipam.py
gso/services/ipam.py
+11
-0
11 additions, 0 deletions
gso/services/ipam.py
with
27 additions
and
7 deletions
gso/services/_ipam.py
+
16
−
7
View file @
02d113be
...
...
@@ -290,13 +290,14 @@ def _allocate_host(hostname=None, addr=None, network=None) -> Union[V4HostAddres
else
:
return
V6HostAddress
(
v6
=
addr
)
def
allocate_service_host
(
hostname
=
None
,
service_type
=
None
,
service_networks
:
ServiceNetworks
=
None
)
->
HostAddresses
:
def
allocate_service_host
(
hostname
=
None
,
service_type
=
None
,
service_networks
:
ServiceNetworks
=
None
,
host_addresses
:
HostAddresses
=
None
)
->
HostAddresses
:
"""
Allocate host with both IPv4 and IPv6 address (and respective DNS records).
The domain name is also taken from the service type and appended to specified hostname.
If service_networks is provided, that one is used.
If service_networks is not provided, the first network with available space for this service type is used.
Note that if WFO will always specify the network after creating it, this mode won
'
t be needed.
If service_networks is not provided, and host_addresses is provided, those specific addresses are used.
If neither is not provided, the first network with available space for this service type is used.
Note that if WFO will always specify the network/addresses after creating it, this mode won
'
t be needed.
"""
oss
=
settings
.
load_oss_params
()
assert
oss
.
IPAM
...
...
@@ -308,7 +309,7 @@ def allocate_service_host(hostname=None, service_type=None, service_networks: Se
domain_name
=
getattr
(
ipam_params
,
service_type
).
domain_name
# IPv4
if
not
service_networks
:
if
not
service_networks
and
not
host_addresses
:
ipv4_networks_info
=
_find_networks
(
network_container
=
str
(
ipv4_container
),
ip_version
=
4
)
assert
len
(
ipv4_networks_info
)
>=
1
,
"
No IPv4 network exists in the container for this service type.
"
first_nonfull_ipv4_network
=
None
...
...
@@ -323,13 +324,17 @@ def allocate_service_host(hostname=None, service_type=None, service_networks: Se
first_nonfull_ipv4_network
=
str
(
allocate_service_ipv4_network
(
service_type
=
service_type
).
v4
)
assert
first_nonfull_ipv4_network
,
"
No available IPv4 addresses for this service type.
"
v4_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
network
=
first_nonfull_ipv4_network
)
els
e
:
el
if
service_network
s
:
network
=
service_networks
.
v4
assert
network
.
subnet_of
(
ipv4_container
)
v4_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
network
=
str
(
network
))
elif
host_addresses
:
addr
=
host_addresses
.
v4
assert
addr
in
ipv4_container
v4_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
addr
=
str
(
addr
))
# IPv6
if
not
service_networks
:
if
not
service_networks
and
not
host_addresses
:
# ipv6 does not support capacity fetching (not even the GUI displays it).
# Maybe it's assumed that there is always available space?
ipv6_networks_info
=
_find_networks
(
network_container
=
str
(
ipv6_container
),
ip_version
=
6
)
...
...
@@ -337,10 +342,14 @@ def allocate_service_host(hostname=None, service_type=None, service_networks: Se
assert
'
network
'
in
ipv6_networks_info
[
0
]
# TODO: if "no available IP" error, create a new network?
v6_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
network
=
ipv6_networks_info
[
0
][
'
network
'
])
els
e
:
el
if
service_network
s
:
network
=
service_networks
.
v6
assert
network
.
subnet_of
(
ipv6_container
)
v6_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
network
=
str
(
network
))
elif
host_addresses
:
addr
=
host_addresses
.
v6
assert
addr
in
ipv6_container
v6_host
=
_allocate_host
(
hostname
=
hostname
+
domain_name
,
addr
=
str
(
addr
))
return
HostAddresses
(
v4
=
v4_host
.
v4
,
v6
=
v6_host
.
v6
)
...
...
This diff is collapsed.
Click to expand it.
gso/services/ipam.py
+
11
−
0
View file @
02d113be
...
...
@@ -44,12 +44,23 @@ def new_service_host(hostname, service_type, service_networks: ServiceNetworks)
if
__name__
==
'
__main__
'
:
# sample call flow to allocate two loopback interfaces and a trunk service
# new_service_host can be called passing networks or addresses
# - the first time is called by passing a specific ipv4/ipv6 address pair
# - the rest are called by passing the ipv4/ipv6 network pair
hostname_A
=
'
newhost1
'
hostname_B
=
'
newhost2
'
# h1 loopback
lo1_service_networks
=
new_service_networks
(
'
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
,
v6
=
lo1_v6_host_address
)
new_service_host
(
hostname_A
,
'
LO
'
,
lo1_service_networks
)
# h2 loopback
lo2_service_networks
=
new_service_networks
(
'
LO
'
)
new_service_host
(
hostname_B
,
'
LO
'
,
lo2_service_networks
)
# h1-h2 trunk
trunk12_service_networks
=
new_service_networks
(
'
TRUNK
'
)
new_service_host
(
hostname_A
,
'
TRUNK
'
,
trunk12_service_networks
)
new_service_host
(
hostname_B
,
'
TRUNK
'
,
trunk12_service_networks
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment