From: garciadeblas Date: Thu, 3 Apr 2025 21:57:04 +0000 (+0200) Subject: Add default profile creation during cluster registration X-Git-Tag: v18.0.0~22 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F15156%2F4;p=osm%2FNBI.git Add default profile creation during cluster registration Change-Id: I5d8aff64e564dd1cf2e13f67736e6110a633f164 Signed-off-by: garciadeblas --- diff --git a/osm_nbi/k8s_topics.py b/osm_nbi/k8s_topics.py index 85ea565..fab9e6c 100644 --- a/osm_nbi/k8s_topics.py +++ b/osm_nbi/k8s_topics.py @@ -578,6 +578,10 @@ class ClusterOpsTopic(ACMTopic): def __init__(self, db, fs, msg, auth): super().__init__(db, fs, msg, auth) + self.infra_contr_topic = InfraContTopic(db, fs, msg, auth) + self.infra_conf_topic = InfraConfTopic(db, fs, msg, auth) + self.resource_topic = ResourceTopic(db, fs, msg, auth) + self.app_topic = AppTopic(db, fs, msg, auth) @staticmethod def format_on_new(content, project_id=None, make_public=False): @@ -600,7 +604,9 @@ class ClusterOpsTopic(ACMTopic): operation_params = cls_add_request step = "filling cluster details from input data" - cls_add_request = self._add_cluster(cls_add_request, session) + cls_add_request = self._add_cluster( + cls_add_request, rollback, session, indata, kwargs, headers + ) step = "registering the cluster at database" self.format_on_new( @@ -637,12 +643,32 @@ class ClusterOpsTopic(ACMTopic): ) as e: raise type(e)("{} while '{}'".format(e, step), http_code=e.http_code) - def _add_cluster(self, cls_add_request, session): + def _add_cluster(self, cls_add_request, rollback, session, indata, kwargs, headers): cls_add = { "name": cls_add_request["name"], "credentials": cls_add_request["credentials"], "vim_account": cls_add_request["vim_account"], "bootstrap": cls_add_request["bootstrap"], + "infra_controller_profiles": [ + self._create_default_profiles( + rollback, session, indata, kwargs, headers, self.infra_contr_topic + ) + ], + "infra_config_profiles": [ + self._create_default_profiles( + rollback, session, indata, kwargs, headers, self.infra_conf_topic + ) + ], + "resource_profiles": [ + self._create_default_profiles( + rollback, session, indata, kwargs, headers, self.resource_topic + ) + ], + "app_profiles": [ + self._create_default_profiles( + rollback, session, indata, kwargs, headers, self.app_topic + ) + ], "created": "false", "state": "IN_CREATION", "operatingState": "PROCESSING", @@ -654,6 +680,35 @@ class ClusterOpsTopic(ACMTopic): cls_add["description"] = cls_add_request["description"] return cls_add + def check_vim(self, session, name): + try: + vim_account_details = self.db.get_one("vim_accounts", {"name": name}) + if vim_account_details is not None: + return name + except ValidationError as e: + raise EngineException( + e, + HTTPStatus.UNPROCESSABLE_ENTITY, + ) + + def _create_default_profiles( + self, rollback, session, indata, kwargs, headers, topic + ): + topic = self.to_select_topic(topic) + default_profiles = topic.default(rollback, session, indata, kwargs, headers) + return default_profiles + + def to_select_topic(self, topic): + if topic == "infra_controller_profiles": + topic = self.infra_contr_topic + elif topic == "infra_config_profiles": + topic = self.infra_conf_topic + elif topic == "resource_profiles": + topic = self.resource_topic + elif topic == "app_profiles": + topic = self.app_topic + return topic + def remove(self, session, _id, dry_run=False, not_send_msg=None): """ Delete item by its internal _id