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
73570429
Commit
73570429
authored
5 years ago
by
Attila Farkas
Browse files
Options
Downloads
Patches
Plain Diff
first version
parent
25f8b3ac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Devel
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+20
-1
20 additions, 1 deletion
README.md
generate.py
+53
-0
53 additions, 0 deletions
generate.py
name_mapping/vagrant.yml
+73
-0
73 additions, 0 deletions
name_mapping/vagrant.yml
templates/base
+23
-0
23 additions, 0 deletions
templates/base
test.yaml
+43
-0
43 additions, 0 deletions
test.yaml
with
212 additions
and
1 deletion
README.md
+
20
−
1
View file @
73570429
# sandbox-creator
A next generation of https://gitlab.ics.muni.cz/KYPO-content/KYPO-Creator
\ No newline at end of file
A next generation of https://gitlab.ics.muni.cz/KYPO-content/KYPO-Creator
generate.py is a python program that generates a vagrant source file from a definition in yaml.
### Usage:
1.
Clone the project.
2.
Navigate to the project folder.
3.
Type
`$ python generate.py {yaml_file.yaml} >> Vagrantfile`
. There is a test yaml file in the repository called test.yaml.
4.
Run
`$ vagrant up`
### Implemented attribute types:
-
all simple string vagrant attributes
-
a simple network (assigning an ip address to a device)
### Not implemented yet:
-
numeric and other vagrant attributes
-
VirtualBox and OpenStack attributes
-
other network configuration
This diff is collapsed.
Click to expand it.
generate.py
0 → 100644
+
53
−
0
View file @
73570429
#!/usr/bin/python3
import
sys
import
yaml
import
jinja2
if
(
len
(
sys
.
argv
)
!=
2
):
print
(
"
Error: Expecting 1 argument (yml file).
"
)
sys
.
exit
();
try
:
ymlfile
=
open
(
str
(
sys
.
argv
[
1
]))
yml
=
yaml
.
safe_load
(
ymlfile
)
except
IOError
:
print
(
"
Error: file does not exist.
"
)
try
:
v_mappings_file
=
open
(
"
name_mapping/vagrant.yml
"
)
vagrant_mappings
=
yaml
.
safe_load
(
v_mappings_file
)
except
IOError
:
print
(
"
Error: cannot find mappings.
"
)
# Converts yaml attribute names to vagrant attribute names.
def
do_mapping
(
name
):
return
vagrant_mappings
[
name
]
def
find_ip
(
name
):
for
net_mapping
in
yml
[
'
net_mappings
'
]:
if
(
net_mapping
[
'
host
'
]
==
name
):
return
net_mapping
[
'
ip
'
]
devices
=
{}
for
host
in
yml
[
'
hosts
'
]:
devices
[
host
[
'
name
'
]]
=
[]
for
key
,
value
in
host
.
items
():
if
(
key
!=
'
name
'
):
devices
[
host
[
'
name
'
]].
append
(
'
device.
'
+
str
(
do_mapping
(
key
))
+
'
=
\"
'
+
str
(
value
)
+
'
\"
'
)
if
(
yml
[
'
net_mappings
'
]):
devices
[
host
[
'
name
'
]].
append
(
'
device.vm.network :private_network, ip:
\"
'
+
str
(
find_ip
(
host
[
'
name
'
]))
+
'
\"
'
)
templateLoader
=
jinja2
.
FileSystemLoader
(
searchpath
=
"
templates
"
)
templateEnv
=
jinja2
.
Environment
(
loader
=
templateLoader
,
trim_blocks
=
True
)
baseTemplate
=
templateEnv
.
get_template
(
"
base
"
)
output
=
baseTemplate
.
render
(
devices
=
devices
)
print
(
output
)
#vagrantfile = open('Vagrantfile','w')
#vagrantfile.write(output)
This diff is collapsed.
Click to expand it.
name_mapping/vagrant.yml
0 → 100644
+
73
−
0
View file @
73570429
base_mac
:
vm.base_mac
base_address
:
vm.base_address
boot_timeout
:
vm.boot_timeout
base_box
:
vm.box
box_check_update
:
vm.box_check_update
box_download_checksum
:
vm.box_download_checksum
box_download_checksum_type
:
vm.box_download_checksum_type
box_download_client_cert
:
vm.box_download_client_cert
box_download_ca_cert
:
vm.box_download_ca_cert
box_download_ca_path
:
vm.box_download_ca_path
box_download_insecure
:
vm.box_download_insecure
box_download_location_trusted
:
vm.box_download_location_trusted
box_url
:
vm.box_url
box_version
:
vm.box_version
communicator
:
vm.communicator
graceful_halt_timeout
:
vm.graceful_halt_timeout
guest
:
vm.guest
hostname
:
vm.hostname
ignore_box_vagrantfile
:
vm.ignore_box_vagrantfile
network
:
vm.network
post_up_message
:
vm.post_up_message
provider
:
vm.provider
provision
:
vm.provision
synced_folder
:
vm.synced_folder
usable_port_range
:
vm.usable_port_range
ssh_compression
:
ssh.compression
ssh_config
:
ssh.config
ssh_dsa_authentication
:
ssh.dsa_authentication
ssh_export_command_template
:
ssh.export_command_template
ssh_extra_args
:
ssh.extra_args
ssh_forward_agent
:
ssh.forward_agent
ssh_forward_env
:
ssh.forward_env
ssh_forward_x11
:
ssh.forward_x11
ssh_guest_port
:
ssh.guest_port
ssh_host
:
ssh.host
ssh_insert_key
:
ssh.insert_key
ssh_keep_alive
:
ssh.keep_alive
ssh_keys_only
:
ssh.keys_only
ssh_paranoid
:
ssh.paranoid
ssh_password
:
ssh.password
ssh_port
:
ssh.port
ssh_private_key_path
:
ssh.private_key_path
ssh_proxy_command
:
ssh.proxy_command
ssh_pty
:
ssh.pty
ssh_remote_user
:
ssh.remote_user
ssh_shell
:
ssh.shell
ssh_sudo_command
:
ssh.sudo_command
ssh_username
:
ssh.username
ssh_verify_host_key
:
ssh.verify_host_key
winrm_username
:
winrm.username
winrm_password
:
winrm.password
winrm_host
:
winrm.host
winrm_port
:
winrm.port
winrm_guest_port
:
winrm.guest_port
winrm_transport
:
winrm.transport
winrm_basic_auth_only
:
winrm.basic_auth_only
winrm_ssl_peer_verification
:
winrm.ssl_peer_verification
winrm_timeout
:
winrm.timeout
winrm_retry_limit
:
winrm.retry_limit
winrm_retry_delay
:
winrm.retry_delay
winrm_codepage
:
winrm.codepage
winssh_forward_agent
:
winssh.forward_agent
winssh_forward_env
:
winssh.forward_env
winssh_proxy_command
:
winssh.proxy_command
winssh_keep_alive
:
winssh.keep_alive
winssh_shell
:
winssh.shell
winssh_export_command_template
:
winssh.export_command_template
winssh_sudo_command
:
winssh.sudo_command
winssh_upload_directory
:
winssh.upload_directory
vagrant_host
:
vagrant.host
vagrant_plugins
:
vagrant.plugins
vagrant_sensitive
:
vagrant.sensitive
This diff is collapsed.
Click to expand it.
templates/base
0 → 100644
+
23
−
0
View file @
73570429
# Generated vagrant file
#
# -*- mode: ruby -*-
# vi: set ft=ruby :
{
# Macro that prints out attributes of a device #}
{
% macro
printAttributes
(
device_name
)
%
}
{
% for
command
in
devices
[
device_name
]
%
}
{{
command
}}
{
% endfor
%
}
{
% endmacro
%
}
{
# Device definitions #}
Vagrant
.
configure
(
"2"
)
do
|
config
|
{
% for
name
,
attributes
in
devices
.
iteritems
()
%
}
# device: {{ name }}
config
.
vm
.
define
"{{ name }}"
do
|
device
|
{{
printAttributes
(
name
)
}}
end
{
% endfor
%
}
end
This diff is collapsed.
Click to expand it.
test.yaml
0 → 100644
+
43
−
0
View file @
73570429
provisioning
:
Openstack
name
:
small-sandbox
hosts
:
-
name
:
server
base_box
:
ubuntu/bionic64
-
name
:
home
base_box
:
ubuntu/bionic64
routers
:
-
name
:
server-router
cidr
:
100.100.100.0/29
-
name
:
home-router
cidr
:
200.100.100.0/29
networks
:
-
name
:
server-switch
cidr
:
10.10.20.0/24
-
name
:
home-switch
cidr
:
10.10.30.0/24
net_mappings
:
-
host
:
server
network
:
server-switch
ip
:
10.10.20.5
-
host
:
home
network
:
home-switch
ip
:
10.10.30.5
router_mappings
:
-
router
:
server-router
network
:
server-switch
ip
:
10.10.20.1
-
router
:
home-router
network
:
home-switch
ip
:
10.10.30.1
block_internet
:
[]
include_user_access
:
-
server-switch
-
home-switch
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