Add error messages to the new register_peers command

This commit is contained in:
Jeff Bradberry
2022-01-06 15:39:16 -05:00
parent ce5aefd3d8
commit fc2a5224ef

View File

@@ -16,10 +16,11 @@ class Command(BaseCommand):
def handle(self, **options): def handle(self, **options):
nodes = Instance.objects.in_bulk(field_name='hostname') nodes = Instance.objects.in_bulk(field_name='hostname')
if options['source'] not in nodes: if options['source'] not in nodes:
raise CommandError() raise CommandError(f"Host {options['source']} is not a registered instance.")
missing_peers = set(options['peers']) - set(nodes) missing_peers = set(options['peers']) - set(nodes)
if missing_peers: if missing_peers:
raise CommandError() missing = ' '.join(missing_peers)
raise CommandError(f"Peers not currently registered as instances: {missing}")
results = 0 results = 0
for target in options['peers']: for target in options['peers']: