Fixes for make tasks
This commit is contained in:
parent
e2e9c80647
commit
ff93c78831
6 changed files with 376 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ from paramecio2.libraries.mtemplates import PTemplate, env_theme
|
|||
from paramecio2.libraries import datetime
|
||||
from paramecio2.libraries.urls import make_media_url
|
||||
from modules.monit.models.monit import Server, ServerData, Alerts
|
||||
from modules.pastafari2.libraries.scandir import scandir
|
||||
from paramecio2.libraries.db.webmodel import WebModel
|
||||
from paramecio2.libraries.lists import AjaxList
|
||||
from paramecio2.libraries.db.extraforms.fileform import FileForm
|
||||
|
|
@ -20,6 +21,10 @@ from pathlib import Path
|
|||
import paramiko
|
||||
import socket
|
||||
import os
|
||||
import configparser
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module, reload
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except:
|
||||
|
|
@ -35,10 +40,28 @@ t.env.directories.insert(1, os.path.dirname(__file__).replace('/admin', '')+'/te
|
|||
|
||||
system_path='./ssh/'
|
||||
|
||||
base_path='modules/pastafari2/tasks'
|
||||
|
||||
if hasattr(config, 'pastafari_base_path'):
|
||||
base_path=config.pastafari_base_path
|
||||
|
||||
pastafari_paths=[]
|
||||
|
||||
if hasattr(config, 'pastafari_paths'):
|
||||
pastafari_paths=config.pastafari_paths
|
||||
|
||||
@admin_app.route('/pastafari2/dashboard/')
|
||||
def pastafari2_dashboard():
|
||||
|
||||
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard'), path_module='admin_app.pastafari2_dashboard')
|
||||
config_parser=configparser.ConfigParser()
|
||||
|
||||
select_task=scandir(base_path, config_parser, OrderedDict(), 'tasks')
|
||||
|
||||
for module in pastafari_paths:
|
||||
|
||||
select_task=scandir(module, config_parser, select_task, 'tasks')
|
||||
|
||||
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard'), path_module='admin_app.pastafari2_dashboard', select_task=select_task)
|
||||
|
||||
@admin_app.route('/pastafari2/settings/')
|
||||
def pastafari2_settings():
|
||||
|
|
@ -472,7 +495,77 @@ def pastafari2_update_task():
|
|||
|
||||
return {'error': error, 'txt_error': txt_error, 'error_form': error_form, 'task_id': task_id}
|
||||
|
||||
return {}
|
||||
@admin_app.route('/pastafari2/make_task/', methods=['POST'])
|
||||
def pastafari2_make_task():
|
||||
|
||||
db=g.connection
|
||||
|
||||
ids=json.loads(request.form.get('ids', '[]'))
|
||||
arr_ids=[]
|
||||
|
||||
task_file=request.form.get('task', '')
|
||||
|
||||
task_file=task_file.replace('/', '.')
|
||||
|
||||
task_file=task_file.replace('.py', '')
|
||||
|
||||
task_execute=import_module(task_file)
|
||||
|
||||
task_first=task_execute.ServerTask('', db, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={'mysql_password': ''})
|
||||
|
||||
if config.reloader:
|
||||
reload(task_execute)
|
||||
|
||||
send_task=request.args.get('send_task', '')
|
||||
|
||||
#if not os.path.isfile(task)
|
||||
|
||||
if send_task=='':
|
||||
|
||||
#Check if form
|
||||
|
||||
if hasattr(task_first, 'form'):
|
||||
|
||||
url_exec=url_for('.pastafari2_make_task', ids=ids, task_file=task_file, send_task=1)
|
||||
|
||||
return t.load_template('maketask.phtml', form=task_first.form(t, yes_error=False, pass_values=False), url_exec=url_exec)
|
||||
|
||||
error=0
|
||||
txt_error=''
|
||||
error_form={}
|
||||
|
||||
#print(ids)
|
||||
for v in ids:
|
||||
arr_ids.append(str(int(v)))
|
||||
|
||||
where_sql='WHERE id IN ('+",".join(arr_ids)+') order by hostname ASC'
|
||||
|
||||
#print(where_sql)
|
||||
|
||||
task=Task(db)
|
||||
|
||||
task_id=0
|
||||
|
||||
path_task='modules.pastafari2.tasks.system.updates'
|
||||
|
||||
#Load task, check if have question
|
||||
|
||||
data={}
|
||||
|
||||
server_host=''
|
||||
|
||||
user=config_task.remote_user
|
||||
|
||||
ssh_key_priv='./ssh/id_rsa'
|
||||
"""
|
||||
if not task.run_task(server_host, path_task, 'Update server', 'update_server', 'Task for update servers', user=user, password='', where_sql_server=where_sql, ssh_key_priv=ssh_key_priv, url='', data=data, send_task=True):
|
||||
|
||||
error=1
|
||||
error_form['#server_host_error']=I18n.lang('pastafari2', 'error_exec_task', 'Error: cannot execute the task')
|
||||
|
||||
task_id=task.task_id
|
||||
"""
|
||||
return {'error': error, 'txt_error': txt_error, 'error_form': error_form, 'task_id': task_id}
|
||||
|
||||
@admin_app.route('/pastafari2/multiprogress/')
|
||||
def pastafari2_multiprogress():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue