mirror of
https://github.com/ansible/awx.git
synced 2026-05-22 08:17:39 -02:30
Working instance registration.
This commit is contained in:
@@ -59,13 +59,28 @@ class Command(BaseCommand):
|
|||||||
'%s instance.' % instance.role)
|
'%s instance.' % instance.role)
|
||||||
|
|
||||||
# If this instance is being set to primary and a *different* primary
|
# If this instance is being set to primary and a *different* primary
|
||||||
# machine already exists, then error out if we're supposed to be timid.
|
# machine alreadyexists, error out if we're supposed to be timid.
|
||||||
if timid and instance.primary and primaries:
|
if timid and options['primary'] and primaries:
|
||||||
raise CommandError('Another instance is already registered as '
|
raise CommandError('Another instance is already registered as '
|
||||||
'primary.')
|
'primary.')
|
||||||
|
|
||||||
# Lastly, if there are no primary machines at all, then don't allow
|
# Lastly, if there are no primary machines at all, then don't allow
|
||||||
# this to be registered as a secondary machine.
|
# this to be registered as a secondary machine.
|
||||||
if not instance.primary and not primaries:
|
if not options['primary'] and not primaries:
|
||||||
raise CommandError('Unable to register a secondary machine until '
|
raise CommandError('Unable to register a secondary machine until '
|
||||||
'a primary machine has been registered')
|
'another primary machine has been registered.')
|
||||||
|
|
||||||
|
# If this is a primary machine and there is another primary machine,
|
||||||
|
# it must be de-primary-ified.
|
||||||
|
if options['primary'] and primaries:
|
||||||
|
for old_primary in other_instances.filter(primary=True):
|
||||||
|
old_primary.primary = False
|
||||||
|
old_primary.save()
|
||||||
|
|
||||||
|
# Okay, we've checked for appropriate errata; perform the registration.
|
||||||
|
dirty = instance.primary is not options['primary']
|
||||||
|
instance.primary = options['primary']
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
print('Instance %s registered (changed: %r).' % (uuid, dirty))
|
||||||
|
|||||||
Reference in New Issue
Block a user