mirror of
https://github.com/ansible/awx.git
synced 2026-03-14 07:27:28 -02:30
Explicit db field for is_container_group
We now have Container Groups that dont require a credential.
This commit is contained in:
@@ -4776,8 +4776,7 @@ class InstanceGroupSerializer(BaseSerializer):
|
||||
)
|
||||
is_container_group = serializers.BooleanField(
|
||||
help_text=_('Indicates whether instances in this group are containerized.'
|
||||
'Containerized groups have a designated Openshift or Kubernetes cluster.'),
|
||||
read_only=True
|
||||
'Containerized groups have a designated Openshift or Kubernetes cluster.')
|
||||
)
|
||||
# NOTE: help_text is duplicated from field definitions, no obvious way of
|
||||
# both defining field details here and also getting the field's help_text
|
||||
@@ -4853,6 +4852,15 @@ class InstanceGroupSerializer(BaseSerializer):
|
||||
raise serializers.ValidationError(_('Only Kubernetes credentials can be associated with an Instance Group'))
|
||||
return value
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs = super(InstanceGroupSerializer, self).validate(attrs)
|
||||
|
||||
if attrs.get('credential') and not attrs.get('is_container_group'):
|
||||
raise serializers.ValidationError({'is_container_group': _(
|
||||
'is_container_group must be True when associating a credential to an Instance Group')})
|
||||
|
||||
return attrs
|
||||
|
||||
def get_capacity_dict(self):
|
||||
# Store capacity values (globally computed) in the context
|
||||
if 'capacity_map' not in self.context:
|
||||
|
||||
@@ -17,13 +17,14 @@ class InstanceNotFound(Exception):
|
||||
|
||||
|
||||
class RegisterQueue:
|
||||
def __init__(self, queuename, controller, instance_percent, inst_min, hostname_list):
|
||||
def __init__(self, queuename, controller, instance_percent, inst_min, hostname_list, is_container_group=None):
|
||||
self.instance_not_found_err = None
|
||||
self.queuename = queuename
|
||||
self.controller = controller
|
||||
self.instance_percent = instance_percent
|
||||
self.instance_min = inst_min
|
||||
self.hostname_list = hostname_list
|
||||
self.is_container_group = is_container_group
|
||||
|
||||
def get_create_update_instance_group(self):
|
||||
created = False
|
||||
@@ -36,6 +37,10 @@ class RegisterQueue:
|
||||
ig.policy_instance_minimum = self.instance_min
|
||||
changed = True
|
||||
|
||||
if self.is_container_group:
|
||||
ig.is_container_group = self.is_container_group
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
ig.save()
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ class InstanceManager(models.Manager):
|
||||
from awx.main.management.commands.register_queue import RegisterQueue
|
||||
pod_ip = os.environ.get('MY_POD_IP')
|
||||
registered = self.register(ip_address=pod_ip)
|
||||
RegisterQueue('tower', None, 100, 0, []).register()
|
||||
is_container_group = settings.IS_K8S
|
||||
RegisterQueue('tower', None, 100, 0, [], is_container_group).register()
|
||||
return registered
|
||||
else:
|
||||
return (False, self.me())
|
||||
|
||||
27
awx/main/migrations/0132_instancegroup_is_container_group.py
Normal file
27
awx/main/migrations/0132_instancegroup_is_container_group.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 2.2.16 on 2021-03-13 14:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_existing_container_groups(apps, schema_editor):
|
||||
InstanceGroup = apps.get_model('main', 'InstanceGroup')
|
||||
|
||||
for group in InstanceGroup.objects.filter(credential__isnull=False).iterator():
|
||||
group.is_container_group = True
|
||||
group.save(update_fields=['is_container_group'])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0131_undo_org_polymorphic_ee'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='instancegroup',
|
||||
name='is_container_group',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.RunPython(migrate_existing_container_groups, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -199,6 +199,9 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
||||
null=True,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
is_container_group = models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
credential = models.ForeignKey(
|
||||
'Credential',
|
||||
related_name='%(class)ss',
|
||||
@@ -253,13 +256,6 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
||||
def is_isolated(self):
|
||||
return bool(self.controller)
|
||||
|
||||
@property
|
||||
def is_container_group(self):
|
||||
if settings.IS_K8S:
|
||||
return True
|
||||
|
||||
return bool(self.credential and self.credential.kubernetes)
|
||||
|
||||
'''
|
||||
RelatedJobsMixin
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user