Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Anders Harrisson
csentry
Commits
f7c71b50
Commit
f7c71b50
authored
6 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add function to update the TN core services
parent
f384a9da
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/network/views.py
+5
-1
5 additions, 1 deletion
app/network/views.py
app/settings.py
+3
-0
3 additions, 0 deletions
app/settings.py
app/tasks.py
+44
-0
44 additions, 0 deletions
app/tasks.py
with
52 additions
and
1 deletion
app/network/views.py
+
5
−
1
View file @
f7c71b50
...
@@ -18,7 +18,7 @@ from .forms import (HostForm, InterfaceForm, HostInterfaceForm, NetworkForm,
...
@@ -18,7 +18,7 @@ from .forms import (HostForm, InterfaceForm, HostInterfaceForm, NetworkForm,
NetworkScopeForm
,
DomainForm
)
NetworkScopeForm
,
DomainForm
)
from
..extensions
import
db
from
..extensions
import
db
from
..decorators
import
login_groups_accepted
from
..decorators
import
login_groups_accepted
from
..
import
models
,
utils
,
helpers
from
..
import
models
,
utils
,
helpers
,
tasks
bp
=
Blueprint
(
'
network
'
,
__name__
)
bp
=
Blueprint
(
'
network
'
,
__name__
)
...
@@ -72,6 +72,7 @@ def create_host():
...
@@ -72,6 +72,7 @@ def create_host():
flash
(
f
'
{
e
}
'
,
'
error
'
)
flash
(
f
'
{
e
}
'
,
'
error
'
)
else
:
else
:
flash
(
f
'
Host
{
host
}
created!
'
,
'
success
'
)
flash
(
f
'
Host
{
host
}
created!
'
,
'
success
'
)
tasks
.
trigger_core_services_update
()
# Save network_id to the session to retrieve it after the redirect
# Save network_id to the session to retrieve it after the redirect
session
[
'
network_id
'
]
=
network_id
session
[
'
network_id
'
]
=
network_id
return
redirect
(
url_for
(
'
network.create_host
'
))
return
redirect
(
url_for
(
'
network.create_host
'
))
...
@@ -103,6 +104,7 @@ def edit_host(name):
...
@@ -103,6 +104,7 @@ def edit_host(name):
flash
(
f
'
{
e
}
'
,
'
error
'
)
flash
(
f
'
{
e
}
'
,
'
error
'
)
else
:
else
:
flash
(
f
'
Host
{
host
}
updated!
'
,
'
success
'
)
flash
(
f
'
Host
{
host
}
updated!
'
,
'
success
'
)
tasks
.
trigger_core_services_update
()
return
redirect
(
url_for
(
'
network.view_host
'
,
name
=
host
.
name
))
return
redirect
(
url_for
(
'
network.view_host
'
,
name
=
host
.
name
))
return
render_template
(
'
network/edit_host.html
'
,
form
=
form
)
return
render_template
(
'
network/edit_host.html
'
,
form
=
form
)
...
@@ -137,6 +139,7 @@ def create_interface(hostname):
...
@@ -137,6 +139,7 @@ def create_interface(hostname):
flash
(
f
'
{
e
}
'
,
'
error
'
)
flash
(
f
'
{
e
}
'
,
'
error
'
)
else
:
else
:
flash
(
f
'
Host
{
interface
}
created!
'
,
'
success
'
)
flash
(
f
'
Host
{
interface
}
created!
'
,
'
success
'
)
tasks
.
trigger_core_services_update
()
return
redirect
(
url_for
(
'
network.create_interface
'
,
hostname
=
hostname
))
return
redirect
(
url_for
(
'
network.create_interface
'
,
hostname
=
hostname
))
return
render_template
(
'
network/create_interface.html
'
,
form
=
form
,
hostname
=
hostname
)
return
render_template
(
'
network/create_interface.html
'
,
form
=
form
,
hostname
=
hostname
)
...
@@ -199,6 +202,7 @@ def edit_interface(name):
...
@@ -199,6 +202,7 @@ def edit_interface(name):
flash
(
f
'
{
e
}
'
,
'
error
'
)
flash
(
f
'
{
e
}
'
,
'
error
'
)
else
:
else
:
flash
(
f
'
Interface
{
interface
}
updated!
'
,
'
success
'
)
flash
(
f
'
Interface
{
interface
}
updated!
'
,
'
success
'
)
tasks
.
trigger_core_services_update
()
return
redirect
(
url_for
(
'
network.view_host
'
,
name
=
interface
.
host
.
name
))
return
redirect
(
url_for
(
'
network.view_host
'
,
name
=
interface
.
host
.
name
))
return
render_template
(
'
network/edit_interface.html
'
,
form
=
form
,
hostname
=
interface
.
host
.
name
)
return
render_template
(
'
network/edit_interface.html
'
,
form
=
form
,
hostname
=
interface
.
host
.
name
)
...
...
This diff is collapsed.
Click to expand it.
app/settings.py
+
3
−
0
View file @
f7c71b50
...
@@ -66,3 +66,6 @@ TEMPORARY_ICS_ID = 'ZZ'
...
@@ -66,3 +66,6 @@ TEMPORARY_ICS_ID = 'ZZ'
MAC_OUI
=
'
02:42:42
'
MAC_OUI
=
'
02:42:42
'
DOCUMENTATION_URL
=
'
http://ics-infrastructure.pages.esss.lu.se/csentry/index.html
'
DOCUMENTATION_URL
=
'
http://ics-infrastructure.pages.esss.lu.se/csentry/index.html
'
# AWX job templates
AWX_CORE_SERVICES_UPDATE
=
'
ics-ans-core CSENTRY refresh
'
This diff is collapsed.
Click to expand it.
app/tasks.py
0 → 100644
+
44
−
0
View file @
f7c71b50
# -*- coding: utf-8 -*-
"""
app.tasks
~~~~~~~~~
This module implements tasks to run.
:copyright: (c) 2018 European Spallation Source ERIC
:license: BSD 2-Clause, see LICENSE for more details.
"""
import
tower_cli
from
flask
import
current_app
from
rq
import
Queue
def
trigger_core_services_update
():
"""
Trigger a job to update the core services on the TN (DNS and DHCP)
This function should be called every time an host or interface is created/edited
We can have one running job + one in queue to apply the latest changes.
Make sure that we don
'
t have more than one in queue.
"""
job_template
=
current_app
.
config
[
'
AWX_CORE_SERVICES_UPDATE
'
]
q
=
Queue
()
# Only trigger a new job if none is already waiting in queue
for
job
in
q
.
jobs
:
if
(
job
.
func_name
==
'
app.tasks.launch_job_template
'
and
job
.
kwargs
.
get
(
'
job_template
'
,
''
)
==
job_template
):
current_app
.
logger
.
info
(
f
'
Already one
{
job_template
}
job in queue. No need to trigger a new one.
'
)
return
None
current_app
.
logger
.
info
(
f
'
Launch new job to update core services:
{
job_template
}
'
)
job
=
q
.
enqueue
(
launch_job_template
,
job_template
=
job_template
,
)
return
job
def
launch_job_template
(
job_template
,
monitor
=
True
,
**
kwargs
):
resource
=
tower_cli
.
get_resource
(
'
job
'
)
result
=
resource
.
launch
(
job_template
=
job_template
,
monitor
=
monitor
,
**
kwargs
)
return
result
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