def deploy(general_config, staker_options, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe, prometheus): """Deploys NuCypher on existing hardware.""" emitter = setup_emitter(general_config) if not CloudDeployers: emitter.echo("Ansible is required to use `nucypher cloudworkers *` commands. (Please run 'pip install ansible'.)", color="red") return STAKEHOLDER = staker_options.create_character(emitter, config_file) stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, stakes) config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer('generic')(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, prometheus=prometheus) emitter.echo("found nodes for the following stakers:") for staker_address in staker_addresses: if deployer.config['instances'].get(staker_address): data = deployer.config['instances'].get(staker_address) emitter.echo(f'\t{staker_address}: {data["publicaddress"]}', color="yellow") deployer.deploy_nucypher_on_existing_nodes(staker_addresses, wipe_nucypher=wipe)
def add_for_stake(general_config, staker_options, config_file, staker_address, host_address, login_name, key_path, ssh_port, namespace): """Sets an existing node as the host for the given staker address.""" emitter = setup_emitter(general_config) STAKEHOLDER = staker_options.create_character( emitter, config_file ) # FIXME: NameErrors for 'staker options' and 'config_file' stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, [staker_address]) if not staker_addresses: emitter.echo( f"Could not find staker address: {staker_address} among your stakes. (try `nucypher stake --list`)", color="red") return config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer('generic')( emitter, STAKEHOLDER, config_file, namespace=namespace, network=STAKEHOLDER.network, action='add_for_stake') config = deployer.create_nodes(staker_addresses, host_address, login_name, key_path, ssh_port)
def up(general_config, staker_options, config_file, cloudprovider, aws_profile, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe, prometheus): """Creates workers for all stakes owned by the user for the given network.""" emitter = setup_emitter(general_config) if not CloudDeployers: emitter.echo("Ansible is required to use this command. (Please run 'pip install ansible'.)", color="red") return STAKEHOLDER = staker_options.create_character(emitter, config_file) stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, stakes) config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, aws_profile, prometheus) config = deployer.create_nodes_for_stakers(staker_addresses) if config.get('instances') and len(config.get('instances')) >= len(staker_addresses): emitter.echo('Nodes exist for all requested stakes', color="yellow") deployer.deploy_nucypher_on_existing_nodes(staker_addresses, wipe_nucypher=wipe)
def destroy(general_config, staker_options, config_file, cloudprovider, stakes): """Cleans up all previously created resources for the given netork for the cloud providern""" emitter = setup_emitter(general_config) if not CloudDeployers: emitter.echo( "Ansible is required to use `nucypher cloudworkers *` commands. (Please run 'pip install ansible'.)", color="red") return STAKEHOLDER = staker_options.create_character(emitter, config_file) stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, stakes) config_file = config_file or StakeHolderConfiguration.default_filepath() if not cloudprovider: hosts = CloudDeployers.get_deployer('generic')( emitter, STAKEHOLDER, config_file).get_all_hosts() if len(set(host['provider'] for address, host in hosts)) == 1: cloudprovider = hosts[0][1]['provider'] else: emitter.echo( "Please specify which provider's hosts you'd like to destroy using --cloudprovider (digitalocean or aws)" ) deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file) deployer.destroy_resources(staker_addresses=staker_addresses)
def add(general_config, staker_options, config_file, staker_address, host_address, login_name, key_path, ssh_port): """Creates workers for all stakes owned by the user for the given network.""" emitter = setup_emitter(general_config) STAKEHOLDER = staker_options.create_character(emitter, config_file) stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, [staker_address]) if not staker_addresses: emitter.echo( f"Could not find staker address: {staker_address} among your stakes. (try `nucypher stake --list`)", color="red") return config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer('generic')(emitter, STAKEHOLDER, config_file) config = deployer.create_nodes_for_stakers(staker_addresses, host_address, login_name, key_path, ssh_port)
def config(general_config, config_file, config_options): """View and optionally update existing StakeHolder's configuration.""" emitter = setup_emitter(general_config) configuration_file_location = config_file or StakeHolderConfiguration.default_filepath() updates = config_options.get_updates() get_or_update_configuration(emitter=emitter, config_class=StakeHolderConfiguration, filepath=configuration_file_location, updates=updates)
def config(general_config, config_file, config_options): """View and optionally update existing StakeHolder's configuration.""" emitter = _setup_emitter(general_config) configuration_file_location = config_file or StakeHolderConfiguration.default_filepath() emitter.echo(f"StakeHolder Configuration {configuration_file_location} \n {'='*55}") return get_or_update_configuration(emitter=emitter, config_class=StakeHolderConfiguration, filepath=configuration_file_location, config_options=config_options)
def status(general_config, staker_options, config_file, cloudprovider, stakes): """Displays worker status and updates worker data in stakeholder config""" emitter = setup_emitter(general_config) if not CloudDeployers: emitter.echo("Ansible is required to use `nucypher cloudworkers *` commands. (Please run 'pip install ansible'.)", color="red") return STAKEHOLDER = staker_options.create_character(emitter, config_file) config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file) stakers = STAKEHOLDER.get_stakers() staker_addresses = filter_staker_addresses(stakers, stakes) deployer.get_worker_status(staker_addresses)
def destroy(general_config, staker_options, config_file, cloudprovider, stakes): """Cleans up all previously created resources for the given netork for the cloud providern""" emitter = setup_emitter(general_config) if not CloudDeployers: emitter.echo("Ansible is required to use `nucypher cloudworkers *` commands. (Please run 'pip install ansible'.)", color="red") return STAKEHOLDER = staker_options.create_character(emitter, config_file) stakers = STAKEHOLDER.get_stakers() if not stakers: emitter.echo("No staking accounts found.") return staker_addresses = filter_staker_addresses(stakers, stakes) config_file = config_file or StakeHolderConfiguration.default_filepath() deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file) deployer.destroy_resources(staker_addresses=staker_addresses)