Esempio n. 1
0
def unarchive_module(ip, src, dest):
    """[Using ansible.sh unarchive_module, compress files to the corresponding server and extract it]
    
    Arguments:
        ip {[string]} -- [corresponding server host ip]
        src {[string]} -- [files dir path]
        dest {[string]} -- [corresponding server dir path]
    
    Returns:
        [bool] -- [true or false]
    """


    (status, result) = utils.getstatusoutput('bash ' + path.get_path() +
                                                '/scripts/ansible.sh unarchive ' + ip + ' ' + src + ' ' + dest)
    logger.debug('unarchive action , status %s, output %s' % (status, result))
   
    if status:
        logger.warn('unarchive action failed, status %s' % (status))
        consoler.warn(' ansible unarchive  failed, host is %s, src is %s, dst is %s, status is %s, output is %s.', ip, src, dest, status, result)
    elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1:
        logger.warn('unarchive action failed, output %s' % (result))
        consoler.warn(' ansible unarchive failed, host is %s, src is %s, dst is %s, status is %s, output is %s.', ip, src, dest, status, result)
    else:
        consoler.info(' ansible unarchive success, host is %s, src is %s, dst is %s.', ip, src, dest)
        return True
    return False
Esempio n. 2
0
def copy_module(ip, src, dest):
    """[Using ansible.sh copy_module, push package to servers]
    
    Arguments:
        ip {string} -- corresponding server host ip
        src {string} -- files which push
        dest {string} -- corresponding server dir path

    Returns:
        bool -- true or false.
    """

    (status, result) = utils.getstatusoutput('bash ' + path.get_path() +
                                                '/scripts/ansible.sh copy ' + ip + ' ' + src + ' ' + dest)
    logger.debug('copy action , status %s, output %s' % (status, result))
   
    if status:
        logger.warn('copy action failed, status %s' % (status))
        consoler.warn(' ansible copy failed, host is %s, src is %s, dst is %s, status is %s, output is %s.', ip, src, dest, status, result)
    elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1:
        consoler.warn(' ansible copy failed, host is %s, src is %s, dst is %s, status is %s, output is %s.', ip, src, dest, status, result)
        logger.warn('copy action failed, output %s' % (result))
    else:
        consoler.info(' ansible copy success, host is %s, src is %s, dst is %s.', ip, src, dest)
        return True
    return False
Esempio n. 3
0
def check_module(ip, dest):
    """Using ansible.sh check_module, check chain status
    
    Arguments:
        ip {string} -- corresponding server host ip
        dest {string} -- corresponding server dir path
    
    Returns:
        bool -- true or false
    """

    (status, result) = utils.getstatusoutput('bash ' + path.get_path() +
                                                '/scripts/ansible.sh check ' + ip + ' ' + dest)
    logger.debug('check action , status %s, output %s' % (status, result))
    
    if status:
        logger.warn('check action failed, status %s' % (status))
        consoler.warn(' ansible check failed, host is %s, dst is %s, status is %s, output is %s.', ip, dest, status, result)
    elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1:
        logger.warn('check action failed, output %s' % (result))
        consoler.warn(' ansible check failed, host is %s, dst is %s, status is %s, output is %s.', ip, dest, status, result)
    else:
        consoler.info(' ansible check success, host is %s, output is %s.', ip, result)
        return True
    
    return False
Esempio n. 4
0
def check_server(chain_id):
    """[Using scheck.sh check all nodes of a chain]
    
    Arguments:
        chain_id {[string]} -- [chain_id:version]
    """

    mm = Meta(chain_id)
    if not mm.exist():
        logger.warn('chain meta is not exist, maybe the chain is not published, chain_id is %s', chain_id)
        consoler.warn('chain is not published, can not check action, chain_id is %s', chain_id)
        return 

    logger.info('check action, chain_id is ' + chain_id)
    consoler.info(' => check all node of chain %s', chain_id)
    for k in mm.get_nodes().keys():
        logger.debug('host ip is ' + k)
        ansible.check_module(k, ansible.get_dir() + '/' + chain_id)
Esempio n. 5
0
def unregister_module(ip, dest, index):
    """Using ansible.sh unregister_module, start nodes
    
    Arguments:
        ip {string} -- corresponding server host ip
        dest {string} -- corresponding server dir path
        index {int} -- node index to be register
    
    Returns:
        bool -- true or false
    """

    (status, result) = utils.getstatusoutput('bash ' + path.get_path() +
                                                '/scripts/ansible.sh unregister ' + ip + ' ' + dest + ' ' + str(index))
    logger.debug(' unregister action, status %s, output %s' % (status, result))
    
    if status:
        consoler.warn(' ansible unregister  failed, host is %s, index is %s, dst is %s, status is %s, output is %s.', ip, str(index), dest, status, result)
    elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1:
        consoler.warn(' ansible unregister failed, host is %s, index is %s, dst is %s, status is %s, output is %s.', ip, str(index), dest, status, result)
    elif not (result.find('success') + 1):
        consoler.warn(' ansible register failed, host is %s, index is %s, dst is %s, status is %s, output is %s.', ip, str(index), dest, status, result)
    else:
        consoler.info(' ansible unregister success, host is %s, index is %s, output is %s.', ip, str(index), result)
        return True
    return False
Esempio n. 6
0
def diagnose_server(chain_id):
    """[Using diagnose.sh diagnose all nodes of a chain]
    
    Arguments:
        chain_id {[string]} -- [chain_id:version]
    """

    mm = Meta(chain_id)
    if not mm.exist():
        logger.warn(
            'chain meta is not exist, maybe the chain is not published, chain_id is %s',
            chain_id)
        consoler.warn(
            ' chain is not published, can not diagnose action, chain_id is %s',
            chain_id)
        return

    consoler.info(' ==> diagnose chain %s', chain_id)

    logger.info('diagnose_server action, chain_id is ' + chain_id)
    for k in mm.get_nodes().keys():
        logger.debug('host ip is ' + k)
        ansible.diagnose_module(k, ansible.get_dir() + '/' + chain_id)
Esempio n. 7
0
def mkdir_module(ip, dest):
    """[Using ansible.sh mkdir_module create dictionary ]
    
    Arguments:
        ip {string} -- corresponding server host ip
        dest {string} -- dir path
    
    Returns:
        int -- success return True, else return False.
    """

    (status, result) = utils.getstatusoutput('bash ' + path.get_path() +
                                                '/scripts/ansible.sh mkdir ' + ip + ' ' + dest)
    logger.debug('mkdir action , status %s, output %s' % (status, result))
   
    if status:
        consoler.warn(' ansible mkdir failed, host is %s, dst is %s, status is %s, output is %s.', ip, dest, status, result)
        logger.warn('mkdir action failed, status %s, result %s ' % (status, result))
    elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1:
        consoler.warn(' ansible mkdir failed, host is %s, dst is %s, status is %s, output is %s.', ip, dest, status, result)
        logger.warn('mkdir action failed, output %s' % (result))
    else:
        return True
    return False