Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
3e17e942
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3e17e942
编写于
7月 15, 2018
作者:
baltery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Update] 修改资产
上级
5648dcd7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
40 deletion
+44
-40
apps/assets/forms/asset.py
apps/assets/forms/asset.py
+7
-4
apps/assets/models/asset.py
apps/assets/models/asset.py
+7
-15
apps/assets/models/node.py
apps/assets/models/node.py
+29
-9
apps/orgs/mixins.py
apps/orgs/mixins.py
+1
-12
未找到文件。
apps/assets/forms/asset.py
浏览文件 @
3e17e942
...
...
@@ -3,14 +3,17 @@
from
django
import
forms
from
django.utils.translation
import
gettext_lazy
as
_
from
..models
import
Asset
,
AdminUser
from
common.utils
import
get_logger
from
orgs.mixins
import
OrgModelForm
from
..models
import
Asset
,
AdminUser
logger
=
get_logger
(
__file__
)
__all__
=
[
'AssetCreateForm'
,
'AssetUpdateForm'
,
'AssetBulkUpdateForm'
]
class
AssetCreateForm
(
forms
.
ModelForm
):
class
AssetCreateForm
(
Org
ModelForm
):
class
Meta
:
model
=
Asset
fields
=
[
...
...
@@ -50,7 +53,7 @@ class AssetCreateForm(forms.ModelForm):
}
class
AssetUpdateForm
(
forms
.
ModelForm
):
class
AssetUpdateForm
(
Org
ModelForm
):
class
Meta
:
model
=
Asset
fields
=
[
...
...
@@ -90,7 +93,7 @@ class AssetUpdateForm(forms.ModelForm):
}
class
AssetBulkUpdateForm
(
forms
.
ModelForm
):
class
AssetBulkUpdateForm
(
Org
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
required
=
True
,
help_text
=
'* required'
,
label
=
_
(
'Select assets'
),
queryset
=
Asset
.
objects
.
all
(),
...
...
apps/assets/models/asset.py
浏览文件 @
3e17e942
...
...
@@ -71,16 +71,11 @@ class Asset(OrgModelMixin):
)
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
ip
=
models
.
GenericIPAddressField
(
max_length
=
32
,
verbose_name
=
_
(
'IP'
),
db_index
=
True
)
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Hostname'
))
protocol
=
models
.
CharField
(
max_length
=
128
,
default
=
SSH_PROTOCOL
,
choices
=
PROTOCOL_CHOICES
,
verbose_name
=
_
(
'Protocol'
))
ip
=
models
.
GenericIPAddressField
(
max_length
=
32
,
verbose_name
=
_
(
'IP'
),
db_index
=
True
)
hostname
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
'Hostname'
))
protocol
=
models
.
CharField
(
max_length
=
128
,
default
=
SSH_PROTOCOL
,
choices
=
PROTOCOL_CHOICES
,
verbose_name
=
_
(
'Protocol'
))
port
=
models
.
IntegerField
(
default
=
22
,
verbose_name
=
_
(
'Port'
))
platform
=
models
.
CharField
(
max_length
=
128
,
choices
=
PLATFORM_CHOICES
,
default
=
'Linux'
,
verbose_name
=
_
(
'Platform'
))
platform
=
models
.
CharField
(
max_length
=
128
,
choices
=
PLATFORM_CHOICES
,
default
=
'Linux'
,
verbose_name
=
_
(
'Platform'
))
domain
=
models
.
ForeignKey
(
"assets.Domain"
,
null
=
True
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
"Domain"
),
on_delete
=
models
.
SET_NULL
)
...
...
@@ -94,11 +89,8 @@ class Asset(OrgModelMixin):
null
=
True
,
verbose_name
=
_
(
"Admin user"
))
# Some information
public_ip
=
models
.
GenericIPAddressField
(
max_length
=
32
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Public IP'
))
number
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
public_ip
=
models
.
GenericIPAddressField
(
max_length
=
32
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Public IP'
))
number
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
# Collect
vendor
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
...
...
@@ -233,7 +225,7 @@ class Asset(OrgModelMixin):
return
data
class
Meta
:
unique_together
=
(
'
ip'
,
'port
'
)
unique_together
=
(
'
org'
,
'hostname
'
)
verbose_name
=
_
(
"Asset"
)
@
classmethod
...
...
apps/assets/models/node.py
浏览文件 @
3e17e942
...
...
@@ -7,7 +7,8 @@ from django.db.models import Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
orgs.mixins
import
OrgModelMixin
from
common.utils
import
with_cache
from
orgs.utils
import
get_current_org
,
set_current_org
from
orgs.models
import
Organization
__all__
=
[
'Node'
]
...
...
@@ -119,7 +120,11 @@ class Node(OrgModelMixin):
return
self
.
get_all_assets
().
valid
()
def
is_root
(
self
):
return
self
.
key
==
'0'
root
=
self
.
__class__
.
root
()
if
self
==
root
:
return
True
else
:
return
False
@
property
def
parent
(
self
):
...
...
@@ -148,8 +153,8 @@ class Node(OrgModelMixin):
def
get_ancestor
(
self
,
with_self
=
False
):
if
self
.
is_root
():
ancestor
=
self
.
__class__
.
objects
.
filter
(
key
=
'0'
)
return
ancestor
root
=
self
.
__class__
.
root
(
)
return
[
root
]
_key
=
self
.
key
.
split
(
':'
)
if
not
with_self
:
...
...
@@ -163,11 +168,26 @@ class Node(OrgModelMixin):
).
order_by
(
'key'
)
return
ancestor
@
classmethod
def
create_root_node
(
cls
):
with
transaction
.
atomic
():
org
=
get_current_org
()
set_current_org
(
Organization
.
root
())
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r
'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
max_value
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
if
org_nodes_roots_keys
else
0
set_current_org
(
org
)
root
=
cls
.
objects
.
create
(
key
=
max_value
+
1
,
value
=
org
.
name
)
return
root
@
classmethod
def
root
(
cls
):
obj
,
created
=
cls
.
objects
.
get_or_create
(
key
=
'0'
,
defaults
=
{
"key"
:
'0'
,
'value'
:
"ROOT"
}
)
print
(
obj
)
return
obj
root
=
cls
.
objects
.
filter
(
key__regex
=
r
'^[0-9]+$'
)
print
(
"GET ROOT NODE"
)
if
len
(
root
)
==
1
:
return
root
.
get
()
else
:
return
cls
.
create_root_node
()
apps/orgs/mixins.py
浏览文件 @
3e17e942
...
...
@@ -18,28 +18,17 @@ __all__ = [
class
OrgManager
(
models
.
Manager
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
print
(
"INit manager"
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
print
(
"GET CURR"
)
current_org
=
get_current_org
()
kwargs
=
{}
print
(
"Get queryset "
)
print
(
current_org
)
print
(
self
.
model
)
if
not
current_org
:
pass
kwargs
[
'id'
]
=
None
elif
current_org
.
is_real
():
kwargs
[
'org'
]
=
current_org
elif
current_org
.
is_default
():
kwargs
[
'org'
]
=
None
queryset
=
super
().
get_queryset
().
filter
(
**
kwargs
)
print
(
kwargs
)
print
(
queryset
)
return
queryset
def
all
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录