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

View File

@ -59,3 +59,5 @@ A Cluster service is a [service](./service.md) deployed to a cluster. See [#125]
### Configuration
Cluster configuration is configuration that is used by Ansible to setup/deploy the cluster. The configuration is presented by Centurion ERP within a format that is designed for [our collection](../../../ansible/collections/centurion/index.md).
Configuration if applied within the [cluster type](./clustertype.md#configuration) is used as the base and if also defined within the cluster will take precedence. This allows the cluster type configuration to be used as a base template for clusters of the same type.

View File

@ -10,3 +10,21 @@ This component as part of ITIM is for the classification of a [cluster](./cluste
!!! info
This feature is ready for further features if desired. i.e. `Cluster Type` configuration. want to see this log a feature request on github.
## Cluster Type
Within the Cluster Type the following fields are available:
- `Name` _name of the cluster type_
- `Organization` _organization the cluster belongs to_
- `Notes` _model notes for cluster type_
- `configuration` _cluster type config_
## Configuration
Configuration can be applied to the cluster type. This configuration is then treated as a template for all clusters of the same type. If the same configuration key is also defined within the cluster, it will take precedence over the cluster type configuration.