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
483239d0
Commit
483239d0
authored
5 years ago
by
Michael Loipführer
Browse files
Options
Downloads
Patches
Plain Diff
fix errors
parent
b0dafd48
No related branches found
No related tags found
No related merge requests found
Pipeline
#344
passed
5 years ago
Stage: build_buster
Stage: upload_to_repo
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lustmolch/cli.py
+7
-14
7 additions, 14 deletions
lustmolch/cli.py
lustmolch/config.py
+6
-3
6 additions, 3 deletions
lustmolch/config.py
lustmolch/lustmolch.py
+12
-8
12 additions, 8 deletions
lustmolch/lustmolch.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
26 additions
and
26 deletions
lustmolch/cli.py
+
7
−
14
View file @
483239d0
import
click
import
click
from
lustmolch.config
import
DEFAULT_CONF_FILE
,
init_config
from
lustmolch.config
import
DEFAULT_CONF_FILE
,
init_config
from
lustmolch.lustmolch
import
(
from
lustmolch
import
lustmolch
list_containers
,
add_user
,
create_container
,
remove_container
,
remove_user
,
update_containers
)
@click.group
()
@click.group
()
...
@@ -22,14 +15,14 @@ def cli(config_file: str):
...
@@ -22,14 +15,14 @@ def cli(config_file: str):
@cli.command
()
@cli.command
()
def
list_containers
():
def
list_containers
():
list_containers
()
lustmolch
.
list_containers
()
@cli.command
()
@cli.command
()
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
@click.argument
(
'
name
'
)
@click.argument
(
'
name
'
)
def
create_container
(
dry_run
:
bool
,
name
:
str
):
def
create_container
(
dry_run
:
bool
,
name
:
str
):
create_container
(
dry_run
,
name
)
lustmolch
.
create_container
(
dry_run
,
name
)
@cli.command
()
@cli.command
()
...
@@ -37,23 +30,23 @@ def create_container(dry_run: bool, name: str):
...
@@ -37,23 +30,23 @@ def create_container(dry_run: bool, name: str):
@click.argument
(
'
name
'
)
@click.argument
(
'
name
'
)
@click.argument
(
'
key
'
)
@click.argument
(
'
key
'
)
def
add_user
(
key_string
:
bool
,
name
:
str
,
key
:
str
)
->
None
:
def
add_user
(
key_string
:
bool
,
name
:
str
,
key
:
str
)
->
None
:
add_user
(
key_string
,
name
,
key
)
lustmolch
.
add_user
(
key_string
,
name
,
key
)
@cli.command
()
@cli.command
()
@click.argument
(
'
name
'
)
@click.argument
(
'
name
'
)
def
remove_user
(
name
:
str
)
->
None
:
def
remove_user
(
name
:
str
)
->
None
:
remove_user
(
name
)
lustmolch
.
remove_user
(
name
)
@cli.command
()
@cli.command
()
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
def
update_containers
(
dry_run
:
bool
)
->
None
:
def
update_containers
(
dry_run
:
bool
)
->
None
:
update_containers
(
dry_run
)
lustmolch
.
update_containers
(
dry_run
)
@cli.command
()
@cli.command
()
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
@click.option
(
'
--dry-run
'
,
is_flag
=
True
,
default
=
False
)
@click.argument
(
'
name
'
)
@click.argument
(
'
name
'
)
def
remove_container
(
dry_run
:
bool
,
name
:
str
)
->
None
:
def
remove_container
(
dry_run
:
bool
,
name
:
str
)
->
None
:
remove_container
(
dry_run
,
name
)
lustmolch
.
remove_container
(
dry_run
,
name
)
This diff is collapsed.
Click to expand it.
lustmolch/config.py
+
6
−
3
View file @
483239d0
...
@@ -14,7 +14,7 @@ DEFAULTS = {
...
@@ -14,7 +14,7 @@ DEFAULTS = {
'
ssh_start_port
'
:
10022
,
'
ssh_start_port
'
:
10022
,
'
ssh_port_increment
'
:
1000
,
'
ssh_port_increment
'
:
1000
,
'
host_ip
'
:
'
141.84.69.235
'
,
'
host_ip
'
:
'
141.84.69.235
'
,
'
ip_start_host
'
:
(
192
,
168
,
0
,
1
)
,
'
ip_start_host
'
:
'
192
.
168
.0.1
'
,
'
ip_subnet_length
'
:
30
,
'
ip_subnet_length
'
:
30
,
'
log_level
'
:
logging
.
INFO
'
log_level
'
:
logging
.
INFO
}
}
...
@@ -35,15 +35,18 @@ class Config:
...
@@ -35,15 +35,18 @@ class Config:
self
.
config
[
key
]
=
value
self
.
config
[
key
]
=
value
def
__getitem__
(
self
,
key
:
str
)
->
Any
:
def
__getitem__
(
self
,
key
:
str
)
->
Any
:
return
self
.
config
[
key
]
return
self
.
get
(
key
)
def
__setitem__
(
self
,
key
:
str
,
value
:
Any
)
->
Any
:
def
__setitem__
(
self
,
key
:
str
,
value
:
Any
)
->
Any
:
self
.
config
[
key
]
=
value
self
.
set
(
key
,
value
)
def
__delitem__
(
self
,
key
):
def
__delitem__
(
self
,
key
):
del
self
.
config
[
key
]
del
self
.
config
[
key
]
def
save
(
self
):
def
save
(
self
):
if
not
self
.
file_path
.
exists
():
self
.
file_path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
with
self
.
file_path
.
open
(
'
w+
'
)
as
f
:
with
self
.
file_path
.
open
(
'
w+
'
)
as
f
:
json
.
dump
(
self
.
config
,
f
,
indent
=
2
)
json
.
dump
(
self
.
config
,
f
,
indent
=
2
)
...
...
This diff is collapsed.
Click to expand it.
lustmolch/lustmolch.py
+
12
−
8
View file @
483239d0
...
@@ -10,7 +10,7 @@ from jinja2 import Environment, PackageLoader
...
@@ -10,7 +10,7 @@ from jinja2 import Environment, PackageLoader
from
.config
import
config
,
DEFAULT_TEMPLATE_DIR
from
.config
import
config
,
DEFAULT_TEMPLATE_DIR
logging
.
basicConfig
(
level
=
config
[
'
log_level
'
])
logging
.
basicConfig
(
format
=
'
%(levelname)s:%(message)s
'
,
level
=
config
[
'
log_level
'
])
env
=
Environment
(
loader
=
PackageLoader
(
'
lustmolch
'
,
str
(
Path
(
__file__
).
parent
.
parent
/
'
templates
'
)))
env
=
Environment
(
loader
=
PackageLoader
(
'
lustmolch
'
,
str
(
Path
(
__file__
).
parent
.
parent
/
'
templates
'
)))
cfg_template
=
namedtuple
(
'
cfg_template
'
,
[
'
source
'
,
'
path
'
,
'
filename
'
])
cfg_template
=
namedtuple
(
'
cfg_template
'
,
[
'
source
'
,
'
path
'
,
'
filename
'
])
...
@@ -66,13 +66,13 @@ def next_ip_address(name: str) -> Tuple[str, str]:
...
@@ -66,13 +66,13 @@ def next_ip_address(name: str) -> Tuple[str, str]:
return
(
c
.
get
(
'
ip_address_host
'
).
split
(
'
/
'
)[
0
],
return
(
c
.
get
(
'
ip_address_host
'
).
split
(
'
/
'
)[
0
],
c
.
get
(
'
ip_address_container
'
).
split
(
'
/
'
)[
0
])
c
.
get
(
'
ip_address_container
'
).
split
(
'
/
'
)[
0
])
ip_host
=
list
(
config
[
'
ip_start_host
'
]
)
ip_host
=
[
int
(
ip
)
for
ip
in
config
[
'
ip_start_host
'
]
.
split
(
'
.
'
)]
container_ips
=
[
container
[
'
ip_address_host
'
].
split
(
'
/
'
)[
0
].
split
(
'
.
'
)
container_ips
=
[
container
[
'
ip_address_host
'
].
split
(
'
/
'
)[
0
].
split
(
'
.
'
)
for
container
in
config
[
'
containers
'
].
values
()]
for
container
in
config
[
'
containers
'
].
values
()]
ip_host
[
2
]
=
max
([
int
(
ip
[
2
])
for
ip
in
container_ips
])
ip_host
[
2
]
=
max
([
int
(
ip
[
2
])
for
ip
in
container_ips
]
+
[
ip_host
[
2
]]
)
ip_host
[
3
]
=
max
([
int
(
ip
[
3
])
for
ip
in
container_ips
])
ip_host
[
3
]
=
max
([
int
(
ip
[
3
])
for
ip
in
container_ips
]
+
[
ip_host
[
3
]]
)
ip_host
[
3
]
+=
4
ip_host
[
3
]
+=
4
if
ip_host
[
3
]
>=
254
:
if
ip_host
[
3
]
>=
254
:
...
@@ -85,9 +85,9 @@ def next_ip_address(name: str) -> Tuple[str, str]:
...
@@ -85,9 +85,9 @@ def next_ip_address(name: str) -> Tuple[str, str]:
ip_container
=
list
(
ip_host
)
ip_container
=
list
(
ip_host
)
ip_container
[
3
]
+=
1
ip_container
[
3
]
+=
1
return
(
return
(
'
.
'
.
join
(
'
.
'
.
join
(
str
(
x
)
for
x
in
ip_host
),
str
(
x
)
for
x
in
ip_
host
),
'
.
'
.
join
(
'
.
'
.
join
(
str
(
x
)
for
x
in
ip_
container
)
str
(
x
)
for
x
in
ip_container
)
)
)
def
list_containers
():
def
list_containers
():
...
@@ -117,7 +117,7 @@ def create_container(dry_run, name):
...
@@ -117,7 +117,7 @@ def create_container(dry_run, name):
'
ssh_port
'
:
ssh_port
,
'
ssh_port
'
:
ssh_port
,
'
ip_address_host
'
:
ip_address_host
,
'
ip_address_host
'
:
ip_address_host
,
'
ip_address_container
'
:
ip_address_container
,
'
ip_address_container
'
:
ip_address_container
,
'
ip_subnet_length
'
:
config
[
'
ip_subnet_leng
h
t
'
],
'
ip_subnet_length
'
:
config
[
'
ip_subnet_lengt
h
'
],
'
url
'
:
f
'
{
name
}
.stusta.de
'
,
'
url
'
:
f
'
{
name
}
.stusta.de
'
,
'
users
'
:
[]
'
users
'
:
[]
}
}
...
@@ -209,9 +209,13 @@ def add_user(key_string: bool, name: str, key: str) -> None:
...
@@ -209,9 +209,13 @@ def add_user(key_string: bool, name: str, key: str) -> None:
def
remove_user
(
name
:
str
)
->
None
:
def
remove_user
(
name
:
str
)
->
None
:
"""
remove a user, doesn
'
t remove the user from all containers
"""
"""
remove a user, doesn
'
t remove the user from all containers
"""
logging
.
info
(
f
'
Removing user
{
name
}
'
)
if
name
in
config
[
'
users
'
]:
if
name
in
config
[
'
users
'
]:
del
config
[
'
users
'
][
name
]
del
config
[
'
users
'
][
name
]
for
container
in
config
[
'
containers
'
]:
container
[
'
users
'
]
=
[
user
for
user
in
container
[
'
users
'
]
if
user
!=
name
]
config
.
save
()
config
.
save
()
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
483239d0
from
setuptools
import
setup
from
setuptools
import
setup
VERSION
=
'
1.0.
0
'
VERSION
=
'
1.0.
1
'
AUTHOR
=
'
Michael Loipführer
'
AUTHOR
=
'
Michael Loipführer
'
...
...
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