Commit 24c4e1df authored by ibuler's avatar ibuler

[Update] 资产,系统用户,管理用户等支持查看日志

parent d247e49b
...@@ -79,5 +79,5 @@ class AdminUserTestConnectiveApi(generics.RetrieveAPIView): ...@@ -79,5 +79,5 @@ class AdminUserTestConnectiveApi(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
admin_user = self.get_object() admin_user = self.get_object()
test_admin_user_connectability_manual.delay(admin_user) task = test_admin_user_connectability_manual.delay(admin_user)
return Response({"msg": "Task created"}) return Response({"task": task.id})
\ No newline at end of file
...@@ -87,12 +87,8 @@ class AssetRefreshHardwareApi(generics.RetrieveAPIView): ...@@ -87,12 +87,8 @@ class AssetRefreshHardwareApi(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
asset_id = kwargs.get('pk') asset_id = kwargs.get('pk')
asset = get_object_or_404(Asset, pk=asset_id) asset = get_object_or_404(Asset, pk=asset_id)
summary = update_asset_hardware_info_manual(asset)[1] task = update_asset_hardware_info_manual.delay(asset)
logger.debug("Refresh summary: {}".format(summary)) return Response({"task": task.id})
if summary.get('dark'):
return Response(summary['dark'].values(), status=501)
else:
return Response({"msg": "ok"})
class AssetAdminUserTestApi(generics.RetrieveAPIView): class AssetAdminUserTestApi(generics.RetrieveAPIView):
...@@ -105,8 +101,5 @@ class AssetAdminUserTestApi(generics.RetrieveAPIView): ...@@ -105,8 +101,5 @@ class AssetAdminUserTestApi(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
asset_id = kwargs.get('pk') asset_id = kwargs.get('pk')
asset = get_object_or_404(Asset, pk=asset_id) asset = get_object_or_404(Asset, pk=asset_id)
ok, msg = test_asset_connectability_manual(asset) task = test_asset_connectability_manual.delay(asset)
if ok: return Response({"task": task.id})
return Response({"msg": "pong"})
else:
return Response({"error": msg}, status=502)
\ No newline at end of file
...@@ -130,10 +130,9 @@ class RefreshNodeHardwareInfoApi(APIView): ...@@ -130,10 +130,9 @@ class RefreshNodeHardwareInfoApi(APIView):
node_id = kwargs.get('pk') node_id = kwargs.get('pk')
node = get_object_or_404(self.model, id=node_id) node = get_object_or_404(self.model, id=node_id)
assets = node.assets.all() assets = node.assets.all()
# task_name = _("Refresh node assets hardware info: {}".format(node.name))
task_name = _("更新节点资产硬件信息: {}".format(node.name)) task_name = _("更新节点资产硬件信息: {}".format(node.name))
update_assets_hardware_info_util.delay(assets, task_name=task_name) task = update_assets_hardware_info_util.delay(assets, task_name=task_name)
return Response({"msg": "Task created"}) return Response({"task": task.id})
class TestNodeConnectiveApi(APIView): class TestNodeConnectiveApi(APIView):
...@@ -145,6 +144,6 @@ class TestNodeConnectiveApi(APIView): ...@@ -145,6 +144,6 @@ class TestNodeConnectiveApi(APIView):
node = get_object_or_404(self.model, id=node_id) node = get_object_or_404(self.model, id=node_id)
assets = node.assets.all() assets = node.assets.all()
task_name = _("测试节点下资产是否可连接: {}".format(node.name)) task_name = _("测试节点下资产是否可连接: {}".format(node.name))
test_asset_connectability_util.delay(assets, task_name=task_name) task = test_asset_connectability_util.delay(assets, task_name=task_name)
return Response({"msg": "Task created"}) return Response({"task": task.id})
...@@ -58,8 +58,8 @@ class SystemUserPushApi(generics.RetrieveAPIView): ...@@ -58,8 +58,8 @@ class SystemUserPushApi(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
system_user = self.get_object() system_user = self.get_object()
push_system_user_to_assets_manual.delay(system_user) task = push_system_user_to_assets_manual.delay(system_user)
return Response({"msg": "Task created"}) return Response({"task": task.id})
class SystemUserTestConnectiveApi(generics.RetrieveAPIView): class SystemUserTestConnectiveApi(generics.RetrieveAPIView):
...@@ -71,5 +71,5 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView): ...@@ -71,5 +71,5 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
system_user = self.get_object() system_user = self.get_object()
test_system_user_connectability_manual.delay(system_user) task = test_system_user_connectability_manual.delay(system_user)
return Response({"msg": "Task created"}) return Response({"task": task.id})
\ No newline at end of file
...@@ -215,7 +215,7 @@ def test_admin_user_connectability_period(): ...@@ -215,7 +215,7 @@ def test_admin_user_connectability_period():
def test_admin_user_connectability_manual(admin_user): def test_admin_user_connectability_manual(admin_user):
# task_name = _("Test admin user connectability: {}").format(admin_user.name) # task_name = _("Test admin user connectability: {}").format(admin_user.name)
task_name = _("测试管理行号可连接性: {}").format(admin_user.name) task_name = _("测试管理行号可连接性: {}").format(admin_user.name)
return test_admin_user_connectability_util.delay(admin_user, task_name) return test_admin_user_connectability_util(admin_user, task_name)
@shared_task @shared_task
...@@ -395,11 +395,12 @@ def get_node_push_system_user_task_name(system_user, node): ...@@ -395,11 +395,12 @@ def get_node_push_system_user_task_name(system_user, node):
) )
@shared_task
def push_system_user_to_node(system_user, node): def push_system_user_to_node(system_user, node):
logger.info("Start push system user node: {} => {}".format(system_user.name, node.value)) logger.info("Start push system user node: {} => {}".format(system_user.name, node.value))
assets = node.get_all_assets() assets = node.get_all_assets()
task_name = get_node_push_system_user_task_name(system_user, node) task_name = get_node_push_system_user_task_name(system_user, node)
push_system_user_util.delay([system_user], assets, task_name) push_system_user_util([system_user], assets, task_name)
@shared_task @shared_task
......
...@@ -121,14 +121,16 @@ $(document).ready(function () { ...@@ -121,14 +121,16 @@ $(document).ready(function () {
}) })
.on('click', '.btn-test-connective', function () { .on('click', '.btn-test-connective', function () {
var the_url = "{% url 'api-assets:admin-user-connective' pk=admin_user.id %}"; var the_url = "{% url 'api-assets:admin-user-connective' pk=admin_user.id %}";
var error = function (data) { var success = function (data) {
alert(data) var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
}; };
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
error: error,
method: 'GET', method: 'GET',
success_message: "{% trans 'Task has been send, seen left asset status' %}" success: success,
flash_message: false
}); });
}) })
</script> </script>
......
...@@ -269,16 +269,15 @@ function updateAssetNodes(nodes) { ...@@ -269,16 +269,15 @@ function updateAssetNodes(nodes) {
function refreshAssetHardware() { function refreshAssetHardware() {
var the_url = "{% url 'api-assets:asset-refresh' pk=asset.id %}"; var the_url = "{% url 'api-assets:asset-refresh' pk=asset.id %}";
var success = function (data) { var success = function(data) {
location.reload(); console.log(data);
}; var task_id = data.task;
var error = function (data) { var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
alert(data) window.open(url, '', 'width=800,height=600')
}; };
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
success: success, success: success,
error: error,
method: 'GET' method: 'GET'
}); });
} }
...@@ -344,19 +343,20 @@ $(document).ready(function () { ...@@ -344,19 +343,20 @@ $(document).ready(function () {
var redirect_url = "{% url 'assets:asset-list' %}"; var redirect_url = "{% url 'assets:asset-list' %}";
objectDelete($this, name, the_url, redirect_url); objectDelete($this, name, the_url, redirect_url);
}).on('click', '#btn_refresh_asset', function () { }).on('click', '#btn_refresh_asset', function () {
alert('关闭alert, 等待完成, 自动刷新页面');
refreshAssetHardware() refreshAssetHardware()
}).on('click', '#btn-test-is-alive', function () { }).on('click', '#btn-test-is-alive', function () {
var the_url = "{% url 'api-assets:asset-alive-test' pk=asset.id %}"; var the_url = "{% url 'api-assets:asset-alive-test' pk=asset.id %}";
var error = function (data) {
alert(data) var success = function(data) {
var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
}; };
alert('关闭alert, 等待完成');
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
error: error,
method: 'GET', method: 'GET',
success_message: "{% trans "Reachable" %}" success: success
}); });
}) })
......
...@@ -497,14 +497,17 @@ $(document).ready(function(){ ...@@ -497,14 +497,17 @@ $(document).ready(function(){
} }
var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id); var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id);
function success() { function success(data) {
rMenu.css({"visibility" : "hidden"}); rMenu.css({"visibility" : "hidden"});
var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
} }
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
method: "GET", method: "GET",
success_message: "更新硬件信息任务下发成功", success: success,
success: success flash_message: false
}); });
}) })
...@@ -519,14 +522,17 @@ $(document).ready(function(){ ...@@ -519,14 +522,17 @@ $(document).ready(function(){
} }
var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id); var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id);
function success() { function success(data) {
rMenu.css({"visibility" : "hidden"}); rMenu.css({"visibility" : "hidden"});
var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
} }
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
method: "GET", method: "GET",
success_message: "测试可连接性任务下发成功", success: success,
success: success flash_message: false
}); });
}) })
.on('click', '.btn_asset_delete', function () { .on('click', '.btn_asset_delete', function () {
......
...@@ -293,26 +293,30 @@ $(document).ready(function () { ...@@ -293,26 +293,30 @@ $(document).ready(function () {
}) })
.on('click', '.btn-push', function () { .on('click', '.btn-push', function () {
var the_url = "{% url 'api-assets:system-user-push' pk=system_user.id %}"; var the_url = "{% url 'api-assets:system-user-push' pk=system_user.id %}";
var error = function (data) { var success = function (data) {
alert(data) var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
}; };
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
error: error,
method: 'GET', method: 'GET',
success_message: "{% trans "Task has been send, Go to ops task list seen result" %}" success: success,
flash_message: false
}); });
}) })
.on('click', '.btn-test-connective', function () { .on('click', '.btn-test-connective', function () {
var the_url = "{% url 'api-assets:system-user-connective' pk=system_user.id %}"; var the_url = "{% url 'api-assets:system-user-connective' pk=system_user.id %}";
var error = function (data) { var success = function (data) {
alert(data) var task_id = data.task;
var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id);
window.open(url, '', 'width=800,height=600')
}; };
APIUpdateAttr({ APIUpdateAttr({
url: the_url, url: the_url,
error: error,
method: 'GET', method: 'GET',
success_message: "{% trans "Task has been send, seen left assets status" %}" success: success,
flash_message: false
}); });
}) })
</script> </script>
......
{% extends '_base_list.html' %} {% extends '_base_list.html' %}
{% load i18n %} {% load i18n %}
{% load static %} {% load static %}
{% block content_left_head %} {% block content_left_head %}
<link href="{% static 'css/plugins/datepicker/datepicker3.css' %}" rel="stylesheet"> <div class="uc pull-left m-r-5"><a class="btn btn-sm btn-primary btn-create-asset"> {% trans "Create task" %} </a></div>
{% endblock %} {% endblock %}
......
...@@ -157,7 +157,7 @@ function APIUpdateAttr(props) { ...@@ -157,7 +157,7 @@ function APIUpdateAttr(props) {
props = props || {}; props = props || {};
var success_message = props.success_message || '更新成功!'; var success_message = props.success_message || '更新成功!';
var fail_message = props.fail_message || '更新时发生未知错误.'; var fail_message = props.fail_message || '更新时发生未知错误.';
var flash_message = true; var flash_message = props.flash_message || true;
if (props.flash_message === false){ if (props.flash_message === false){
flash_message = false; flash_message = false;
} }
...@@ -170,7 +170,9 @@ function APIUpdateAttr(props) { ...@@ -170,7 +170,9 @@ function APIUpdateAttr(props) {
dataType: props.data_type || "json" dataType: props.data_type || "json"
}).done(function(data, textStatue, jqXHR) { }).done(function(data, textStatue, jqXHR) {
if (flash_message) { if (flash_message) {
toastr.success(success_message); if (send_message) {
toastr.success(success_message);
}
} }
if (typeof props.success === 'function') { if (typeof props.success === 'function') {
return props.success(data); return props.success(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment