feat(itim): Ability to add configuration to cluster type

ref: #247 closes #71
This commit is contained in:
2024-08-19 14:49:39 +09:30
parent bfb20dab0f
commit 66b8bd5a74
6 changed files with 90 additions and 2 deletions

View File

@ -47,6 +47,16 @@ class DetailForm(ClusterTypeForm):
'model_notes',
]
},
{
"layout": "single",
"name": "Configuration",
"fields": [
'config'
],
"json": [
'config',
]
}
]
},
"notes": {

View File

@ -84,10 +84,10 @@ class DetailForm(ClusterForm):
{
"layout": "single",
"fields": [
'config_variables',
'rendered_config',
],
"json": [
'config_variables'
'rendered_config'
]
}
]
@ -136,6 +136,14 @@ class DetailForm(ClusterForm):
initial = 'xx/yy CPU, xx/yy RAM, xx/yy Storage',
)
self.fields['rendered_config'] = forms.fields.JSONField(
label = 'Available Resources',
disabled = True,
initial = self.instance.rendered_config,
)
self.tabs['details'].update({
"edit_url": reverse('ITIM:_cluster_change', args=(self.instance.pk,))
})

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-08-19 04:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('itim', '0002_clustertype_created_clustertype_modified'),
]
operations = [
migrations.AddField(
model_name='clustertype',
name='config',
field=models.JSONField(blank=True, default=None, help_text='Cluster Type Configuration that is applied to all clusters of this type', null=True, verbose_name='Configuration'),
),
]

View File

@ -39,6 +39,16 @@ class ClusterType(TenancyObject):
slug = AutoSlugField()
config = models.JSONField(
blank = True,
default = None,
help_text = 'Cluster Type Configuration that is applied to all clusters of this type',
null = True,
verbose_name = 'Configuration',
)
created = AutoCreatedField()
modified = AutoLastModifiedField()
@ -131,6 +141,28 @@ class Cluster(TenancyObject):
modified = AutoLastModifiedField()
@property
def rendered_config(self):
rendered_config: dict = {}
if self.cluster_type.config:
rendered_config.update(
self.cluster_type.config
)
if self.config:
rendered_config.update(
self.config
)
return rendered_config
def __str__(self):
return self.name