[Update] 修改运行命令名称 (#2140)

pull/2142/head
老广 6 years ago committed by GitHub
parent 76aadad6fe
commit 31356e825f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2364,7 +2364,7 @@ msgstr "执行历史"
#: ops/templates/ops/adhoc_detail.html:72
#: ops/templates/ops/adhoc_detail.html:77 ops/templates/ops/task_adhoc.html:61
msgid "Run as"
msgstr "用户"
msgstr "运行用户"
#: ops/templates/ops/adhoc_detail.html:94 ops/templates/ops/task_list.html:36
msgid "Run times"

@ -159,7 +159,7 @@ class CommandResultCallback(AdHocResultCallback):
def v2_playbook_on_play_start(self, play):
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
msg = '$ {} ({})'.format('echo', now)
msg = '$ {} ({})'.format(play.name, now)
self._play = play
self._display.banner(msg)

@ -250,7 +250,5 @@ class CommandRunner(AdHocRunner):
tasks = [
{"action": {"module": module, "args": cmd}}
]
hosts = self.inventory.get_hosts(pattern=pattern)
name = "Run command {} on {}'s hosts".format(cmd, len(hosts))
return self.run(tasks, pattern, play_name=name)
return self.run(tasks, pattern, play_name=cmd)

@ -48,6 +48,9 @@ class CommandExecution(models.Model):
return False
return True
def get_hosts_names(self):
return ','.join(self.hosts.all().values_list('hostname', flat=True))
def run(self):
print('-'*10 + ' ' + ugettext('Task start') + ' ' + '-'*10)
self.date_start = timezone.now()

@ -44,6 +44,7 @@
<th class="text-center">{% trans 'Hosts' %}</th>
<th class="text-center">{% trans 'User' %}</th>
<th class="text-center">{% trans 'Command' %}</th>
<th class="text-center">{% trans 'Run as' %}</th>
<th class="text-center">{% trans 'Output' %}</th>
<th class="text-center">{% trans 'Finished' %}</th>
<th class="text-center">{% trans 'Success' %}</th>
@ -55,9 +56,10 @@
{% for object in object_list %}
<tr class="gradeX">
<td class="text-center"><input type="checkbox" class="cbx-term"></td>
<td class="text-center">{{ object.hosts.count }}</td>
<td class="text-center hosts">{{ object.get_hosts_names }}</td>
<td class="text-center">{{ object.user }}</td>
<td class="text-center">{{ object.command| truncatechars:16 }}</td>
<td class="text-center">{{ object.run_as }}</td>
<td class="text-center"><a href="{% url "ops:celery-task-log" pk=object.id %}" target="_blank">查看</a></td>
<td class="text-center">{{ object.is_finished | state_show | safe }}</td>
<td class="text-center">{{ object.is_success | state_show | safe }}</td>
@ -89,6 +91,17 @@ $(document).ready(function() {
calendarWeeks: true,
autoclose: true
});
$(".hosts").each(function (i) {
var data = $(this).text();
var data_list = data.split(",");
if (data_list.length === 1 && data_list[0] === "") {
data_list.pop();
}
var html = createPopover(data_list);
$(this).html(html);
});
$('[data-toggle="popover"]').popover();
})
</script>
{% endblock %}

Loading…
Cancel
Save