feat(itim): Ensure cluster cant assign itself as parent on api v2 endpoint
ref: #248 #356
This commit is contained in:
@ -213,6 +213,7 @@ class Cluster(TenancyObject):
|
|||||||
],
|
],
|
||||||
"right": [
|
"right": [
|
||||||
'model_notes',
|
'model_notes',
|
||||||
|
'resources',
|
||||||
'created',
|
'created',
|
||||||
'modified',
|
'modified',
|
||||||
]
|
]
|
||||||
|
@ -62,7 +62,14 @@ class ClusterModelSerializer(ClusterBaseSerializer):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rendered_config = serializers.JSONField()
|
rendered_config = serializers.JSONField( read_only = True)
|
||||||
|
|
||||||
|
resources = serializers.CharField(
|
||||||
|
label = 'Available Resources',
|
||||||
|
read_only = True,
|
||||||
|
initial = 'xx/yy CPU, xx/yy RAM, xx/yy Storage',
|
||||||
|
default = 'xx/yy CPU, xx/yy RAM, xx/yy Storage',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -77,6 +84,7 @@ class ClusterModelSerializer(ClusterBaseSerializer):
|
|||||||
'model_notes',
|
'model_notes',
|
||||||
'parent_cluster',
|
'parent_cluster',
|
||||||
'cluster_type',
|
'cluster_type',
|
||||||
|
'resources',
|
||||||
'config',
|
'config',
|
||||||
'rendered_config',
|
'rendered_config',
|
||||||
'nodes',
|
'nodes',
|
||||||
@ -91,12 +99,32 @@ class ClusterModelSerializer(ClusterBaseSerializer):
|
|||||||
'id',
|
'id',
|
||||||
'display_name',
|
'display_name',
|
||||||
'rendered_config',
|
'rendered_config',
|
||||||
|
'resources',
|
||||||
'created',
|
'created',
|
||||||
'modified',
|
'modified',
|
||||||
'_urls',
|
'_urls',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid(self, *, raise_exception=False):
|
||||||
|
|
||||||
|
is_valid = super().is_valid(raise_exception=False)
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(self.instance, 'id') and self.validated_data['parent_cluster']:
|
||||||
|
|
||||||
|
if self.validated_data['parent_cluster'].id == self.instance.id:
|
||||||
|
|
||||||
|
is_valid = False
|
||||||
|
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
detail = "Cluster can't have itself as its parent cluster",
|
||||||
|
code = 'parent_not_self'
|
||||||
|
)
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterViewSerializer(ClusterModelSerializer):
|
class ClusterViewSerializer(ClusterModelSerializer):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user