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
9c11adc3
Commit
9c11adc3
authored
5 years ago
by
Attila Farkas
Browse files
Options
Downloads
Patches
Plain Diff
move argument parsing to separate module
parent
ff9407c1
No related branches found
No related tags found
1 merge request
!7
Resolve Refactoring
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
create.py
+29
-20
29 additions, 20 deletions
create.py
modules/input_argument_parser.py
+31
-0
31 additions, 0 deletions
modules/input_argument_parser.py
with
60 additions
and
20 deletions
create.py
+
29
−
20
View file @
9c11adc3
#!/usr/bin/python3
"""
A script that generates a Vagrantfile from yaml.
"""
"""
This script generates a Vagrantfile and ansible files from a YAML definition
of virtual machines and network topology. See the documentation for details.
"""
import
sys
import
jinja2
from
modules.file_generator
import
generate_vagrantfile
,
generate_ansible_files
from
modules.device_creator
import
open_file
from
modules.routing
import
create_border_router
from
modules.input_argument_parser
import
parse_input_args
if
len
(
sys
.
argv
)
==
3
:
if
str
(
sys
.
argv
[
1
])
==
"
-l
"
:
ansible_local
=
True
input_file_name
=
str
(
sys
.
argv
[
2
])
elif
str
(
sys
.
argv
[
2
])
==
"
-l
"
:
ansible_local
=
True
input_file_name
=
str
(
sys
.
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
sys
.
exit
()
elif
len
(
sys
.
argv
)
==
2
:
ansible_local
=
False
input_file_name
=
str
(
sys
.
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
sys
.
exit
()
device_definitions
=
open_file
(
input_file_name
)
"""
Parsing the input arguments.
"""
flags
=
dict
()
try
:
input_file_name
=
parse_input_args
(
sys
.
argv
,
flags
)
except
Exception
:
print
(
"
Input arguments could not be parsed.
"
)
raise
"""
Parsing the definitions file.
"""
try
:
device_definitions
=
open_file
(
input_file_name
)
except
Exception
:
print
(
"
Definitions file could not be parsed.
"
)
raise
# TODO
create_border_router
(
device_definitions
)
if
"
ansible_local
"
in
flags
and
flags
[
"
ansible_local
"
]:
generate_vagrantfile
(
device_definitions
,
True
)
else
:
generate_vagrantfile
(
device_definitions
,
False
)
generate_vagrantfile
(
device_definitions
,
ansible_local
)
generate_ansible_files
(
device_definitions
)
This diff is collapsed.
Click to expand it.
modules/input_argument_parser.py
0 → 100644
+
31
−
0
View file @
9c11adc3
"""
This module contains functions to parse input arguments.
"""
def
parse_input_args
(
argv
,
flags
):
"""
Parses the given input arguments for input file name and flags.
:param argv: input arguments (list of strings)
:param flags: dictionary to write the parsed flags
:returns: name of the input file
:raise AttributeError: invalid number of args or unknown flag
"""
input_file_name
=
None
if
len
(
argv
)
==
3
:
if
str
(
argv
[
1
])
==
"
-l
"
:
flags
[
"
ansible_local
"
]
=
True
input_file_name
=
str
(
argv
[
2
])
elif
str
(
argv
[
2
])
==
"
-l
"
:
flags
[
"
ansible_local
"
]
=
True
input_file_name
=
str
(
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
raise
AttributeError
elif
len
(
argv
)
==
2
:
input_file_name
=
str
(
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
raise
AttributeError
return
input_file_name
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