Skip to content

Commit

Permalink
feat(itim): Ability to add configuration to cluster type
Browse files Browse the repository at this point in the history
ref: #247 closes #71
  • Loading branch information
jon-nfc committed Aug 19, 2024
1 parent e46cf44 commit 08a649b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/itim/forms/cluster_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class DetailForm(ClusterTypeForm):
'model_notes',
]
},
{
"layout": "single",
"name": "Configuration",
"fields": [
'config'
],
"json": [
'config',
]
}
]
},
"notes": {
Expand Down
12 changes: 10 additions & 2 deletions app/itim/forms/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class DetailForm(ClusterForm):
{
"layout": "single",
"fields": [
'config_variables',
'rendered_config',
],
"json": [
'config_variables'
'rendered_config'
]
}
]
Expand Down Expand Up @@ -136,6 +136,14 @@ def __init__(self, *args, **kwargs):
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,))
})
Expand Down
18 changes: 18 additions & 0 deletions app/itim/migrations/0003_clustertype_config.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
32 changes: 32 additions & 0 deletions app/itim/models/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class Meta:

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()
Expand Down Expand Up @@ -131,6 +141,28 @@ class Meta:
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
2 changes: 2 additions & 0 deletions docs/projects/centurion_erp/user/itim/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 18 additions & 0 deletions docs/projects/centurion_erp/user/itim/clustertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 08a649b

Please sign in to comment.