コード例 #1
0
ファイル: job.py プロジェクト: big-max/python
 def post(self):
     proj_log.log().debug('JobHandler::post 收到数据' + self.request.body)
     body = json.loads(self.request.body)
     if body['operType'] == 'createJob':
         self.createJob(body)
     if body['operType'] == 'deleteJob':
         self.deleteJob(body)
コード例 #2
0
ファイル: logCatch.py プロジェクト: big-max/python
 def post(self):
     proj_log.log().info(self.request.body)
     body = json.loads(self.request.body)
     if body.has_key('operType') and body['operType'] == 'deleteLog':
         self.deleteLog(body)
     else:
         self.addLog(body)
コード例 #3
0
def getOSInfo(ip):
    try:
        ansible_param = '/usr/bin/ansible ' + ip + ' -i ' + ip + ', -m setup'
        retVal = subprocess.check_output([ansible_param], shell=True)
        log().info('receive getOSInfo::' + str(retVal))
        first = retVal.index('{')
        last = retVal.rindex('}')
        ansi_obj = json.loads(retVal[first:last + 1])
        if ansi_obj['ansible_facts']['ansible_distribution'] == 'AIX':
            name = ansi_obj['ansible_facts']['ansible_nodename']
            hconf=str(ansi_obj['ansible_facts']['ansible_processor_cores'])+'C/'+\
            str(ansi_obj['ansible_facts']['ansible_memtotal_mb'])+'MB'
            os=ansi_obj['ansible_facts']['ansible_distribution']+' '+ansi_obj['ansible_facts']['ansible_distribution_version']\
            +'.'+ansi_obj['ansible_facts']['ansible_distribution_release']
            hvisor = ansi_obj['ansible_facts']['ansible_processor']
        elif ansi_obj['ansible_facts']['ansible_distribution'] == 'HP-UX':
            name = ansi_obj['ansible_facts']['ansible_nodename']
            hvisor = ansi_obj['ansible_facts']['ansible_virtualization_type']
            os=ansi_obj['ansible_facts']['ansible_distribution']+' '+ansi_obj['ansible_facts']['ansible_distribution_version']\
            +'.'+ansi_obj['ansible_facts']['ansible_distribution_release']
            hconf=str(ansi_obj['ansible_facts']['ansible_processor_count'])+'C/'+\
            str(ansi_obj['ansible_facts']['ansible_memtotal_mb'])+'MB'
        else:
            name = ansi_obj['ansible_facts']['ansible_nodename']
            hvisor = ansi_obj['ansible_facts']['ansible_virtualization_type']
            os = ansi_obj['ansible_facts'][
                'ansible_distribution'] + ' ' + ansi_obj['ansible_facts'][
                    'ansible_distribution_version']
            hconf=str(ansi_obj['ansible_facts']['ansible_processor_cores'])+'C/'+\
            str(ansi_obj['ansible_facts']['ansible_memtotal_mb'])+'MB'
        return {'name': name, 'hvisor': hvisor, 'os': os, 'hconf': hconf}
    except Exception, e:
        print str(e)
        return 'notalive'
コード例 #4
0
ファイル: compareConf.py プロジェクト: big-max/python
    def post(self):
        proj_log.log().info('compareconfHandler: ' + self.request.body)
        body = json.loads(self.request.body)
        srcIP = body['srcIP']
        srcProduct = body['srcProduct']
        srcDatetime = body['srcDatetime']
        srcInstance = body['srcInstance']
        srcDB = body['srcDB']
        targetIP = body['targetIP']
        targetProduct = body['targetProduct']
        targetDatetime = body['targetDatetime']
        targetInstance = body['targetInstance']
        targetDB = body['targetDB']
        srcOut = self.createFinalJson(srcIP, srcProduct, srcDatetime,
                                      srcInstance, srcDB)
        targetOut = self.createFinalJson(targetIP, targetProduct,
                                         targetDatetime, targetInstance,
                                         targetDB)
        #srcOut.append(targetOut[0])  # 这里targetOut永远只有一个元素 可以用下标0
        for item in targetOut:
            srcOut.append(item)

        final = json.dumps(srcOut)
        proj_log.log().info(final)
        if final:
            self.write({'status': 1, 'msg': final})
        else:
            self.write({'status': 0, 'msg': 'error'})
        self.finish()
コード例 #5
0
def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    #http_server.bind(options.port)
    #http_server.start(num_processes=cpu_count())
    log().info('the server is running at http://127.0.0.1:%s/' % options.port)
    log().info('quit the server with Control-C')
    tornado.ioloop.IOLoop.instance().start()
コード例 #6
0
def addsshcredits(ip, user, passwd):
    ping_param = 'ping ' + ip + ' -c 1 -w 1'
    retVal = subprocess.call([ping_param], shell=True)
    if retVal == 1:
        return 'networkerror'

    ansible_os_param = "/usr/bin/ansible " + ip + " -i " + ip + ", -m 'command' -a 'uname' -e 'ansible_user="******" ansible_ssh_pass="******"'"
    log().info('get OS Info::' + ansible_os_param)
    try:
        retVal = subprocess.check_output([ansible_os_param], shell=True)
    except CalledProcessError, mimaerror:
        log().info('get OS error::' + str(mimaerror))
        return 'passerror'
