# ============LICENSE_START===================================================
-# Copyright (C) 2021 Nordix Foundation.
+# Copyright (C) 2021-2022 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# ============LICENSE_END=====================================================
from mod import db, aai_client, logger
-from mod.api.db_models import NetworkFunctionModel
+from mod.api.db_models import NetworkFunctionModel, NetworkFunctionFilterModel
from mod.pmsh_config import AppConfig
from mod.network_function import NetworkFunctionFilter
Args:
sub_name (string): The name of subscription inorder to perform filtering
Returns:
- list[NetworkFunction]: a list of filtered NetworkFunction Objects.
+ list[NetworkFunction]: a list of filtered NetworkFunction Objects
+ or an empty list if no network function is filtered.
"""
logger.info(f'Getting filtered nfs for subscription: {sub_name}')
nf_filter = NetworkFunctionFilter.get_network_function_filter(sub_name)
sdnc_model_name=nf.sdnc_model_name,
sdnc_model_version=nf.sdnc_model_version)
db.session.add(network_function)
+
+
+def save_nf_filter_update(sub_name, nf_filter):
+ """
+ Updates the network function filter for the subscription in the db
+
+ Args:
+ sub_name (String): Name of the Subscription
+ nf_filter (dict): filter object to update in the subscription
+ """
+ NetworkFunctionFilterModel.query.filter(
+ NetworkFunctionFilterModel.subscription_name == sub_name). \
+ update({NetworkFunctionFilterModel.nf_names: nf_filter['nfNames'],
+ NetworkFunctionFilterModel.model_invariant_ids: nf_filter['modelInvariantIDs'],
+ NetworkFunctionFilterModel.model_version_ids: nf_filter['modelVersionIDs'],
+ NetworkFunctionFilterModel.model_names: nf_filter['modelNames']},
+ synchronize_session='evaluate')
+ db.session.commit()
+ logger.info(f'Successfully saved filter for subscription: {sub_name}')