def check_chain(chain): """[Check if the nodes is running normally.] Arguments: chain {[list]} -- [get chain_id:host_ip from command Line] """ if chain[0] == 'all': dir = data.meta_dir_base() if os.path.exists(dir): for chain_id in os.listdir(dir): check_server(chain_id) else: consoler.info(' No published chain exist, do nothing.') else: for i in range(len(chain)): chain_get = chain[i].split(':') if len(chain_get) == 1: if utils.valid_chain_id(chain_get[0]): check_server(chain_get[0]) else: consoler.info(' skip, invalid chain_id, chain_id is %s', chain_get[0]) elif len(chain_get) == 2: if utils.valid_chain_id(chain_get[0]): if utils.valid_ip(chain_get[1]): ansible.check_module(chain_get[1], ansible.get_dir() + '/' + chain_get[0]) else: consoler.info(' skip, invalid host, chain_id is %s, host is %s', chain_get[0], chain_get[1]) else: consoler.info(' skip, invalid chain_id, chain_id is %s, host is %s', chain_get[0], chain_get[1]) else: consoler.info(' skip, invalid format, not chain_id:host, input %s', chain_get)
def load(self): dir = data.meta_dir_base() for chain_id in os.listdir(dir): try: meta = Meta(chain_id) self.metas[chain_id] = meta except Exception as e: pass
def stop_chain(chain): """[stop nodes] Arguments: chain {[list]} -- [get chain_id:host_ip from command Line] """ if chain[0] == 'all': consoler.info('You want to stop all node,are you sure? yes or no? y/n') consoler.info('Your choice is : ') choice = sys.stdin.readline().strip('\n') if ((choice == 'yes') | (choice == 'Yes') | (choice == 'Y') | (choice == 'y')): dir = data.meta_dir_base() if os.path.exists(dir): for chain_id in os.listdir(dir): stop_server(chain_id) else: consoler.info(' No published chain exist, do nothing.') else: consoler.info(' input No, and will do nothing.') logger.info('refuse stop all node') else: for i in range(len(chain)): chain_get = chain[i].split(':') if len(chain_get) == 1: if utils.valid_chain_id(chain_get[0]): stop_server(chain_get[0]) else: consoler.info(' skip, invalid chain_id, chain_id is %s', chain_get[0]) elif len(chain_get) == 2: if utils.valid_chain_id(chain_get[0]): if utils.valid_ip(chain_get[1]): ansible.stop_module( chain_get[1], ansible.get_dir() + '/' + chain_get[0]) else: consoler.info( ' skip, invalid host, chain_id is %s, host is %s', chain_get[0], chain_get[1]) else: consoler.info( ' skip, invalid chain_id, chain_id is %s, host is %s', chain_get[0], chain_get[1]) else: consoler.info( ' skip, invalid format, not chain_id:host, input %s', chain_get)
def pub_list(chains): """[List the nodes in package corresponding to the --publishi chain:version] Arguments: chains {[list]} -- [chain id] """ logger.info('list begin, chains is %s', chains) consoler.info(' chains is %s' % chains) ns = Names() meta_list = [] if chains[0] == 'all': dir = data.meta_dir_base() if os.path.exists(dir): for chain_id in os.listdir(dir): m = Meta(chain_id) if not m.empty(): meta_list.append(m) else: consoler.info(' No published chain exist, do nothing.') else: for chain_id in chains: m = Meta(chain_id) if not m.empty(): meta_list.append(m) for m in meta_list: consoler.info( ' => chain id :%s chain name : %s published version : %s', m.get_chain_id(), ns.get_name(m.get_chain_id()), m.get_chain_version()) nodes = m.get_nodes() for host, nodes in nodes.items(): consoler.info('\t host => %s', host) for node in nodes: consoler.info('\t\t node => %s', node.get_node()) logger.info('list end.')