Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
fc376318
Commit
fc376318
authored
Dec 26, 2020
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
hangar creation management command
parent
aac6aec4
Branches
Branches containing commit
Tags
release/polls/5.4.0
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/management/commands/hangar_creation.py
+63
-0
63 additions, 0 deletions
src/core/management/commands/hangar_creation.py
src/core/models/assemblies.py
+6
-0
6 additions, 0 deletions
src/core/models/assemblies.py
with
69 additions
and
0 deletions
src/core/management/commands/hangar_creation.py
0 → 100644
+
63
−
0
View file @
fc376318
import
logging
import
subprocess
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.utils
import
timezone
from
core.models.rooms
import
Room
def
create_hangar
(
room
:
Room
):
username
=
room
.
assembly
.
slug
cmd
=
[
'
ssh
'
,
settings
.
HANGAR_HOST
,
settings
.
HANGAR_CMD
,
username
]
result
=
subprocess
.
run
(
cmd
,
capture_output
=
True
,
timeout
=
42
,
encoding
=
'
utf-8
'
,
stderr
=
subprocess
.
STDOUT
)
if
result
.
returncode
==
0
:
password
=
result
.
stdout
room
.
backend_link
=
settings
.
BACKEND_URL
.
format
(
username
=
username
,
password
=
password
)
room
.
backend_status
=
Room
.
BackendStatus
.
ACTIVE
all_contacts
=
room
.
assembly
.
get_all_managing_contacts
()
room
.
backend_data
=
{
'
timestamp
'
:
timezone
.
now
(),
'
contacts
'
:
all_contacts
,
}
room
.
save
()
else
:
room
.
backend_data
=
{
'
timestamp
'
:
timezone
.
now
(),
'
_error
'
:
result
.
stdout
,
}
room
.
backend_status
=
Room
.
BackendStatus
.
ERROR
room
.
save
()
raise
Exception
(
'
Backend creation failed.
'
)
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
for
x
in
[
'
URL
'
,
'
BACKEND_URL
'
,
'
HOST
'
,
'
CMD
'
]:
if
not
hasattr
(
settings
,
'
HANGAR_
'
+
x
)
or
getattr
(
settings
,
'
HANGAR_
'
+
x
)
in
[
None
,
''
]:
raise
CommandError
(
f
'
No HANGAR_
{
x
}
configured.
'
)
if
settings
.
HANGAR_BACKEND_URL
is
None
or
settings
.
HANGAR_BACKEND_URL
==
''
:
raise
CommandError
(
'
No HANGAR_BACKEND_URL configured.
'
)
rooms
=
Room
.
objects
.
filter
(
room_type
=
Room
.
RoomType
.
HANGAR
,
backend_status
=
Room
.
BackendStatus
.
NEW
)
for
room
in
rooms
:
room
.
backend_status
=
Room
.
BackendStatus
.
SETUP
room
.
save
()
try
:
create_hangar
(
room
)
except
Exception
as
err
:
logging
.
error
(
'
Got error on creating hangar for %s: %s
'
,
room
,
err
)
room
.
backend_status
=
Room
.
BackendStatus
.
ERROR
room
.
backend_data
=
{
'
timestamp
'
:
timezone
.
now
(),
'
_exception
'
:
str
(
err
),
}
room
.
save
()
This diff is collapsed.
Click to expand it.
src/core/models/assemblies.py
+
6
−
0
View file @
fc376318
...
...
@@ -293,6 +293,12 @@ class Assembly(TaggedItemMixin, models.Model):
def
sorted_tags
(
self
):
return
sorted
(
t
[
'
slug
'
]
for
t
in
self
.
tags
)
def
get_all_managing_contacts
(
self
):
result
=
{}
for
member
in
self
.
members
.
filter
(
role__in
=
AssemblyMember
.
MANAGEMENT_ROLES
):
result
[
member
.
member
.
username
]
=
member
.
member
.
get_verified_contacts
()
return
result
def
create_technical_user_if_necessary
(
self
):
if
self
.
technical_user
is
not
None
:
return
self
.
technical_user
...
...
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