Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cyber-sandbox-creator
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
MUNI-KYPO-CSC
cyber-sandbox-creator
Commits
7985696f
Commit
7985696f
authored
4 years ago
by
Attila Farkas
Browse files
Options
Downloads
Patches
Plain Diff
Find available ip for the controller
parent
80e9baba
No related branches found
No related tags found
1 merge request
!22
Resolve "Support Windows boxes"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/controller.py
+27
-0
27 additions, 0 deletions
modules/controller.py
with
27 additions
and
0 deletions
modules/controller.py
+
27
−
0
View file @
7985696f
"""
Contains functions for controller creation.
"""
from
netaddr
import
*
from
itertools
import
chain
CONTROLLER_NAME
=
"
controller
"
...
...
@@ -14,6 +17,28 @@ def _are_controller_parameters_free(definitions):
return
True
def
_is_ip_available
(
ip
,
definitions
):
"""
Check if the given ip is used somewhere
"""
for
mapping
in
chain
(
definitions
[
"
router_mappings
"
],
definitions
[
"
net_mappings
"
]):
if
mapping
[
"
ip
"
]
==
ip
:
return
False
return
True
def
_find_available_ip
(
definitions
):
"""
Return an available ip for the controller
"""
network
=
IPNetwork
(
definitions
[
"
networks
"
][
0
][
"
cidr
"
])
for
ip
in
network
:
if
_is_ip_available
(
ip
,
definitions
):
return
str
(
ip
)
def
_add_controller
(
definitions
):
"""
Add controller to definitions
"""
ip
=
_find_available_ip
(
definitions
)
def
create_controller
(
definitions
):
"""
Add the definition of controller to definitions.
...
...
@@ -25,4 +50,6 @@ def create_controller(definitions):
raise
ValueError
(
"
A device with the same name as border router
"
"
already exists.
"
)
_add_controller
(
definitions
)
return
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