def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Pull. network_id = factory.create_network_id(args.network) network = cache.infra.get_network(network_id) if network is None: raise ValueError("Unregistered network.") # Set key pair. pvk, pbk = crypto.get_key_pair_from_pvk_pem_file( args.pem_path, crypto.KeyAlgorithm.ED25519, crypto.KeyEncoding.HEX, ) # Set faucet. network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.KeyAlgorithm.ED25519, private_key=pvk, public_key=pbk, ) # Push. cache.infra.set_network(network) # Inform. utils.log(f"Network {args.network} faucet key was successfully registered")
def remote_node_ssh_copy( source_path: Path, ssh_user: str, ssh_host: str, target_dir: Path, ssh_key_path: str = None, ): utils.log(f'Copying `{source_path}` to {ssh_host}:{target_dir}') def yield_args(): identity = f'{ssh_user}@{ssh_host}' utils.log(f'Making SSH connection as identity: {identity}') yield 'scp' yield '-r' # yield '-q' if ssh_key_path: utils.log(f'Using SSH key file: {ssh_key_path}') yield '-i' yield ssh_key_path yield source_path target = f'{identity}:{target_dir}' yield target subprocess.run(yield_args(), check=True)
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Unpack. network_id = factory.create_network_id(args.network) node_id = factory.create_node_id(network_id, int(args.node)) # Pull. node = cache.infra.get_node(node_id) if node is None: raise ValueError("Unregistered node.") # Update. node.status = NodeStatus[args.status.upper()] # Push. cache.infra.set_node(node) # Notify. utils.log( f"Node {args.network}:{args.node} status was updated --> {node.status}" )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: _, node = get_network_node(args) nodeset = [node] else: _, nodeset = get_network_nodeset(args) for node in nodeset: utils.log_line() utils.log( f"VALIDATOR ACCOUNT KEYS @ NODE {node.index} ({node.address}) :") utils.log( f"NETWORK: {node.network} :: validator account-hash = {node.account.account_hash}" ) utils.log( f"NETWORK: {node.network} :: validator account-id = {node.account.account_key}" ) utils.log( f"NETWORK: {node.network} :: validator private-key = {node.account.private_key}" ) utils.log( f"NETWORK: {node.network} :: validator public-key = {node.account.public_key}" ) utils.log_line()
def _register_faucet(network: Network, path_pvk_pem: str): """Register a network's faucet account. """ # Set key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_pvk_pem, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX ) # Set faucet. network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.DEFAULT_KEY_ALGO, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_network(network) # Inform. utils.log(f"Registered {network.name} - faucet key")
def _register_network(chainspec: dict, network_idx: int, count_of_bootstrap_nodes: int, count_of_genesis_nodes: int, path_to_faucet_pvk: pathlib.Path): """Register a network. """ # Set network. network = factory.create_network( f"lrt{network_idx}", chainspec['genesis']['name'], count_of_bootstrap_nodes, count_of_genesis_nodes, ) # Set faucet. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_to_faucet_pvk, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX) network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.DEFAULT_KEY_ALGO, private_key=private_key, public_key=public_key, ) # Push to cache. cache.infra.set_network(network) utils.log(f"registered network") return network
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Unpack. host = args.hostname index = int(args.node) network = args.network port_rest = int(args.port_rest) port_rpc = int(args.port_rpc) port_event = int(args.port_event) typeof = NodeType[args.typeof.upper()] # Instantiate. node = factory.create_node(group=NodeGroup.UNKNOWN, host=host, index=index, network_id=factory.create_network_id(network), port_rest=port_rest, port_rpc=port_rpc, port_event=port_event, typeof=typeof) # Push. cache.infra.set_node(node) # Notify. utils.log(f"Node {args.network}:{args.node} was successfully registered")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ account_hash = crypto.get_account_hash(args.account_key) utils.log(f"ACCOUNT HASH = {account_hash or 'N/A'}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Pull data. network_id = factory.create_network_id(args.network) data = cache.orchestration.get_info_list(network_id, args.run_type) data = [i for i in data if i.aspect == ExecutionAspect.RUN] if not data: utils.log("No run information found.") return # Filter by status. if args.status not in (None, "*"): for status in ExecutionStatus: if status.name.lower().startswith(args.status.lower()): data = [i for i in data if i.status == status] break # Associate info with execution context. ctx_list = cache.orchestration.get_context_list(network_id, args.run_type) for i in data: i.ctx = _get_ctx(i, ctx_list) # Associate info with deploy count. keys, counts = cache.orchestration.get_deploy_count_list( network_id, args.run_type) counts = dict(zip(keys, counts)) for i in data: i.deploy_count = _get_deploy_count(i, counts) # Sort data. data = sorted(data, key=lambda i: f"{i.run_type}.{i.label_index}") # Set cols/rows. cols = [i for i, _ in COLS] rows = map(lambda i: _get_row(i, counts), data) # Set table. t = utils.get_table(cols, rows) # Set table alignments. for key, aligmnent in COLS: t.column_alignments[key] = aligmnent # Render. print(t) print( "----------------------------------------------------------------------------------------------------------------------------" ) print(f"{network_id.name} - total runs = {len(data)}.") print( "----------------------------------------------------------------------------------------------------------------------------" )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ network, node = get_network_node(args) purse_uref = chain.get_account_main_purse_uref(network, node, network.faucet.account_key) balance = chain.get_account_balance(network, node, purse_uref) utils.log(f"FAUCET ACCOUNT BALANCE = {balance or 'N/A'}")
def _register_network(network_id: str, chain_name: str): """Register a network. """ network = factory.create_network(network_id, chain_name) cache.infra.set_network(network) # Inform. utils.log(f"registered {network.name_raw} - metadata") return network
def main(args): """Entry point. :param args: Parsed CLI arguments. """ network, node = get_network_node(args) purse_uref = chain.get_account_main_purse_uref(network, node, args.account_key) utils.log(f"ACCOUNT MAIN PURSE UREF = {purse_uref or 'N/A'}")
def _register_node( network: Network, index: int, info: typing.Tuple[str, int, pathlib.Path] ): """Register a network node. """ # Destructure node info. host, weight, path_sk_pem = info # Set default ports. port_rpc = 7777 port_rest = 8888 port_sse = 9999 # Set node. node = factory.create_node( group=NodeGroup.UNKNOWN, host=host, index=index, network_id=factory.create_network_id(network.name_raw), port_rest=port_rest, port_rpc=port_rpc, port_event=port_sse, typeof=NodeType.VALIDATOR, weight=weight, ) # Set bonding key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_sk_pem, algo=crypto.KeyAlgorithm.ED25519, encoding=crypto.KeyEncoding.HEX, ) # Set bonding account. node.account = factory.create_account( network=network.name, typeof=AccountType.VALIDATOR_BOND, index=index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_node(node) # Inform. utils.log(f"registered {network.name_raw} - {node.address_rpc} : {node.typeof.name}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Instantiate. network = factory.create_network(args.network, args.chain) # Push. cache.infra.set_network(network) # Inform. utils.log(f"Network {args.network} was successfully registered")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: purse_uref = chain.get_account_main_purse_uref(network, node, node.account.account_key) balance = chain.get_account_balance(network, node, purse_uref) utils.log(f"VALIDATOR ACCOUNT BALANCE @ NODE #{node.index} ({node.address}) = {balance or 'N/A'}")
def _register_node(network: Network, accounts: dict, index: int, info: typing.Tuple[str, dict, pathlib.Path]): """Register a network node. """ host, cfg, path_to_pvk, is_boostrap = info # Set bonding key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_to_pvk, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX) # Set staking weight. _, _, _, stake_weight = _get_account(accounts, public_key, crypto.DEFAULT_KEY_ALGO) # Set group. group = NodeGroup.BOOTSTRAP if is_boostrap else NodeGroup.GENESIS # Set node. node = factory.create_node( group=group, host=host, index=index, network_id=factory.create_network_id(network.name_raw), port_rest=8888, port_rpc=7777, port_event=9999, typeof=NodeType.VALIDATOR, use_to_dispatch=True, use_to_monitor=random.choice(range(4)) == 0, use_to_query=True, weight=stake_weight, ) # Set bonding account. node.account = factory.create_account( network=network.name, typeof=AccountType.VALIDATOR_BOND, index=index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_node(node) utils.log(f"Registered {node.label}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ utils.log(f"Executing `systemctl {args.command}`:") _, node = get_network_node(args) remote_node_systemctl( node=node, ssh_user=args.ssh_user, command=args.command, ssh_key_path=args.ssh_key_path, check_rc=False, )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: state_root_hash = chain.get_state_root_hash(network, node, args.block_hash) utils.log( f"STATE ROOT HASH @ {node.address_rpc} = {state_root_hash or 'N/A'}" )
def _register_network(network_idx: int, count_of_bootstrap_nodes: int, count_of_genesis_nodes: int): """Register a network. """ # Set network. network = factory.create_network( f"nctl{network_idx}", f"casper-net-{network_idx}", count_of_bootstrap_nodes, count_of_genesis_nodes, ) # Push to cache. cache.infra.set_network(network) # Inform. utils.log(f"Registered {network.name} - metadata") return network
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Pull data. network_id = factory.create_network_id(args.network) data = cache.state.get_deploys(network_id, args.run_type, args.run_index) if not data: utils.log("No run deploys found.") return # Sort data. data = sorted(data, key=lambda i: i.dispatch_timestamp) # Render views. _render_table(args, network_id, data) _render_finalization_stats(data)
def yield_args(): identity = f'{ssh_user}@{ssh_host}' utils.log(f'Making SSH connection as identity: {identity}') yield 'scp' yield '-r' # yield '-q' if ssh_key_path: utils.log(f'Using SSH key file: {ssh_key_path}') yield '-i' yield ssh_key_path yield source_path target = f'{identity}:{target_dir}' yield target
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: utils.log_line() utils.log(f"NODE METRICS @ NODE {node.index} :: {node.address_rpc}:") for metric in chain.get_node_metrics(network, node).split("\n"): if args.metric == "*" or metric.startswith(args.metric): print(metric) utils.log_line()
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Set run data. network_id = factory.create_network_id(args.network) data = cache.orchestration.get_info_list(network_id, args.run_type, args.run_index) if not data: utils.log("No run information found.") return # Set sorted data. data = sorted(data, key=lambda i: i.label_index) # Set deploy counts. keys, counts = cache.orchestration.get_deploy_count_list( network_id, args.run_type, args.run_index) keys = [i.split(":") for i in keys] keys = [f"{i[3]}.{i[5]}" if i[5] != "-" else i[3] for i in keys] counts = dict(zip(keys, counts)) # Set table. t = utils.get_table( [i for i, _ in COLS], map(lambda i: _get_row(i, counts), data), ) for key, aligmnent in COLS: t.column_alignments[key] = aligmnent # Render. print(t) print( "--------------------------------------------------------------------------------------------------------------------" ) print(f"{network_id.name} - {args.run_type} - Run {args.run_index}") print( "--------------------------------------------------------------------------------------------------------------------" )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: info = chain.get_node_peers(network, node) if info: utils.log_line() utils.log(f"NODE PEERS @ {node.address_rpc}:") print(json.dumps(info, indent=4)) else: utils.log("Node peers query failed.") utils.log_line()
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: try: block = chain.get_block(network, node) except: utils.log(f"ERA::HEIGHT @ {node.address_rpc} = N/A") else: utils.log( f"ERA:HEIGHT @ {node.address_rpc} = {block['header']['era_id']}:{block['header']['height']}" )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Pull. network_id = factory.create_network_id(args.network) network = cache.infra.get_network(network_id) if network is None: raise ValueError("Unregistered network.") # Update. network.status = NetworkStatus[args.status.upper()] # Push. cache.infra.set_network(network) # Notify. utils.log( f"Network {args.network} status was updated --> {network.status}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ network = get_network(args) healthy_nodes, down_nodes = get_healthy_and_down_nodes(network) # Check that there are enough nodes. if not len(healthy_nodes) and not len(down_nodes): utils.log('No nodes found, returning') return # TODO: Do we need to ensure at least one healthy node is always remaining? target_node = random.choice(healthy_nodes + down_nodes) utils.log(f'Selected node #{target_node.index} for toggling') utils.log(f'Current status of node: {target_node.status}') if target_node.status is NodeStatus.DOWN: # Start the node. command = SvcCommand.START else: # Stop the node. command = SvcCommand.STOP remote_node_systemctl( node=target_node, ssh_user=args.ssh_user, command=command, ssh_key_path=args.ssh_key_path, force=args.force, )
def yield_args(): identity = f'{ssh_user}@{ssh_host}' utils.log(f'Making connection as identity: {identity}') yield 'rsync' yield '-avz' yield '-q' if use_remote_sudo: utils.log('Using `sudo` on remote target') yield '--rsync-path="sudo rsync"' if ssh_key_path: utils.log(f'Using SSH key file: {ssh_key_path}') # With `rsync`, this needs to be passed in as a suboption to `ssh`. yield '-e' yield f'ssh -i {ssh_key_path}' yield source_path target = f'{identity}:{target_dir}' yield target
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Unpack. network_id = factory.create_network_id(args.network) node_id = factory.create_node_id(network_id, int(args.node)) # Pull. node = cache.infra.get_node(node_id) if node is None: raise ValueError("Unregistered node.") # Set key pair. pvk, pbk = crypto.get_key_pair_from_pvk_pem_file( args.pem_path, algo=crypto.KeyAlgorithm.ED25519, encoding=crypto.KeyEncoding.HEX) # Set bonding account. node.account = factory.create_account( network=network_id.name, typeof=AccountType.VALIDATOR_BOND, index=-node_id.index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=pvk, public_key=pbk, ) # Push. cache.infra.set_node(node) # Inform. utils.log( f"Node {args.network}:{args.node} bonding key was successfully registered" )
def remote_node_ssh_rsync( source_path: Path, ssh_user: str, ssh_host: str, target_dir: Path, ssh_key_path: str = None, use_remote_sudo: bool = True, ): utils.log( f'Copying `{source_path}` to {ssh_host}:{target_dir} using `rsync`') def yield_args(): identity = f'{ssh_user}@{ssh_host}' utils.log(f'Making connection as identity: {identity}') yield 'rsync' yield '-avz' yield '-q' if use_remote_sudo: utils.log('Using `sudo` on remote target') yield '--rsync-path="sudo rsync"' if ssh_key_path: utils.log(f'Using SSH key file: {ssh_key_path}') # With `rsync`, this needs to be passed in as a suboption to `ssh`. yield '-e' yield f'ssh -i {ssh_key_path}' yield source_path target = f'{identity}:{target_dir}' yield target subprocess.run(yield_args(), check=True)