예제 #1
0
def upload_conf(para):
    logging.info('begin to upload conf files ...')
    work_dir = REMOTE_DIR+'/smartlog_install'
    for item in para:
        remote_path = work_dir+'/'+'single_conf.json'
        single_json = os.path.join(CURRENT_DIR,item['server']['host'].split('@')[1]+'.json')
        file_put_contents(single_json,json.dumps(item['config']))
        tools.remote_up_file([item['server']],single_json,remote_path)

    logging.info('upload conf files done ...')
예제 #2
0
def upload_packages(hosts):
    logging.info('begin to upload files ...')
    cmd = 'mkdir -p /home/ultrapower/upload && chmod 755 /home/ultrapower -R'
    tools.remote_cmd(hosts,cmd)

    local_path = os.path.join(CURRENT_DIR,'smartlog_install.tar.gz')
    remote_path = REMOTE_DIR+'/smartlog_install.tar.gz'
    tools.remote_up_file(hosts,local_path,remote_path)
    cmd = 'cd %s && tar xzf smartlog_install.tar.gz '%REMOTE_DIR
    tools.remote_cmd(hosts,cmd)
    logging.info('upload packages done ...')
예제 #3
0
def get_component_status(parameters):
    host_list = []
    upload_path = os.path.normpath(HOME_DIR + r'/upload/')
    local_status_path = os.path.normpath(CURRENT_DIR + r'/status.json')
    local_py_path = os.path.normpath(CURRENT_DIR + r'/getServerStatus.py')
    dst_path  = '/home/test/smartStatus'
    if not os.path.exists(dst_path):
        cmd = 'mkdir -p %s' % dst_path
        os.system(cmd)

    for item in parameters:
        tmpDict = {}
        tmpDict['host'] = item['host']
        tmpDict['password'] = item['password']
        host_list.append(tmpDict)
        del item['password']
        fp = open(local_status_path,'w')
        fp.write(json.dumps(item))
        fp.close()
        tools.remote_singe_upload(tmpDict,local_status_path,upload_path)
    tools.remote_up_file(host_list,local_py_path,upload_path)
    cmd_status = 'cd %s && python getServerStatus.py "%s"' % (upload_path,os.path.normpath(upload_path + r'/status.json'))
    tools.remote_cmd(host_list,cmd_status)
    logging.info('start get status file from yuanchengfuwuqi !!!!')
    for item in host_list:
        src_path = r'/home/ultrapower/upload/status_%s' % item['host'].split('@')[1]
        logging.info(tools.remote_single_download(item,src_path,dst_path))

    logging.info('end get status file from yuanchengfuwuqi !!!!')

    result_list = getStatusFromFile(dst_path)
    for item in result_list:
        item_list = []
        for each in item['components']:
            each_dict = {}
            if not each['install_status']:
                each_dict['status'] = -1
                each_dict['current_status'] = each['current_status']
            if each['install_status'] and not each['current_status'] and each['process_status']:
                each_dict['status'] = 0
                each_dict['current_status'] = False
            if each['install_status'] and not each['current_status'] and not each['process_status']:
                each_dict['status'] = 1
                each_dict['current_status'] = False
            each_dict['log'] = each['log']
            each_dict['host'] = each['host']
            item_list.append(each_dict)
        item['components'] = item_list

    logging.info('end getStatusFromFile : %s' % str(result_list))

    for item in result_list:
        sum_status_zero = 0
        sum_current = 0
        length = len(item['components'])
        for each in item['components']:
            if each['status'] == 0:
                sum_status_zero += 1
            if each['status'] == -1:
                item['status'] = -1
                item['current_status'] = True
            if each['status'] == 1:
                item['status'] = 1
                item['current_status'] = False
            if not each['current_status']:
                sum_current += 1
            if sum_status_zero == length and sum_current == length:
                item['status'] = 0
                item['current_status'] = False

    for item in result_list:
        if numDict[item['name']]:
            item['index'] = numDict[item['name']]
            item['showname'] = nameDict[item['name']]

    return result_list