Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
961abad1
Commit
961abad1
authored
Oct 18, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add heatbeat
parent
17ade287
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
21 deletions
+24
-21
api.py
apps/terminal/api.py
+10
-19
hands.py
apps/terminal/hands.py
+5
-0
models.py
apps/terminal/models.py
+1
-1
serializers.py
apps/terminal/serializers.py
+7
-1
urls.py
apps/terminal/urls.py
+1
-0
No files found.
apps/terminal/api.py
View file @
961abad1
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
rest_framework.generics
import
ListCreateAPIView
from
rest_framework.generics
import
ListCreateAPIView
,
CreateAPIView
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.permissions
import
AllowAny
from
rest_framework.permissions
import
AllowAny
from
common.utils
import
unsign
,
get_object_or_none
from
common.utils
import
unsign
,
get_object_or_none
from
.models
import
Terminal
from
.models
import
Terminal
,
TerminalHeatbeat
from
.serializers
import
TerminalSerializer
from
.serializers
import
TerminalSerializer
,
TerminalHeatbeatSerializer
from
.hands
import
IsSuperUserOrTerminalUser
class
TerminalApi
(
ListCreateAPIView
):
class
TerminalApi
(
ListCreateAPIView
):
...
@@ -21,7 +22,7 @@ class TerminalApi(ListCreateAPIView):
...
@@ -21,7 +22,7 @@ class TerminalApi(ListCreateAPIView):
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
if
terminal
:
if
terminal
:
if
terminal
.
is_accepted
and
terminal
.
is_active
:
if
terminal
.
is_accepted
and
terminal
.
is_active
:
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'i
p'
:
terminal
.
ip
},
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'i
d'
:
terminal
.
id
},
'msg'
:
'Success'
},
'msg'
:
'Success'
},
status
=
200
)
status
=
200
)
else
:
else
:
...
@@ -36,20 +37,10 @@ class TerminalApi(ListCreateAPIView):
...
@@ -36,20 +37,10 @@ class TerminalApi(ListCreateAPIView):
'msg'
:
'Need admin accept or active it'
},
'msg'
:
'Need admin accept or active it'
},
status
=
204
)
status
=
204
)
else
:
else
:
return
Response
(
data
=
{
'error'
:
'Secrete key invalid'
},
status
=
401
)
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
# class TerminalRegister(APIView):
# def post(self, request, format='json'):
# return Response(data={'hello': request.META.get('REMOTE_ADDR')})
# name = unsign(request.data.get('name', ''))
# if name:
# terminal = get_object_or_none(Terminal, name=name)
# if terminal:
# return Response(data={'name': name, 'ip': terminal.ip}, status=200)
# else:
# ip = request.Meta.get('X-Real-IP')
# Terminal.objects.create(name=name, ip=request.META.host)
class
TerminalHeatbeatApi
(
CreateAPIView
):
model
=
TerminalHeatbeat
serializer_class
=
TerminalHeatbeatSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
apps/terminal/hands.py
0 → 100644
View file @
961abad1
# -*- coding: utf-8 -*-
#
from
users.backends
import
IsSuperUserOrTerminalUser
apps/terminal/models.py
View file @
961abad1
...
@@ -41,7 +41,7 @@ class Terminal(models.Model):
...
@@ -41,7 +41,7 @@ class Terminal(models.Model):
class
TerminalHeatbeat
(
models
.
Model
):
class
TerminalHeatbeat
(
models
.
Model
):
terminal
=
models
.
ForeignKey
(
Terminal
,
on_delete
=
models
.
CASCADE
)
terminal
=
models
.
ForeignKey
(
Terminal
,
on_delete
=
models
.
CASCADE
)
date_
timestamp
=
models
.
IntegerField
(
)
date_
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
class
Meta
:
class
Meta
:
db_table
=
'terminal_heatbeat'
db_table
=
'terminal_heatbeat'
apps/terminal/serializers.py
View file @
961abad1
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
.models
import
Terminal
from
.models
import
Terminal
,
TerminalHeatbeat
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
...
@@ -13,5 +13,11 @@ class TerminalSerializer(serializers.ModelSerializer):
...
@@ -13,5 +13,11 @@ class TerminalSerializer(serializers.ModelSerializer):
'get_type_display'
]
'get_type_display'
]
class
TerminalHeatbeatSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
TerminalHeatbeat
fields
=
[
'terminal'
]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
pass
pass
apps/terminal/urls.py
View file @
961abad1
...
@@ -15,4 +15,5 @@ urlpatterns = [
...
@@ -15,4 +15,5 @@ urlpatterns = [
urlpatterns
+=
[
urlpatterns
+=
[
url
(
r'^v1/terminal/$'
,
api
.
TerminalApi
.
as_view
(),
name
=
'terminal-list-create-api'
),
url
(
r'^v1/terminal/$'
,
api
.
TerminalApi
.
as_view
(),
name
=
'terminal-list-create-api'
),
url
(
r'^v1/terminal-heatbeat/$'
,
api
.
TerminalHeatbeatApi
.
as_view
(),
name
=
'terminal-heatbeat-api'
),
]
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment