Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lustmolch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
stustanet
lustmolch
Commits
cab227b4
Commit
cab227b4
authored
5 years ago
by
Michael Loipführer
Browse files
Options
Downloads
Patches
Plain Diff
remove not working iptable stuff, add working iptable stuff
parent
72389013
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lustmolch.py
+12
-9
12 additions, 9 deletions
lustmolch.py
with
12 additions
and
9 deletions
lustmolch.py
+
12
−
9
View file @
cab227b4
...
...
@@ -13,9 +13,7 @@ cfg_template = namedtuple('cfg_template', ['source', 'path', 'filename'])
template_files_host
=
[
cfg_template
(
'
nginx
'
,
Path
(
'
/etc/nginx/sites-available
'
),
'
{name}
'
),
cfg_template
(
'
nspawn
'
,
Path
(
'
/etc/systemd/nspawn
'
),
'
{name}.nspawn
'
),
cfg_template
(
'
iptables.v4
'
,
Path
(
'
/etc/iptables
'
),
'
{50-container-{name}.v4
'
),
cfg_template
(
'
iptables.v6
'
,
Path
(
'
/etc/iptables
'
),
'
{50-container-{name}.v6
'
)
cfg_template
(
'
nspawn
'
,
Path
(
'
/etc/systemd/nspawn
'
),
'
{name}.nspawn
'
)
]
template_files_container
=
[
cfg_template
(
'
sshd_config
'
,
Path
(
'
/etc/ssh
'
),
'
sshd_config
'
)
...
...
@@ -106,11 +104,11 @@ def create_container(dry_run, config_file, name):
# create machine
machine_path
=
Path
(
'
/var/lib/machines
'
,
name
)
click
.
echo
(
f
'
Running debootstrap
'
)
click
.
echo
(
'
Running debootstrap
'
)
if
not
dry_run
:
run
([
'
debootstrap
'
,
FLAVOUR
,
machine_path
,
DEBIAN_MIRROR
],
capture_output
=
True
,
check
=
True
)
click
.
echo
(
f
'
Bootstrapping container
'
)
click
.
echo
(
'
Bootstrapping container
'
)
if
not
dry_run
:
# copy and run bootstrap shell script
script_location
=
'
/opt/bootstrap.sh
'
...
...
@@ -120,7 +118,7 @@ def create_container(dry_run, config_file, name):
Path
(
script_location_host
).
chmod
(
0o755
)
run
([
'
systemd-nspawn
'
,
'
-D
'
,
str
(
machine_path
),
script_location
],
check
=
True
)
click
.
echo
(
f
'
Copying config files into container
'
)
click
.
echo
(
'
Copying config files into container
'
)
if
not
dry_run
:
for
cfg
in
template_files_container
:
template
=
env
.
get_template
(
cfg
.
source
)
...
...
@@ -130,15 +128,20 @@ def create_container(dry_run, config_file, name):
with
open
(
Path
(
f
'
{
machine_path
}{
cfg
.
path
}
/
{
file_name
}
'
),
'
w+
'
)
as
f
:
f
.
write
(
template
.
render
(
context
))
click
.
echo
(
f
'
Starting container
'
)
click
.
echo
(
f
'
Updating Iptable rules for port
{
context
[
"
ssh_port
"
]
}
'
)
ip_ranges
=
[
'
10.150.0.0/17
'
,
'
141.84.69.0/24
'
]
for
ip_range
in
ip_ranges
:
run
([
'
iptables
'
,
'
-A
'
,
'
INPUT
'
,
'
-p
'
,
'
tcp
'
,
'
-m
'
,
'
tcp
'
,
'
--dport
'
,
context
[
'
ssh_port
'
],
'
-s
'
,
ip_range
,
'
-j
'
,
'
ACCEPT
'
])
click
.
echo
(
'
Starting container
'
)
if
not
dry_run
:
run
([
'
machinectl
'
,
'
start
'
,
name
],
capture_output
=
True
,
check
=
True
)
click
.
echo
(
f
'
Updating container configuration file
'
)
click
.
echo
(
'
Updating container configuration file
'
)
if
not
dry_run
:
update_config
(
config_file
,
name
,
container
=
context
)
click
.
echo
(
f
'
All done, ssh server running on port
{
context
[
"
ssh_port
"
]
}
'
)
click
.
echo
(
f
'
All done, ssh server running on port
{
context
[
"
ssh_port
"
]
}
\n
To finish please run
"
iptables-save
"
.
'
)
@cli.command
()
...
...
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