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
75319b99
Commit
75319b99
authored
Mar 25, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 更新ap请求
parent
7f4f67aa
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
14 deletions
+57
-14
domain.py
apps/assets/api/domain.py
+13
-6
domain.py
apps/assets/models/domain.py
+13
-0
asset.py
apps/assets/serializers/asset.py
+1
-1
domain.py
apps/assets/serializers/domain.py
+21
-0
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+0
-0
inventory.py
apps/ops/inventory.py
+2
-3
jms
jms
+7
-4
No files found.
apps/assets/api/domain.py
View file @
75319b99
# ~*~ coding: utf-8 ~*~
from
rest_framework_bulk
import
BulkModelViewSet
from
rest_framework.views
import
APIView
from
rest_framework.
views
import
Response
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.
generics
import
RetrieveAPIView
from
django.views.generic.detail
import
SingleObjectMixin
from
common.utils
import
get_logger
from
..hands
import
IsSuperUser
from
..hands
import
IsSuperUser
,
IsSuperUserOrAppUser
from
..models
import
Domain
,
Gateway
from
..utils
import
test_gateway_connectability
from
..
import
serializers
...
...
@@ -22,6 +22,16 @@ class DomainViewSet(BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
serializer_class
=
serializers
.
DomainSerializer
def
get_serializer_class
(
self
):
if
self
.
request
.
query_params
.
get
(
'gateway'
):
return
serializers
.
DomainWithGatewaySerializer
return
super
()
.
get_serializer_class
()
def
get_permissions
(
self
):
if
self
.
request
.
query_params
.
get
(
'gateway'
):
self
.
permission_classes
=
(
IsSuperUserOrAppUser
,)
return
super
()
.
get_permissions
()
class
GatewayViewSet
(
BulkModelViewSet
):
filter_fields
=
(
"domain"
,)
...
...
@@ -43,6 +53,3 @@ class GatewayTestConnectionApi(SingleObjectMixin, APIView):
return
Response
(
"ok"
)
else
:
return
Response
({
"failed"
:
e
},
status
=
404
)
apps/assets/models/domain.py
View file @
75319b99
...
...
@@ -2,6 +2,8 @@
#
import
uuid
import
random
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -20,6 +22,16 @@ class Domain(models.Model):
def
__str__
(
self
):
return
self
.
name
def
has_gateway
(
self
):
return
self
.
gateway_set
.
filter
(
is_active
=
True
)
.
exists
()
@property
def
gateways
(
self
):
return
self
.
gateway_set
.
filter
(
is_active
=
True
)
def
random_gateway
(
self
):
return
random
.
choice
(
self
.
gateways
)
class
Gateway
(
AssetUser
):
SSH_PROTOCOL
=
'ssh'
...
...
@@ -37,3 +49,4 @@ class Gateway(AssetUser):
def
__str__
(
self
):
return
self
.
name
apps/assets/serializers/asset.py
View file @
75319b99
...
...
@@ -38,7 +38,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
model
=
Asset
fields
=
(
"id"
,
"hostname"
,
"ip"
,
"port"
,
"system_users_granted"
,
"is_active"
,
"system_users_join"
,
"os"
,
"is_active"
,
"system_users_join"
,
"os"
,
'domain'
,
"platform"
,
"comment"
)
...
...
apps/assets/serializers/domain.py
View file @
75319b99
...
...
@@ -26,4 +26,25 @@ class GatewaySerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Gateway
fields
=
[
'id'
,
'name'
,
'ip'
,
'port'
,
'protocol'
,
'username'
,
'domain'
,
'is_active'
,
'date_created'
,
'date_updated'
,
'created_by'
,
'comment'
,
]
class
GatewayWithAuthSerializer
(
GatewaySerializer
):
def
get_field_names
(
self
,
declared_fields
,
info
):
fields
=
super
()
.
get_field_names
(
declared_fields
,
info
)
fields
.
extend
(
[
'password'
,
'private_key'
]
)
return
fields
class
DomainWithGatewaySerializer
(
serializers
.
ModelSerializer
):
gateways
=
GatewayWithAuthSerializer
(
many
=
True
,
read_only
=
True
)
class
Meta
:
model
=
Domain
fields
=
'__all__'
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
75319b99
No preview for this file type
apps/i18n/zh/LC_MESSAGES/django.po
View file @
75319b99
This diff is collapsed.
Click to expand it.
apps/ops/inventory.py
View file @
75319b99
# -*- coding: utf-8 -*-
#
import
random
from
.ansible.inventory
import
BaseInventory
from
assets.utils
import
get_assets_by_hostname_list
,
get_system_user_by_name
...
...
@@ -11,7 +10,7 @@ __all__ = [
def
make_proxy_command
(
asset
):
gateway
=
random
.
choice
(
asset
.
domain
.
gateway_set
.
filter
(
is_active
=
True
)
)
gateway
=
asset
.
domain
.
random_gateway
(
)
proxy_command
=
[
"ssh"
,
"-p"
,
str
(
gateway
.
port
),
...
...
@@ -49,7 +48,7 @@ class JMSInventory(BaseInventory):
info
=
asset
.
to_json
()
info
[
"vars"
]
=
vars
if
asset
.
domain
and
asset
.
domain
.
gateway_set
.
count
():
if
asset
.
domain
and
asset
.
domain
.
has_gateway
():
vars
.
update
(
make_proxy_command
(
asset
))
info
.
update
(
vars
)
...
...
jms
View file @
75319b99
...
...
@@ -82,7 +82,10 @@ def get_pid(service):
pid_file
=
get_pid_file_path
(
service
)
if
os
.
path
.
isfile
(
pid_file
):
with
open
(
pid_file
)
as
f
:
return
int
(
f
.
read
()
.
strip
())
try
:
return
int
(
f
.
read
()
.
strip
())
except
ValueError
:
return
0
return
0
...
...
@@ -282,9 +285,9 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
(
description
=
"""
Jumpserver service control tools;
Example:
\r\n
Example:
\r\n
%(prog)
s start all -d;
"""
)
...
...
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