ux improvements

pull/2359/head
damon 2020-10-14 06:35:58 -07:00
parent fbd434da69
commit cf10f3b4bc
2 changed files with 28 additions and 9 deletions

View File

@ -193,7 +193,7 @@ def destroy(general_config, staker_options, config_file, cloudprovider, stakes):
@cloudworkers.command('status')
@group_staker_options
@option_config_file
@click.option('--cloudprovider', help="aws or digitalocean", default='aws')
@click.option('--cloudprovider', help="aws or digitalocean")
@click.option('--include-stakeholder', 'stakes', help="only show nodes for included stakeholder addresses", multiple=True)
@group_general_config
def status(general_config, staker_options, config_file, cloudprovider, stakes):
@ -205,7 +205,7 @@ def status(general_config, staker_options, config_file, cloudprovider, stakes):
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)
deployer = CloudDeployers.get_deployer('generic')(emitter, STAKEHOLDER, config_file)
stakers = STAKEHOLDER.get_stakers()
staker_addresses = filter_staker_addresses(stakers, stakes)

View File

@ -148,6 +148,7 @@ class BaseCloudNodeConfigurator:
sentry_dsn=None,
profile=None,
prometheus=False,
pre_config=False
):
self.emitter = emitter
@ -162,8 +163,10 @@ class BaseCloudNodeConfigurator:
# where we save our state data so we can remember the resources we created for future use
self.config_path = os.path.join(DEFAULT_CONFIG_ROOT, NODE_CONFIG_STORAGE_KEY, self.config_filename)
self.emitter.echo(f"cloudworker config path: {self.config_path}")
if pre_config:
self.config = pre_config
self.namespace = self.config['namespace']
return
if os.path.exists(self.config_path):
self.config = json.load(open(self.config_path))
@ -387,19 +390,29 @@ class BaseCloudNodeConfigurator:
self.update_stakeholder_config()
def update_stakeholder_config(self):
data = {}
data = json.loads(open(self.config['stakeholder_config_file'], 'r').read())
existing_worker_data = data.get('worker_data', {})
existing_worker_data = data.get('worker_data') or {}
existing_worker_data.update(self.config['instances'])
data['worker_data'] = existing_worker_data
with open(self.config['stakeholder_config_file'], 'w') as outfile:
json.dump(data, outfile, indent=4)
def give_helpful_hints(self):
self.emitter.echo("You may wish to ssh into your running hosts:")
for address, n in self.get_all_hosts():
dep = CloudDeployers.get_deployer(n['provider'])(
self.emitter,
self.stakeholder,
self.config['stakeholder_config_file'],
pre_config=self.config
)
self.emitter.echo(f"\t {dep.format_ssh_cmd(n)}", color="yellow")
def format_ssh_cmd(self, hostdata):
user = next(v['value'] for v in hostdata['provider_deploy_attrs'] if v['key'] == 'default_user')
return f"ssh {user}@{hostdata['publicaddress']}"
if self.config.get('keypair_path'):
keypair = self.config['keypair_path']
self.emitter.echo(f'ssh into any node using `ssh ubuntu@<node address> -i "{keypair}"`', color="yellow")
class DigitalOceanConfigurator(BaseCloudNodeConfigurator):
@ -461,6 +474,7 @@ class DigitalOceanConfigurator(BaseCloudNodeConfigurator):
self.emitter.echo("\twaiting for instance to come online...")
instance_public_ip = None
while not instance_public_ip:
time.sleep(1)
@ -474,6 +488,7 @@ class DigitalOceanConfigurator(BaseCloudNodeConfigurator):
if instance_resp.get('networks', {}).get('v4'):
instance_public_ip = next(
(n['ip_address'] for n in instance_resp['networks']['v4'] if n['type'] == 'public'), None)
node_data['publicaddress'] = instance_public_ip
node_data['remote_provider'] = self.config.get('blockchain_provider')
node_data['provider_deploy_attrs']= self._provider_deploy_attrs
return node_data
@ -774,6 +789,10 @@ class AWSNodeConfigurator(BaseCloudNodeConfigurator):
return node_data
def format_ssh_cmd(self, hostdata):
keypair_path = next(v['value'] for v in hostdata['provider_deploy_attrs'] if v['key'] == 'ansible_ssh_private_key_file')
return f'{super().format_ssh_cmd(hostdata)} -i "{keypair_path}"'
class GenericConfigurator(BaseCloudNodeConfigurator):
provider_name = 'generic'