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
63216add
Commit
63216add
authored
Jun 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改connectivity
parent
9dd951dd
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
115 additions
and
106 deletions
+115
-106
__init__.py
apps/assets/models/__init__.py
+3
-3
asset.py
apps/assets/models/asset.py
+1
-1
authbook.py
apps/assets/models/authbook.py
+0
-3
base.py
apps/assets/models/base.py
+18
-14
utils.py
apps/assets/models/utils.py
+67
-3
admin_user.py
apps/assets/serializers/admin_user.py
+8
-13
tasks.py
apps/assets/tasks.py
+1
-1
admin_user_list.html
apps/assets/templates/assets/admin_user_list.html
+16
-11
utils.py
apps/assets/utils.py
+1
-57
No files found.
apps/assets/models/__init__.py
View file @
63216add
from
.
user
import
*
from
.
asset
import
*
from
.label
import
Label
from
.user
import
*
from
.cluster
import
*
from
.group
import
*
from
.domain
import
*
from
.node
import
*
from
.asset
import
*
from
.cmd_filter
import
*
from
.utils
import
*
from
.authbook
import
*
from
.utils
import
*
apps/assets/models/asset.py
View file @
63216add
...
...
@@ -12,8 +12,8 @@ from django.utils.translation import ugettext_lazy as _
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
from
.user
import
AdminUser
,
SystemUser
from
.utils
import
Connectivity
from
orgs.mixins
import
OrgModelMixin
,
OrgManager
from
..utils
import
Connectivity
__all__
=
[
'Asset'
,
'Protocol'
]
logger
=
logging
.
getLogger
(
__name__
)
...
...
apps/assets/models/authbook.py
View file @
63216add
...
...
@@ -5,7 +5,6 @@ from django.db import models
from
django.utils.translation
import
ugettext_lazy
as
_
from
orgs.mixins
import
OrgManager
from
..utils
import
Connectivity
from
.base
import
AssetUser
__all__
=
[
'AuthBook'
]
...
...
@@ -72,8 +71,6 @@ class AuthBook(AssetUser):
@property
def
connectivity
(
self
):
if
self
.
_connectivity
:
return
self
.
_connectivity
return
self
.
get_asset_connectivity
(
self
.
asset
)
@property
...
...
apps/assets/models/base.py
View file @
63216add
...
...
@@ -6,7 +6,6 @@ from hashlib import md5
import
sshpubkeys
from
django.db
import
models
from
django.core.cache
import
cache
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.conf
import
settings
...
...
@@ -16,9 +15,7 @@ from common.utils import (
from
common.validators
import
alphanumeric
from
common
import
fields
from
orgs.mixins
import
OrgModelMixin
from
.utils
import
private_key_validator
from
..utils
import
Connectivity
from
..
import
const
from
.utils
import
private_key_validator
,
Connectivity
signer
=
get_signer
()
...
...
@@ -167,12 +164,12 @@ class AssetUser(OrgModelMixin):
def
get_asset_connectivity
(
self
,
asset
):
i
=
self
.
generate_id_with_asset
(
asset
)
key
=
self
.
CONNECTIVITY_ASSET_CACHE_KEY
.
format
(
i
)
return
cache
.
get
(
key
,
const
.
CONN_UNKNOWN
)
return
Connectivity
.
get
(
key
)
def
set_asset_connectivity
(
self
,
asset
,
c
):
i
=
self
.
generate_id_with_asset
(
asset
)
key
=
self
.
CONNECTIVITY_ASSET_CACHE_KEY
.
format
(
i
)
cache
.
set
(
key
,
c
,
3600
)
Connectivity
.
set
(
key
,
c
,
3600
)
def
load_specific_asset_auth
(
self
,
asset
):
from
..backends
import
AssetUserManager
...
...
@@ -225,17 +222,24 @@ class AssetUser(OrgModelMixin):
}
def
generate_id_with_asset
(
self
,
asset
):
i
=
'{}_{}'
.
format
(
asset
.
id
,
self
.
id
)
i
=
uuid
.
UUID
(
md5
(
i
.
encode
())
.
hexdigest
())
return
i
user_id
=
str
(
self
.
id
)
.
split
(
'-'
)[:
3
]
asset_id
=
str
(
asset
.
id
)
.
split
(
'-'
)[
3
:]
ids
=
user_id
+
asset_id
return
'-'
.
join
(
ids
)
def
construct_to_authbook
(
self
,
asset
):
from
.
import
AuthBook
fields
=
[
'name'
,
'username'
,
'comment'
,
'org_id'
,
'_password'
,
'_private_key'
,
'_public_key'
,
'date_created'
,
'date_updated'
,
'created_by'
]
i
=
self
.
generate_id_with_asset
(
asset
)
self
.
id
=
i
self
.
asset
=
asset
self
.
version
=
0
self
.
is_latest
=
True
return
self
obj
=
AuthBook
(
id
=
i
,
asset
=
asset
,
version
=
0
,
is_latest
=
True
)
for
field
in
fields
:
value
=
getattr
(
self
,
field
)
setattr
(
obj
,
field
,
value
)
return
obj
class
Meta
:
abstract
=
True
...
...
apps/assets/models/utils.py
View file @
63216add
...
...
@@ -2,11 +2,17 @@
# -*- coding: utf-8 -*-
#
from
django.utils
import
timezone
from
django.core.cache
import
cache
from
django.core.exceptions
import
ValidationError
from
django.utils.translation
import
ugettext_lazy
as
_
from
common.utils
import
validate_ssh_private_key
__all__
=
[
'init_model'
,
'generate_fake'
]
__all__
=
[
'init_model'
,
'generate_fake'
,
'private_key_validator'
,
'Connectivity'
,
]
def
init_model
():
...
...
@@ -31,5 +37,63 @@ def private_key_validator(value):
)
if
__name__
==
'__main__'
:
pass
class
Connectivity
:
UNREACHABLE
,
REACHABLE
,
UNKNOWN
=
range
(
0
,
3
)
CONNECTIVITY_CHOICES
=
(
(
UNREACHABLE
,
_
(
"Unreachable"
)),
(
REACHABLE
,
_
(
'Reachable'
)),
(
UNKNOWN
,
_
(
"Unknown"
)),
)
value
=
UNKNOWN
datetime
=
timezone
.
now
()
def
__init__
(
self
,
value
,
datetime
):
self
.
value
=
value
self
.
datetime
=
datetime
def
display
(
self
):
return
dict
(
self
.
__class__
.
CONNECTIVITY_CHOICES
)
.
get
(
self
.
value
)
def
is_reachable
(
self
):
return
self
.
value
==
self
.
REACHABLE
def
is_unreachable
(
self
):
return
self
.
value
==
self
.
UNREACHABLE
def
is_unknown
(
self
):
return
self
.
value
==
self
.
UNKNOWN
@classmethod
def
unreachable
(
cls
):
return
cls
(
cls
.
UNREACHABLE
,
timezone
.
now
())
@classmethod
def
reachable
(
cls
):
return
cls
(
cls
.
REACHABLE
,
timezone
.
now
())
@classmethod
def
unknown
(
cls
):
return
cls
(
cls
.
UNKNOWN
,
timezone
.
now
())
@classmethod
def
set
(
cls
,
key
,
value
,
ttl
=
0
):
cache
.
set
(
key
,
value
,
ttl
)
@classmethod
def
get
(
cls
,
key
):
value
=
cache
.
get
(
key
,
cls
.
unknown
())
if
not
isinstance
(
value
,
cls
):
value
=
cls
.
unknown
()
return
value
@classmethod
def
set_unreachable
(
cls
,
key
,
ttl
=
0
):
cls
.
set
(
key
,
cls
.
unreachable
(),
ttl
)
@classmethod
def
set_reachable
(
cls
,
key
,
ttl
=
0
):
cls
.
set
(
key
,
cls
.
reachable
(),
ttl
)
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
apps/assets/serializers/admin_user.py
View file @
63216add
...
...
@@ -23,24 +23,19 @@ class AdminUserSerializer(BulkOrgResourceModelSerializer):
list_serializer_class
=
AdaptedBulkListSerializer
model
=
AdminUser
fields
=
[
'id'
,
'name'
,
'username'
,
'assets_amount'
,
'reachable_amount'
,
'unreachable_amount'
,
'password'
,
'comment'
,
'date_created'
,
'date_updated'
,
'become'
,
'become_method'
,
'become_user'
,
'created_by'
,
'id'
,
'name'
,
'username'
,
'password'
,
'comment'
,
'connectivity_amount'
,
'assets_amount'
,
'date_created'
,
'date_updated'
,
'created_by'
,
]
extra_kwargs
=
{
'date_created'
:
{
'
label'
:
_
(
'Date created'
)
},
'date_updated'
:
{
'
label'
:
_
(
'Date updated'
)
},
'
become'
:
{
'read_only'
:
True
},
'become_method
'
:
{
'read_only'
:
True
},
'
become_user'
:
{
'read_only'
:
True
},
'created_by'
:
{
'read_only'
:
True
},
'
assets_amount'
:
{
'label'
,
_
(
'Asset'
)}
'date_created'
:
{
'
read_only'
:
True
},
'date_updated'
:
{
'
read_only'
:
True
},
'
created_by
'
:
{
'read_only'
:
True
},
'
assets_amount'
:
{
'label'
:
_
(
'Asset'
)
},
'
connectivity_amount'
:
{
'label'
:
_
(
'Connectivity'
)},
}
def
get_field_names
(
self
,
declared_fields
,
info
):
fields
=
super
()
.
get_field_names
(
declared_fields
,
info
)
return
[
f
for
f
in
fields
if
not
f
.
startswith
(
'_'
)]
class
AdminUserAuthSerializer
(
AuthSerializer
):
...
...
apps/assets/tasks.py
View file @
63216add
...
...
@@ -16,8 +16,8 @@ from ops.celery.decorator import (
)
from
.models
import
SystemUser
,
AdminUser
from
.models.utils
import
Connectivity
from
.
import
const
from
.utils
import
Connectivity
FORKS
=
10
...
...
apps/assets/templates/assets/admin_user_list.html
View file @
63216add
...
...
@@ -75,27 +75,29 @@ function initTable() {
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
""
;
if
(
cellData
!==
0
)
{
innerHtml
=
"<span class='text-navy'>"
+
cellData
+
"</span>"
;
var
data
=
cellData
[
'reachable'
];
if
(
data
!==
0
)
{
innerHtml
=
"<span class='text-navy'>"
+
data
+
"</span>"
;
}
else
{
innerHtml
=
"<span>"
+
cellD
ata
+
"</span>"
;
innerHtml
=
"<span>"
+
d
ata
+
"</span>"
;
}
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellD
ata
+
'">'
+
innerHtml
+
'</span>'
);
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
d
ata
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
var
data
=
cellData
[
'unreachable'
];
var
innerHtml
=
""
;
if
(
cellD
ata
!==
0
)
{
innerHtml
=
"<span class='text-danger'>"
+
cellD
ata
+
"</span>"
;
if
(
d
ata
!==
0
)
{
innerHtml
=
"<span class='text-danger'>"
+
d
ata
+
"</span>"
;
}
else
{
innerHtml
=
"<span>"
+
cellD
ata
+
"</span>"
;
innerHtml
=
"<span>"
+
d
ata
+
"</span>"
;
}
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellD
ata
+
'">'
+
innerHtml
+
'</span>'
);
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
d
ata
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
val
=
0
;
var
innerHtml
=
""
;
var
total
=
rowData
.
assets_amount
;
var
reachable
=
rowData
.
reachable_amount
;
var
reachable
=
cellData
.
reachable
;
if
(
total
!==
0
)
{
val
=
reachable
/
total
*
100
;
}
...
...
@@ -114,8 +116,11 @@ function initTable() {
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
ajax_url
:
'{% url "api-assets:admin-user-list" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"username"
},
{
data
:
"assets_amount"
},
{
data
:
"reachable_amount"
},
{
data
:
"unreachable_amount"
},
{
data
:
"id"
},
{
data
:
"comment"
},
{
data
:
"id"
}]
columns
:
[
{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"username"
},
{
data
:
"assets_amount"
},
{
data
:
"connectivity_amount"
},
{
data
:
"connectivity_amount"
},
{
data
:
"connectivity_amount"
},
{
data
:
"comment"
},
{
data
:
"id"
}
]
};
admin_user_table
=
jumpserver
.
initServerSideDataTable
(
options
);
return
admin_user_table
...
...
apps/assets/utils.py
View file @
63216add
...
...
@@ -5,7 +5,7 @@ from django.core.cache import cache
from
django.utils
import
timezone
from
common.utils
import
get_object_or_none
from
.models
import
Asset
,
SystemUser
,
Label
from
.models
import
SystemUser
,
Label
def
get_assets_by_id_list
(
id_list
):
...
...
@@ -47,60 +47,4 @@ class LabelFilter:
return
queryset
class
Connectivity
:
UNREACHABLE
,
REACHABLE
,
UNKNOWN
=
range
(
0
,
3
)
CONNECTIVITY_CHOICES
=
(
(
UNREACHABLE
,
_
(
"Unreachable"
)),
(
REACHABLE
,
_
(
'Reachable'
)),
(
UNKNOWN
,
_
(
"Unknown"
)),
)
value
=
UNKNOWN
datetime
=
timezone
.
now
()
def
__init__
(
self
,
value
,
datetime
):
self
.
value
=
value
self
.
datetime
=
datetime
def
display
(
self
):
return
dict
(
self
.
__class__
.
CONNECTIVITY_CHOICES
)
.
get
(
self
.
value
)
def
is_reachable
(
self
):
return
self
.
value
==
self
.
REACHABLE
def
is_unreachable
(
self
):
return
self
.
value
==
self
.
UNREACHABLE
def
is_unknown
(
self
):
return
self
.
value
==
self
.
UNKNOWN
@classmethod
def
unreachable
(
cls
):
return
cls
(
cls
.
UNREACHABLE
,
timezone
.
now
())
@classmethod
def
reachable
(
cls
):
return
cls
(
cls
.
REACHABLE
,
timezone
.
now
())
@classmethod
def
unknown
(
cls
):
return
cls
(
cls
.
UNKNOWN
,
timezone
.
now
())
@classmethod
def
set
(
cls
,
key
,
value
,
ttl
=
0
):
cache
.
set
(
key
,
value
,
ttl
)
@classmethod
def
get
(
cls
,
key
):
return
cache
.
get
(
key
,
cls
.
UNKNOWN
)
@classmethod
def
set_unreachable
(
cls
,
key
,
ttl
=
0
):
cls
.
set
(
key
,
cls
.
unreachable
(),
ttl
)
@classmethod
def
set_reachable
(
cls
,
key
,
ttl
=
0
):
cls
.
set
(
key
,
cls
.
reachable
(),
ttl
)
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
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