def main(): try: init() except Exception as e: consoler.error(' \033[1;31m OWMC init fault , %s \033[0m', e) else: Usage()
def do_cmd(dst, cmd): """do cmd on remote server, dst can be one server, one chain or all server Arguments: dst {string} -- host ip or chain id or 'all' cmd {string} -- shell cmd or shell file """ if dst == 'all': ansible.cmd_module('all', cmd) elif utils.valid_chain_id(dst): mm = Meta(dst) if not mm.exist(): consoler.error( ' \033[1;31m chain is not published, can not cmd action, chain_id is %s \033[0m', dst) else: consoler.info(' => do cmd, chain id is %s', dst) for k in mm.get_nodes().keys(): logger.debug('host ip is ' + k) ansible.cmd_module(k, cmd) elif utils.valid_ip(dst): ansible.cmd_module(dst, cmd) else: consoler.error( ' \033[1;31m invalid docmd dst, dst is %s, dst should be invalid chain_id or invali host ip or \'all\'. \033[0m', dst)
def generate_root_ca(dir, gm=False): """[generate root cert] Arguments: dir {[path]} -- [root cert path] """ try: dir = os.path.abspath(dir) if gm: (status, result) = utils.getstatusoutput( 'bash ' + path.get_path() + '/scripts/ca/gm/cts.sh gen_chain_cert ' + dir) else: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/cts.sh gen_chain_cert ' + dir) if status != 0: logger.warn( ' cts.sh failed! status is %d, output is %s, dir is %s.', status, result, dir) raise MCError( 'cts.sh failed! status is %d, output is %s, dir is %s.' % (status, result, dir)) logger.info(' cts.sh success! status is %d, output is %s, dir is %s.', status, result, dir) logger.info(' Generate root cert success, dir is %s', dir) consoler.info(' Generate root cert success, dir is %s' % dir) except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error( ' \033[1;31m Generate root cert failed! excepion is %s.\033[0m', e) logger.error(' Generate root cert failed! Result is %s' % result)
def publish_chain(chains, force = False): """Publish a chain to designated servers using publish_server Arguments: chains {list} -- chain which you wanto published, type chain_id:chain_version. Returns: null """ pchains = [] for i in range(len(chains)): chain = chains[i].split(':') if len(chain) != 2: logger.error('not chain_id:chain_version format, str is %s', chains[i]) consoler.error(' \033[1;31m skip, invalid publish format, chain_id:chain_version should require, chain is %s \033[0m', chain) continue chain_id = chain[0] chain_version = chain[1] pchains.append(Chain(chain_id, chain_version)) # consoler.info('\t append publish chain, chain_id %s:chain_version %s', chain_id, chain_version) logger.debug('chain_id is %s, chain_version is %s', chain_id, chain_version) if len(pchains) != 0: for chain in pchains: logger.info('publish, chain_id is %s, chain_version is %s', chain_id, chain_version) publish_server(chain.get_id(), chain.get_version(), force)
def cmd_module(ip, cmd): """Using ansible.sh cmd_module, execute commands on the corresponding server. Arguments: ip {string} -- server host ip Keyword Arguments: msg {string} -- execute commands Returns: [bool] -- true or false """ cmd = '"' + cmd + '"' (status, result) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ansible.sh cmd ' + ip + ' ' + cmd) logger.debug(' cmd action , status %s, output %s' % (status, result)) if status: consoler.error(' \033[1;31m ansible cmd failed, host is %s, output is %s \033[0m', ip, result) elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1: consoler.error(' \033[1;31m ansible cmd failed, host is %s, output is %s \033[0m', ip, result) else: consoler.info(' ansible cmd success, host is %s, cmd is %s.', ip, cmd) return True return False
def generator_sdk_ca(agency_dir, sdk_dir, gm=False): """[generate sdkcert] Arguments: dir {[path]} -- [agency cert path] If operation success, dir will generate sdk dir under the target path, the content is sdk_cert. """ dir = os.path.abspath(agency_dir) sdk_dir = os.path.abspath(sdk_dir) try: if gm: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/gm/cts.sh gen_sdk_cert ' + dir + ' ' + sdk_dir) else: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/cts.sh gen_sdk_cert ' + dir + ' ' + sdk_dir) if not status: consoler.info(' Generate sdk cert successful! dir is %s.', sdk_dir + '/sdk') logger.info(' Generate sdk cert successful! dir is %s.', sdk_dir + '/sdk') else: logger.error(' Generate sdk cert failed! Result is %s' % result) raise MCError(' Generate sdk cert failed! Result is %s' % result) except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error( ' \033[1;31m Generate root cert failed! excepion is %s.\033[0m', e) logger.error(' Generate root cert failed! Result is %s' % result)
def parser(self): self.clear() if os.path.exists(self.cfg) and os.path.isfile(self.cfg): logger.info(' single config is %s', self.cfg) # resolve one config.json try: self.append(ConfigConf(self.cfg)) except Exception as e: logger.warn('parser cfg %s end exception, e is %s ', self.cfg, e) raise MCError(' parser config failed, invalid format, config is %s, exception is %s' % (self.cfg, e)) elif os.path.isdir(self.cfg): logger.info(' config dir is %s', self.cfg) # resolve dir, if not config.json goto next for c in os.listdir(self.cfg): try: logger.debug(' config dir is %s, config file is %s', self.cfg, c) cc = ConfigConf(self.cfg + '/' + c) chain = cc.get_chain() if not self.append(cc): cc = self.get_cc(chain) logger.error(' chain_id: %s and chain_version: %s duplicate, config is %s:%s', chain.get_id(), chain.get_version(), cc.get_cfg(), c) raise MCError(' chain_id: %s and chain_version: %s duplicate, config is %s:%s' % (chain.get_id(), chain.get_version(), cc.get_cfg(), c)) logger.debug(' append cc, cc is %s', cc) consoler.info(' parser config %s success, chain_id is %s, chain_version is %s', c, chain.get_id(), chain.get_version()) except Exception as e: consoler.error( ' \033[1;31m skip config %s, invalid config format parser failed, exception is %s \033[0m', c, e) logger.warn(' parser cfg %s end exception, e %s ', c, e) else: raise MCError(' invalid config, %s not exist' % self.cfg)
def check_cert_sdk(path): """[check sdk cert exist] Arguments: path {[dir -> sdk cert]} -- [where sdk cert put] Raises: MCError -- [catch sdk Init status] Returns: [bool] -- [true or false] """ result = os.path.exists(path + '/sdk/sdk.crt') and os.path.exists(path + '/sdk/ca.crt') and os.path.exists(path + '/sdk/client.keystore')\ and os.path.exists(path + '/sdk/keystore.p12') and os.path.exists(path + '/sdk/sdk.csr') and os.path.exists(path + '/sdk/sdk.key') and os.path.exists(path + '/sdk/sdk.param')\ and os.path.exists(path + '/sdk/sdk.private') and os.path.exists(path + '/sdk/sdk.pubkey') try: if result: consoler.info(' Init sdk cert success!') else: logger.error(' Init sdk cert failed!') raise MCError(' Init sdk cert failed!') except MCError as me: logger.error(me) consoler.error(me) return result
def init_ansible(hosts_conf, add_opr=False): try: if not os.path.exists(hosts_conf): raise MCError('hosts_conf not exisits! ') if add_opr: src = '/etc/ansible/hosts' dst = '/etc/ansible/hosts.bak' if not os.path.exists(src): raise MCError('/etc/ansible/hosts not exisits! ') os.rename(src, dst) f = open(src, 'w') f.close() for line in open(hosts_conf): line = line.strip() host_value = line.split() if len(host_value) != 4: raise Exception('hosts_conf type error ,host_line -> %s', host_value) user = host_value[0] ip = host_value[1] port = host_value[2] passwd = host_value[3] if not utils.valid_string(user): raise Exception( 'user type error ,user -> %s, host_line -> %s' % (user, host_value)) if not utils.valid_ip(ip): raise Exception('ip type error ,ip -> %s, host_line -> %s' % (ip, host_value)) if not utils.valid_port(int(port)): raise Exception( 'port type error ,port -> %s, host_line -> %s' % (port, host_value)) if not utils.valid_string(passwd): raise Exception( 'passwd type error ,passwd -> %s, host_line -> %s' % (passwd, host_value)) (status, result) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ansible_init.sh' + ' ' + user + ' ' + ip + ' ' + port + ' ' + passwd) if status != 0: logger.warn( ' ansible_init failed! status is %d, output is %s.', status, result) raise MCError( 'ansible_init failed! status is %d, output is %s.' % (status, result)) result = [] result.append(ip) opr_tools.telnet_ansible(result) logger.info(' ansible_init success! status is %d, output is %s', status, result) except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error( ' \033[1;31m ansible_init failed! excepion is %s.\033[0m', e)
def publish_server(chain_id, chain_version, force=False): """publish one chain. Arguments: chain_id {string} -- chain id. chain_version {string} -- chain version. force {bool} """ chain = Chain(chain_id, chain_version) dir = chain.data_dir() if not os.path.isdir(dir): consoler.info( ' No build version exist for chain_id:%s chain_version:%s, do nothing.', chain_id, chain_version) logger.warn( ' No build version exist for chain_id:%s chain_version:%s, do nothing.', chain_id, chain_version) return mm = meta.Meta(chain_id) if force: # force is set, publish this chain again. mm.clear() mm.set_chain_version(chain_version) else: if mm.exist(): if chain_version != mm.get_chain_version(): consoler.error( ' \033[1;31m chain %s already publish %s version, if you want publish annother version, --force/-f need to be set.\033[0m ', chain_id, mm.get_chain_version()) return else: mm.set_chain_version(chain_version) consoler.info(' publish package for chain %s version %s begin.', chain_id, chain_version) for host in os.listdir(dir): if not utils.valid_ip(host): logger.debug(' skip, not invalid host_ip ' + host) continue ret = push_package(dir, host, chain_id, chain_version, mm, force) if ret: hp = HostPort(chain_id, chain_version, host) for node_dir, p in hp.get_ports().items(): logger.debug(' node_dir is %s, port is %s', node_dir, p) if not mm.host_node_exist(host, node_dir): mm.append(meta.MetaNode(host, p.get_rpc_port(), p.get_p2p_port(), p.get_channel_port(), node_dir)) consoler.info(' \t push package : %s success.', host) else: consoler.error(' \033[1;31m \t push package : %s failed. \033[0m', host) # record meta info, write meta.json file mm.write_to_file() consoler.info(' publish package for chain %s version %s end.', chain_id, chain_version)
def build(cfg, fisco_path): """parser input config file, build install pacakge by Arguments: cfg {string} --config, maybe a config.json or a dictionary of conf,eg: ./conf/config.conf or ./conf fisco_path {string} -- path of fisco-bcos, eg: /usr/local/bin/fisco-bcos """ logger.info('build cfg is %s, fisco is %s ', cfg, fisco_path) try: # check java env java = JAVA() fisco = Fisco(fisco_path) # parser and check config if valid ccs = ConfigConfs(cfg).get_ccs() ns = Names() # build all chain if len(ccs) != 0: for cc in ccs.values(): try: chain_id = cc.get_chain().get_id() chain_version = cc.get_chain().get_version() chain_name = cc.get_chain().get_name() consoler.info( ' build install package for chain %s version %s.', chain_id, chain_version) build_chain.build(cc, fisco) ns.append(chain_id, chain_name) consoler.info( ' \t build install package for chain %s version %s success.', chain_id, chain_version) except MCError as me: logger.error(me) consoler.error(' \033[1;31m \t %s \033[0m', me) ns.write() else: consoler.info(' build operation will do nothing.') except MCError as me: logger.error(me) consoler.error(' \033[1;31m \t %s \033[0m', me) logger.info(' chain build end.')
def diagnose_module(ip, dest): """Using ansible.sh diagnose_module, call script -> monotor.sh, Check status of nodes Arguments: ip {string} -- corresponding server host ip dest {string} -- corresponding server dir path """ (status, result) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ansible.sh diagnose ' + ip + ' ' + dest) logger.debug('diagnose action , status %s, output %s' % (status, result)) if status: consoler.error(' \033[1;31m ansible diagnose failed, host is %s, output is %s \033[0m', ip, result) elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1: consoler.error(' \033[1;31m ansible diagnose failed, host is %s, output is %s \033[0m', ip, result) else: consoler.info(' ansible diagnose success, host is %s, result is %s.', ip, result) return True return False
def register(chain_id, host, node): logger.debug(' chain_id is %s, host is %s, node is %s', chain_id, host, node) meta = Meta(chain_id) if not meta.exist(): consoler.error( ' \033[1;31m register failed, chain not published, chain id is %s \033[0m', chain_id) return try: meta.get_host_node(host, node) except MCError as me: consoler.error(' \033[1;31m register failed, %s \033[0m', me) else: ret = ansible.register_module(host, ansible.get_dir() + '/' + chain_id, int(node[4:])) if ret: consoler.info( ' register success, chain_id is %s, host is %s, node is %s. \033[0m', chain_id, host, node) else: consoler.error( ' \033[1;31m register failed, chain_id is %s, host is %s, node is %s. \033[0m', chain_id, host, node)
def telnet_ansible(server): """[Test ansible operation to all server in operation server] Arguments: server {[list]} -- [host ip] """ if server[0] == 'all': server = ['all'] for i in range(len(server)): if utils.valid_ip(server[i]) or server[i] == 'all': if ansible.telnet_module(server[i]): consoler.info(' telnet test success, host is %s.\n', server[i]) else: consoler.error( ' \033[1;31m telnet test failed, host is %s. \033[0m', server[i]) else: consoler.error( ' \033[1;31m Not invalid host, skip, host is %s. \033[0m', server[i])
def expand(cfg, dir): """expand operation Arguments: cfg {string} -- config file path dir {string} -- dir with fisco-bcos, genesis.json, bootstrapsnode.json """ logger.debug(' cfg is %s, dir is %s', cfg, dir) try: # check java env java = JAVA() try: # parser and check config if valid cc = ConfigConf(cfg) except Exception as e: raise MCError( ' parser config failed, invalid format, config is %s, exception is %s' % (cfg, e)) if os.path.exists(cc.get_chain().data_dir()): ns = Names() expand_chain.expand_on_exist_chain(cc) ns.write() else: expand_chain.expand_on_nonexist_chain(cc, dir) consoler.info( ' expand install package for chain %s version %s success.', cc.get_chain().get_id(), cc.get_chain().get_version()) except MCError as me: consoler.error(me) consoler.error(' \033[1;31m \t %s \033[0m', me)
def telnet_module(ip, msg='HelloWorld!'): """using ansible.sh telnet module, echo 'HelloWorld' to screen to check ansible is useful. Arguments: ip {string} -- host ip Keyword Arguments: msg {string} -- test string (default: {'HelloWorld!'}) Returns: [bool] -- ansible useful echo return True, else False. """ (status, result) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ansible.sh telnet ' + ip + ' ' + msg) logger.debug('telnet action , status %s, output %s' % (status, result)) if status: consoler.error(' \033[1;31m ansible telnet failed, host is %s, output is %s \033[0m', ip, result) elif result.find('SUCCESS') == -1 and result.find('CHANGED') == -1: consoler.error(' \033[1;31m ansible telnet failed, host is %s, output is %s \033[0m', ip, result) else: consoler.info(' ansible telnet success, host is %s, output is %s', ip, result) return True return False
def export(self): try: if self.fisco.is_gm(): shutil.move(get_gm_god_path() + '/godInfo.txt', get_gm_god_path() + '/godInfo.txt.bak') cmd = self.fisco.get_fisco_path() + ' --newaccount ' + get_gm_god_path() + '/godInfo.txt' status, result = utils.getstatusoutput(cmd) logger.debug(' start status, status is %d, output is %s', status, result) else: shutil.move(get_god_path() + '/godInfo.txt', get_god_path() + '/godInfo.txt.bak') cmd = self.fisco.get_fisco_path() + ' --newaccount ' + get_god_path() + '/godInfo.txt' status, result = utils.getstatusoutput(cmd) logger.debug(' start status, status is %d, output is %s', status, result) if status != 0: logger.warn(' export godInfo.txt failed! status is %d, output is %s.', status, result) raise MCError('godInfo.txt failed! status is %d, output is %s.' % (status, result)) logger.info(' export godInfo.txt status is %d, output is %s.', status, result) consoler.info(' export godInfo.txt success') except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error(' \033[1;31m export godInfo.txt failed! excepion is %s.\033[0m', e) logger.error(' export godInfo.txt failed!')
def push_file(host, src, dst): """push file to remote server Arguments: host {string} -- host ip or chain id or 'all' src {string} -- file or dir dst {string} -- dst dir """ if not os.path.exists(src): consoler.error(' \033[1;31m src is not exist, src is %s. \033[0m', src) return logger.info(' host is %s, src is %s, dst is %s', host, src, dst) if host == 'all': if mkdir_and_push(host, src, dst): consoler.info(' push %s to %s of all server success.', src, dst) elif utils.valid_chain_id(host): consoler.info(' => push %s to %s of chain %s.', src, dst, host) mm = Meta(host) if not mm.exist(): consoler.error( ' \033[1;31m chain is not published, can not push file action, chain_id is %s \033[0m', host) else: consoler.info(' => do cmd, chain id is %s', host) for k in mm.get_nodes().keys(): logger.debug(' host is %s', k) if mkdir_and_push(k, src, dst): consoler.info(' \t\t push %s to %s of %s server success.', src, dst, k) consoler.info(' => push %s to %s of chain %s end.', src, dst, host) elif utils.valid_ip(host): if mkdir_and_push(host, src, dst): consoler.info(' push %s to %s of %s server success.', src, dst, host) else: consoler.error( ' \033[1;31m invalid push file host, host is %s, dst should be invalid chain_id or invali host ip or \'all\'. \033[0m', host)
def generator_node_ca(agent, dir, node, gm=False): """[generate node cert ] Arguments: agent {[path]} -- [agency cert path] node {[string]} -- [node name] dir {[path]} -- [node cert path] """ _dir = os.path.abspath(dir) agent = os.path.abspath(agent) try: if gm: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/gm/cts.sh gen_node_cert ' + agent + ' ' + _dir + '/ ' + node) else: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/cts.sh gen_node_cert ' + agent + ' ' + _dir + '/ ' + node) if not status: logger.info(' Generate %s cert successful! dir is %s.', node, _dir + '/' + node) else: consoler.error( ' \033[1;31m Generate node cert failed! Please check your network, and try to check your opennssl version.\033[0m' ) logger.error(' Generate %s cert failed! Result is %s' % (node, result)) raise MCError(' Generate %s cert failed! Result is %s' % (node, result)) except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error( ' \033[1;31m Generate root cert failed! excepion is %s.\033[0m', e) logger.error(' Generate root cert failed! Result is %s' % result)
def generator_agent_ca(dir, ca, agent, gm=False): """[generate agency cert] Arguments: dir {[path]} -- [agency cert path] ca {[path]} -- [root cert path] agent {[string]} -- [agency name] """ try: ca = os.path.abspath(ca) dir = os.path.abspath(dir) if gm: (status, result) = utils.getstatusoutput( 'bash ' + path.get_path() + '/scripts/ca/gm/cts.sh gen_agency_cert ' + ca + ' ' + dir + ' ' + agent) else: (status, result ) = utils.getstatusoutput('bash ' + path.get_path() + '/scripts/ca/cts.sh gen_agency_cert ' + ca + ' ' + dir + ' ' + agent) if not status: logger.info(' Generate %s cert successful! dir is %s.' % (agent, dir + '/' + agent)) else: consoler.error( ' \033[1;31m Generate %s cert failed! Please check your network, and try to check your opennssl version.\033[0m' ) logger.error(' Generate %s cert failed! Result is %s' % (agent, result)) raise MCError(' Generate %s cert failed! Result is %s' % (agent, result)) except MCError as me: consoler.error(' \033[1;31m %s \033[0m', me) except Exception as e: consoler.error( ' \033[1;31m Generate root cert failed! excepion is %s.\033[0m', e) logger.error(' Generate root cert failed! Result is %s' % result)
def Usage(): """cmd usage """ parser = argparse.ArgumentParser( description= ' Build fisco-bcos install pkg for multi chain and manage the chain package with ansible. ' ) parser.add_argument('--version', action='store_true', help='show OWMC\'s version. ') parser.add_argument( '--ansibleinit', nargs=1, metavar=(' hosts config file '), help=' initialize ansible configuration file, need sudo permissions. ') parser.add_argument('--cainit', action='store_true', help=' initialize cert. ') pkg_group = parser.add_argument_group( ' Build, Expand, Export, List Chain Package Options ') pkg_group.add_argument( '--build', nargs=2, metavar=('./config.conf or ./conf/', 'fisco_path'), help=' build chain packages with the specified configuration file') pkg_group.add_argument('--expand', nargs=2, metavar=('./config.conf, dir'), help='build chain packages on exist chain') pkg_group.add_argument('--export', nargs=3, metavar=('chain_id', 'chain_version', 'dest_path'), help='export build package out.') pkg_group.add_argument('--pkglist', nargs='+', metavar=('all or chain_id'), help='list build packages info.') pkg_group.add_argument( '--direct', action='store_true', help= 'follow --export/-E, package of chain will export without reordering') mgr_group = parser.add_argument_group( ' Manage Published Chain With Ansible Options ') mgr_group.add_argument('--publish', nargs='+', metavar=('chain_id:version'), help='publish packages') mgr_group.add_argument('--start', nargs='+', metavar=('all or chain_id or', 'chain_id:host_ip'), help='start node') mgr_group.add_argument('--stop', nargs='+', metavar=('all or chain_id or', 'chain_id:host_ip'), help='stop node') mgr_group.add_argument('--register', nargs=3, metavar=('chain_id ', 'host_ip', 'node'), help='register node on node with expand opr build') mgr_group.add_argument('--unregister', nargs=3, metavar=('chain_id ', 'host_ip', 'node'), help='unregister node') mgr_group.add_argument('--diagnose', nargs='+', metavar=('all or chain_id or', 'chain_id:host_ip'), help='diagnose node') mgr_group.add_argument('--check', nargs='+', metavar=('all or chain_id or', 'chain_id:host_ip'), help='check servers status') mgr_group.add_argument('--publist', nargs='+', metavar=('all or chain_id or'), help='list published packages info.') mgr_group.add_argument('--lshost', nargs='+', metavar=('host_ip'), help='ls published packages\' host') mgr_group.add_argument( '--force', action='store_true', help='follow --publish, all package of chain will be republished') tools_group = parser.add_argument_group(' Other Tools Options ') tools_group.add_argument('--envcheck', nargs='+', metavar=('all or host_ip'), help='check build environment') tools_group.add_argument('--telnet', nargs='+', metavar=('\'all\' or host_ip or chain_id'), help='test ansible') tools_group.add_argument( '--docmd', nargs=2, metavar=(' host ip or chain id or \'all\'', 'shell cmd or shell file, e.g. \'ls -lt\' test.sh'), help='execute a shell command or shell file on remote server') tools_group.add_argument('--pushfile', nargs=3, metavar=('host ip or chain id or \'all\'', 'file or dir to be push.', 'dst dir.'), help='push one file or dir to remote server.') tools_group.add_argument('--chainca', nargs=1, metavar=('chain_dir', ), help='generate root cert') tools_group.add_argument('--agencyca', nargs=3, metavar=('agency_dir', 'chain_dir', ' agency_name'), help='generate agency cert') tools_group.add_argument('--nodeca', nargs=3, metavar=('agency_dir', 'node _dir', 'node_name'), help='generate node cert') tools_group.add_argument('--sdkca', nargs=2, metavar=('sdk_dir', 'agency_dir'), help='generate sdk cert') tools_group.add_argument( '--gm', action='store_true', help= 'follow ----chainca/--agencyca/--agencyca/--sdkca, is gm ca operation.' ) tools_group.add_argument('--god', nargs=1, metavar=('fiscopath'), help='god module.') args = parser.parse_args() os.path.exists if args.version: version.version() elif args.god: consoler.info(' god operation begin.') opr_god.opr_god(args.god[0]) consoler.info(' god operation end.') elif args.build: consoler.info(' build operation begin.') opr_build.build(args.build[0], args.build[1]) consoler.info(' build operation end.') elif args.expand: consoler.info(' expand operation begin.') opr_expand.expand(args.expand[0], args.expand[1]) consoler.info(' expand operation end.') elif args.check: consoler.info(' check operation begin.') chain = args.check opr_check.check_chain(chain) consoler.info(' check operation end.') elif args.diagnose: consoler.info(' diagnose operation begin.') chain = args.diagnose opr_diagnose.diagnose_chain(chain) consoler.info(' diagnose operation end.') elif args.publish: consoler.info(' publish operation begin.') chain = args.publish opr_publish.publish_chain(chain, args.force) consoler.info(' publish operation end.') elif args.register: consoler.info(' register operation begin.') opr_register.register(args.register[0], args.register[1], args.register[2]) consoler.info(' register operation end.') elif args.unregister: consoler.info(' unregister operation begin.') opr_register.unregister(args.unregister[0], args.unregister[1], args.unregister[2]) consoler.info(' unregister operation end.') elif args.start: consoler.info(' start operation begin.') chain = args.start opr_start.start_chain(chain) consoler.info(' start operation end.') elif args.stop: consoler.info(' stop operation begin.') chain = args.stop opr_stop.stop_chain(chain) consoler.info(' stop operation end.') elif args.publist: consoler.info(' publist operation begin.') chain = args.publist opr_list.pub_list(chain) consoler.info(' publist operation end.') elif args.pkglist: consoler.info(' pkglist operation begin.') chain = args.pkglist opr_list.pkg_list(chain) consoler.info(' pkglist operation end.') elif args.docmd: consoler.info(' docmd operation begin.') params = args.docmd opr_tools.do_cmd(params[0], params[1]) consoler.info(' docmd operation end.') elif args.pushfile: consoler.info(' pushfile operation begin.') params = args.pushfile opr_tools.push_file(params[0], params[1], params[2]) consoler.info(' pushfile operation end.') elif args.chainca: consoler.info(' chain cert begin.') chain_dir = args.chainca[0] ca.generate_root_ca(chain_dir, args.gm) consoler.info(' chain cert end.') elif args.agencyca: consoler.info(' agency cert begin.') agency_dir = args.agencyca[0] chain_dir = args.agencyca[1] agency_name = args.agencyca[2] ca.generator_agent_ca(agency_dir, chain_dir, agency_name, args.gm) consoler.info(' agency cert end.') elif args.nodeca: consoler.info(' agency cert begin.') agency_dir = args.nodeca[0] node_dir = args.nodeca[1] node_name = args.nodeca[2] ca.generator_node_ca(agency_dir, node_dir, node_name, args.gm) consoler.info(' agency cert end.') elif args.sdkca: consoler.info(' sdk cert begin.') sdk_dir = args.sdkca[0] agency_dir = args.sdkca[1] ca.generator_sdk_ca(agency_dir, sdk_dir, args.gm) consoler.info(' sdk cert end.') elif args.envcheck: consoler.info(' envcheck operation begin.') hosts = args.envcheck opr_env_check.env_check(hosts) consoler.info(' envcheck operation end.') elif args.telnet: consoler.info(' telnet operation begin.') telnet_list = args.telnet opr_tools.telnet_ansible(telnet_list) consoler.info(' telnet operation end.') elif args.ansibleinit: opr_init_chain.init_ansible(args.ansibleinit[0], False) consoler.info(' ansible init end.') elif args.cainit: consoler.info(' cert init begin.') ca.init_ca(args.cainit[0]) consoler.info(' cert init end.') elif args.export: consoler.info(' export operation begin.') opr_export.export_package(args.export[0], args.export[1], args.export[2], args.direct) consoler.info(' export operation end.') elif args.lshost: consoler.info(' lshost operation begin.') opr_list.ls_host(args.lshost) consoler.info(' lshost operation end.') else: consoler.error( '\033[1;31m invalid operation, \"owmc -h\" can be used to show detailed usage. \033[0m' ) return 0