Пример #1
0
# coding=utf-8
import json
import tornado.web
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import dataverify, ComplexEncoder


TaskModel = QueryTable('task')
QuotasModel = QueryTable('quotas')
TaskKeyModel = QueryTable('task_key')
SchedulerModel = QueryTable('scheduler')

class TaskList(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        self.get_secure_cookie("username")
        data = yield TaskModel.select()
        data = json.dumps(data, ensure_ascii=False, cls=ComplexEncoder)
        return self.write(data)


class TaskKeyHandler(BaseHandler):
    """自动化扩缩容的关键指标"""

    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        self.get_secure_cookie("username")
Пример #2
0
# coding:utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

UserDepartmentModel = QueryTable('opman_user_department')
UserModel = QueryTable('opman_user')


class UserDepartmentMain(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        select = yield UserDepartmentModel.select()
        for group in select:
            id = group['id']
            usernames = yield UserModel.field('user_name').where(
                'user_depart=%s' % id).select()
            users = ""
            for username in usernames:
                username = username['user_name']
                users = users + username + ','
            group['members'] = users.strip(',')
        select = json.dumps(select, ensure_ascii=False, cls=ComplexEncoder)
        self.write(select)
        return
Пример #3
0
# coding:utf-8
from lib import BaseHandler
from tornado import gen
from lib.orm import QueryTable
from lib.decorators import Authenticate
from manager.libs import dataverify, ComplexEncoder

TaskFlowNodeInfo = QueryTable('opman_task_flow_nodeinfo')


class NodeStatusHandler(BaseHandler):
    @gen.coroutine
    @Authenticate
    def post(self, *args, **kwargs):
        # Node info task status ={0:sucess,1:fail,2:timeoute,3:running}
        task_id = self.get_argument('sid')
        node_ip = self.get_argument('nodeip')
        task_status = self.get_argument('status')
        data = yield TaskFlowNodeInfo.where('task_id=%s and ip="%s"' % (task_id,node_ip)).setfield('tstatus',task_status)
        message = dataverify(data, '节点任务状态修改成功', '节点任务修改失败')
        self.write(message)
        return

routes = [
    (r"/api/task/flow/node/status", NodeStatusHandler),
]
Пример #4
0
# coding:utf-8
import json
import tornado.web
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import dataverify


ProductModel = QueryTable('cmdb_product')
BusinessModel = QueryTable('opman_cmdb_business_line')

class MainHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        self.get_secure_cookie("username")
        if 'product' in self.request.arguments:
            select = yield ProductModel.select()
            data = json.dumps(select)
            self.write(data)
            return
        if 'business' in self.request.arguments:
            select = yield BusinessModel.table('cmdb_business').alias('b').join('cmdb_product p ON b.product_id = p.id').field('b.id,b.bus_name,b.bus_leader,p.name').select()
            data = json.dumps(select)
            self.write(data)
            return
        self.render('manager/cmdb/manager_cmdb.html')


class ProductHandler(BaseHandler):
Пример #5
0
    def __init__(self, func, args=()):
        super(MyThread, self).__init__()
        self.func = func
        self.args = args

    def run(self):
        self.result = self.func(*self.args)

    def get_result(self):
        try:
            return self.result
        except Exception:
            return None


CapacityTaskModel = QueryTable('capacity_task')


class CapacityTaskSetHandle(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        self.get_secure_cookie('username')
        data = yield CapacityTaskModel.select()
        data = json.dumps(data, ensure_ascii=False, cls=ComplexEncoder)
        if 'task' in self.request.arguments:
            self.write(data)
            return
        self.render('manager/capacity/setting.html')

    @tornado.web.authenticated
Пример #6
0
# coding:utf-8
import json
import tornado.web
from tornado import gen
from tornado import httpclient
from lib import BaseHandler
from manager.libs import dataverify, ComplexEncoder
from restapi.libs import baseurl, headers
from restapi.libs.AsyncDcp import update_service_jobs
from lib.orm import QueryTable

EmergencyTaskModel = QueryTable('expand_emergency_task')
EmergencyLogkModel = QueryTable('expand_emergency_logs')


class EmergentcyTaskSetHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        self.get_secure_cookie("username")
        data = yield EmergencyTaskModel.select()
        data = json.dumps(data, ensure_ascii=False, cls=ComplexEncoder)
        if 'task' in self.request.arguments:
            self.write(data)
            return
        self.render('manager/emergency/setting.html')

    @tornado.web.authenticated
    @gen.coroutine
    def post(self, *args, **kwargs):
        if 'create_poolname' in self.request.arguments:
Пример #7
0
import tornado.web
from tornado import gen
from manager.libs import dataverify
from lib import BaseHandler
from lib.orm import QueryTable
from tornadostreamform.multipart_streamer import MultiPartStreamer, StreamedPart, TemporaryFileStreamedPart

MB = 1024 * 1024
GB = 1024 * MB
TB = 1024 * GB

MAX_STREAMED_SIZE = 1 * GB
store_dir = '/data1/files'
store_tmp_dir = store_dir + '/tmp'

FileShareModel = QueryTable('opman_fileshare')

class MyStreamer(MultiPartStreamer):
    def create_part(self, headers):
        if not os.path.exists(store_tmp_dir):
            os.makedirs(store_tmp_dir)
        return TemporaryFileStreamedPart(self, headers, tmp_dir=store_tmp_dir)


@tornado.web.stream_request_body
class FileShareHandler(BaseHandler):

    @tornado.web.authenticated
    def get(self, *args, **kwargs):
        self.render('manager/fileshare/fileshare.html')
Пример #8
0
# coding=utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

TaskScriptsModel = QueryTable('opman_task_scripts')
TaskScriptsArgModel = QueryTable('opman_task_scripts_arg')


class MainHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        if 'get' in self.request.arguments:
            scripts = yield TaskScriptsModel.select()
            data = json.dumps(scripts, ensure_ascii=False, cls=ComplexEncoder)
            self.write(data)
            return
        self.render('manager/scripts/manager.html')


class SriptsHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def post(self, *args, **kwargs):
        param = tornado.escape.json_decode(self.request.body)
        param['username'] = self.get_secure_cookie("username").decode("utf-8")
Пример #9
0
# coding:utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

CronModel = QueryTable('opman_cmdb_cron')


class MainHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        if 'all' in self.request.arguments:
            crons = yield CronModel.select()
            data = json.dumps(crons, ensure_ascii=False, cls=ComplexEncoder)
            self.write(data)
            return
        self.render('manager/cmdb/crontab.html')


routes = [
    (r"/manager/cmdb/crontab.html", MainHandler),
]
Пример #10
0
# coding:utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

DepartmentPermissionModel = QueryTable('opman_depart_permission')


class DepartPermissionMain(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        if 'id' in self.request.arguments:
            id = self.get_argument('id')
            permissions = yield DepartmentPermissionModel.where(
                'depart_id=%s' % id).select()
            per_list = []
            for permission in permissions:
                per_list.append(permission['second_menu_id'])
            data = json.dumps(per_list, ensure_ascii=False, cls=ComplexEncoder)
            self.write(data)
            return

    @tornado.web.authenticated
    @gen.coroutine
    def post(self, *args, **kwargs):
        param = tornado.escape.json_decode(self.request.body)
Пример #11
0
# coding:utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import tokenlib
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

UserModel=QueryTable('opman_user')
UserGroupModel= QueryTable('user_group')


class HelpHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self, *args, **kwargs):
        self.render('help.html')


class MainHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self):
        self.render('manager/account/manager.html')


class UserMain(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
Пример #12
0
# coding:utf-8
import json
import tornado.web
import tornado.escape
from tornado import gen
from lib import BaseHandler
from lib.orm import QueryTable
from manager.libs import ComplexEncoder, dataverify

FirstMenuModel = QueryTable('opman_menu_first')
SecondMenuModel = QueryTable('opman_menu_second')
UserModel = QueryTable('opman_user')
DepartPerModel = QueryTable('opman_depart_permission')


class MenusHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, *args, **kwargs):
        if 'first' in self.request.arguments:
            first_menus = yield FirstMenuModel.select()
            data = json.dumps(first_menus,
                              ensure_ascii=False,
                              cls=ComplexEncoder)
            self.write(data)
            return
        if 'second' in self.request.arguments:
            second_menus = yield SecondMenuModel.table(
                'opman_menu_second').alias('s').join(
                    ('opman_menu_first f on s.father_menu = f.id',
                     'LEFT')).select()
Пример #13
0
# coding:utf-8
import json
import time
from tornado import gen
from lib import tokenlib
from lib import BaseHandler
from lib import ctime
from lib.orm import QueryTable
from lib.ldap import ldap_auth

UserModel = QueryTable('opman_user')


@gen.coroutine
def adduser(name, passwd):
    user = yield UserModel.where('user_name="%s"' % name).select()
    if not user:
        argument_data = {
            'user_name': name,
            'pwd': tokenlib.pass_crypt(passwd),
            'is_admin': 0,
            'last_login': ctime()
        }
        yield UserModel.add(argument_data)
    else:
        yield UserModel.where('user_name="%s"' % name).setfield(
            'last_login', ctime())


@gen.coroutine
def check(name, passwd):
Пример #14
0
# coding=utf-8
import json
import tornado.web
from tornado import gen
from lib import tokenlib
from lib import BaseHandler
from manager.libs import dataverify
from lib.orm import QueryTable

SessionModel = QueryTable('opman_token')


class TokenHandler(BaseHandler):
    """接口令牌管理"""
    @tornado.web.authenticated
    @gen.coroutine
    def get(self):
        self.get_secure_cookie("username")
        # if self.request.arguments.has_key('get'):
        if 'get' in self.request.arguments:
            select = yield SessionModel.select()
            data = json.dumps(select)
            self.write(data)
            return
        self.render('manager/token/manager_token.html')

    @tornado.web.authenticated
    @gen.coroutine
    def post(self):
        """新建令牌"""
        if self.get_argument('create_email'):
Пример #15
0
# coding=utf-8
import json
import tornado.web
from tornado import gen
from lib import BaseHandler
from manager.libs import ComplexEncoder
from lib.orm import QueryTable

LogDcpModel = QueryTable('logdcp')


class SchedulerLogHandler(BaseHandler):
    """接口调用日志统计"""
    @tornado.web.authenticated
    @gen.coroutine
    def get(self):
        self.get_secure_cookie("username")
        if 'task' in self.request.arguments:
            data = yield LogDcpModel.order('id desc').select()
            data = json.dumps(data, ensure_ascii=False, cls=ComplexEncoder)
            self.write(data)
            return
        self.render('manager/scheduler/log.html')


routes = [
    (r"/manager/log", SchedulerLogHandler),
]