コード例 #7
0
def configCompare_run_playbook(job_uuid, jobDetail_uuid, jobTarget, ymlName,
                               task_timestamp, job_if_daily, job_scheduled_at,
                               userName):
    sendCommand='/usr/bin/ansible-playbook ' + getProjPath()+'/playbooks/configcompare/'\
    +ymlName+".yml -i "+jobTarget + "  -e 'task_timestamp="+task_timestamp+" confCompDetail_uuid="+jobDetail_uuid+" confComp_uuid="+job_uuid+" ymlName="+ymlName+" confCompDetail_if_daily="+job_if_daily+"'"
    log().info(sendCommand)
    if job_if_daily == '0':  #run immediately
        retVal = subprocess.call([sendCommand], shell=True)
    elif job_if_daily == '2':  #run every day
        cron = CronTab(user=userName)
        job = cron.new(sendCommand)
        job.setall(
            job_scheduled_at.split(':')[1],
            job_scheduled_at.split(':')[0], '*', '*', '*')
        cron.write(user=userName)
コード例 #8
0
def healthCheck_run_playbook(job_uuid, jobDetail_uuid, jobTarget, ymlName,
                             task_timestamp, job_if_daily, job_scheduled_at,
                             userName):
    sendCommand='/usr/bin/ansible-playbook ' + getProjPath()+'/playbooks/healthcheck/'\
    +ymlName+".yml -i "+jobTarget + "  -e 'task_timestamp="+task_timestamp+" jobDetail_uuid="+jobDetail_uuid+" job_uuid="+job_uuid+" ymlName="+ymlName+" job_if_daily="+job_if_daily+"'"
    log().info(sendCommand)
    if job_if_daily == '0' or job_if_daily == '1':  #run immediately
        retVal = subprocess.call([sendCommand], shell=True)
    elif job_if_daily == '2':  #run every day
        #cron = CronTab(user='******')
        cron = CronTab(user=userName)
        job = cron.new(sendCommand)
        job.setall(
            job_scheduled_at.split(':')[1],
            job_scheduled_at.split(':')[0], '*', '*', '*')
        cron.write(user=userName)
        log().info('healthCheck::crotab has written to crontab file.')
コード例 #9
0
ファイル: logCatch.py プロジェクト: big-max/python
 def addLog(self, body):
     proj_log.log().info(self.request.body)
     body = json.loads(self.request.body)
     ip = body['ip']
     product = body['product']
     version = body['version']
     task_timestamp = body['task_timestamp']
     instance = body['instance']
     job = {}
     job['ip'] = ip
     job['product'] = product
     job['version'] = version
     job['task_timestamp'] = task_timestamp
     job['instance'] = instance
     uuid1 = str(uuid.uuid1())
     job['_id'] = uuid1
     mongoOps.db().logCatch.insert(job)
     tasks.logCatch_run_playbook.apply_async(
         args=[uuid1, ip, product, instance, task_timestamp],
         queue='queue_logCatch_run_playbook')
     self.write({'status': 1, 'msg': 'success'})
     self.finish()
コード例 #10
0
ファイル: configJobDetail.py プロジェクト: big-max/python
 def post(self):
     proj_log.log().debug('configJobDetailHandler::post 收到数据'+self.request.body)
     body = json.loads(self.request.body)
     self.getJobDetailList(body['confComp_uuid'])
コード例 #11
0
def ws_receive_status(ws):
    result = ws.recv()
    log().info('get server status receive data' + str(result))
コード例 #12
0
def logCatch_run_playbook(_id, ip, product, instance, task_timestamp):
    sendCommand ='/usr/bin/ansible-playbook ' + getProjPath() +'/playbooks/logcatch/'\
    + product +"log.yml -i " + ip + ",  -e 'target="+ instance+" task_timestamp="+task_timestamp+" _id="+_id+" product="+product+" ip="+ip+"'"
    log().info(sendCommand)
    retVal = subprocess.call([sendCommand], shell=True)
コード例 #13
0
def deploy_run_playbook(ymlName, jsonPath):
    sendCommand = '/usr/bin/ansible-playbook ' + getProjPath(
    ) + '/playbooks/deploy/' + ymlName + '.yml -e @' + jsonPath
    log().info(sendCommand)
    time.sleep(3)
    retVal = subprocess.call([sendCommand], shell=True)
コード例 #14
0
        return 'passerror'
    baseDir = ''
    osType = retVal.split('>>')[1].strip()
    ansible_param = ''
    if user == 'root':
        if osType.lower() == 'linux':
            baseDir = '/root/'
        elif osType.lower() == 'aix':
            baseDir = '/'
        ansible_param = "/usr/bin/ansible " + ip + " -i " + ip + ", -m authorized_key -a 'user="******" key={{ lookup(\"file\",\"/root/.ssh/id_rsa.pub\") }} path='" + baseDir + ".ssh/authorized_keys''  -e 'ansible_user="******" ansible_ssh_pass="******"'"
    else:
        baseDir = '/home/' + user + '/'
        ansible_param = "/usr/bin/ansible " + ip + " -i " + ip + ", -m authorized_key -a 'user="******" key={{ lookup(\"file\",\"" + str(
            baseDir
        ) + ".ssh/id_rsa.pub\") }} path='" + baseDir + ".ssh/authorized_keys''  -e 'ansible_user="******" ansible_ssh_pass="******"'"
    log().info(ansible_param)
    try:
        retVal = subprocess.call([ansible_param], shell=True)
    except Exception as e:
        log().info('add ssh key error,the error is' + str(e))
        return 'fail'
    if retVal == 0:
        return 'success'
    else:
        return 'fail'


@app.task
def updateServerInfo(servers, operation):
    ws = None
    ip = get_conf('websocket', 'host')