import sys import os import traceback from multiprocessing.dummy import Pool as ThreadPool import requests import ujson as json from web.const import MAX_THREAD_NUM from web.const import REDIS_DB_PM, REDIS_DB_COMMON from libs import redisoj, log, utils, server, dnsapi from pm.libs import ilo_info, ilo_oper logger = log.get_logger("pm auto create") client = redisoj.generate(REDIS_DB_PM) client_user_data = redisoj.generate(REDIS_DB_COMMON) def multi(install_lists, task_id): client.hset(task_id, "install_lists", install_lists) pool = ThreadPool(MAX_THREAD_NUM) install_results = pool.map(single, install_lists) pool.close() pool.join() client.hset(task_id, "install_results", install_results) return install_results
#-*- coding: utf-8 -*- """ 生成一个全局递增 id. """ import redis from libs import redisoj from web.const import REDIS_DB_PM client = redisoj.generate(REDIS_DB_PM) def get(): """ 获取全局唯一 id. 能够保证 id 不重复. """ pipe = client.pipeline() while 1: try: pipe.watch('global_id') current_id = pipe.get('global_id') if current_id is None: next_id = 1 else:
# -*- coding: utf-8 -*- import sys import os import ujson as json import tornado.web from libs import decorator, ldapauth, redisoj, server from web.const import REDIS_DB_PM, PM_TASK_BASE_URL from pm.libs import global_id, check, create, create_man, tmessage redis_client_pm = redisoj.generate(REDIS_DB_PM) class CheckHandler(tornado.web.RequestHandler): @decorator.authenticate_decorator def post(self): """ 检查物理机是否可以正常装机. 检查项包括: 1). 是否可以根据 SN 获取到 ILO IP. 2). 是否能够 获取到 ILO 的密码. 3). 是否能够设置第二块网卡支持 PXE 启动. 4). 是否能够设置启动顺序. """ idc = _get_argument_json(self, "idc", False, loads=True)