X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fviews%2Focloud_view.py;h=15a6e1def57d262f077828e6467cbd7bb656a9d0;hb=76a5a4a59a09dab75b7584c787c14d89f7a0a180;hp=52161259ad741ed75cc77c1a3cddf548ae608d4f;hpb=39e022d709689d2fc02d892707971ae852fc55ea;p=pti%2Fo2.git diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index 5216125..15a6e1d 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -186,6 +186,7 @@ def deployment_manager_one(deploymentManagerId: str, def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: + shared_folder = config.get_containers_shared_folder() data = config.gen_k8s_config_dict( kubeconfig.pop('cluster_api_endpoint', None), @@ -204,6 +205,7 @@ def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: current_time = datetime.now().strftime("%Y%m%d%H%M%S") tmp_file_name = 'kubeconfig_' + name_key + "_" + current_time kube_config_name = 'kubeconfig_' + name_key + '.config' + kube_config_path = f'{shared_folder}/{kube_config_name}' # write down the yaml file of kubectl into tmp folder with open('/tmp/' + tmp_file_name, 'w') as file: @@ -211,12 +213,12 @@ def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: # generate the kube config file if not exist or update the file if it # changes - if not os.path.exists('/configs/' + kube_config_name) or not \ - filecmp.cmp('/tmp/'+tmp_file_name, '/configs/'+kube_config_name): + if not os.path.exists(kube_config_path) or not \ + filecmp.cmp('/tmp/'+tmp_file_name, kube_config_path): shutil.move(os.path.join('/tmp', tmp_file_name), - os.path.join('/configs', kube_config_name)) + os.path.join(shared_folder, kube_config_name)) - return '/configs/'+kube_config_name + return kube_config_path def subscriptions(uow: unit_of_work.AbstractUnitOfWork, **kwargs): @@ -241,7 +243,7 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, filter = subscriptionDto.get('filter', '') consumer_subs_id = subscriptionDto.get('consumerSubscriptionId', '') - check_filter(ocloud.Resource, filter) + _check_subscription_filter(filter) sub_uuid = str(uuid.uuid4()) subscription = Subscription( @@ -263,6 +265,62 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, return first.serialize() +def _check_subscription_filter(filter: str): + if not filter: + return + + def _sub_filter_checking(sub_filter: str): + exprs = sub_filter.split(';') + objectType = False + objectTypeValue = '' + for expr in exprs: + expr_strip = expr.strip(' ()') + items = expr_strip.split(',') + if len(items) < 3: + raise BadRequestException("invalid filter {}".format(expr)) + item_key = items[1].strip() + if item_key != 'objectType': + continue + item_op = items[0].strip() + if item_op != 'eq': + raise BadRequestException( + "Filter objectType only support 'eq' operation") + objectType = True + objectTypeValue = items[2].strip() + if not objectType: + # if there has no objectType specific, by default is ResourceInfo + check_filter(ocloud.Resource, sub_filter) + # return 'ResourceInfo' + return + if objectTypeValue == 'ResourceTypeInfo': + check_filter(ocloud.ResourceType, sub_filter) + elif objectTypeValue == 'ResourcePoolInfo': + check_filter(ocloud.ResourcePool, sub_filter) + elif objectTypeValue == 'DeploymentManagerInfo': + check_filter(ocloud.DeploymentManager, sub_filter) + elif objectTypeValue == 'CloudInfo': + check_filter(ocloud.Ocloud, sub_filter) + elif objectTypeValue == 'ResourceInfo': + check_filter(ocloud.Resource, sub_filter) + else: + raise BadRequestException( + "Filter ObjectType {} not support.".format(items[2])) + # return objectTypeValue + filter_strip = filter.strip(' []') + filter_list = filter_strip.split('|') + # check_duplication = dict() + for sub_filter in filter_list: + _sub_filter_checking(sub_filter) + # obj_type = _sub_filter_checking(sub_filter) + # if obj_type not in check_duplication: + # check_duplication[obj_type] = 0 + # check_duplication[obj_type] += 1 + # if check_duplication[obj_type] > 1: + # raise BadRequestException( + # "Filter objectType {} only support one in each." + # .format(obj_type)) + + def subscription_delete(subscriptionId: str, uow: unit_of_work.AbstractUnitOfWork): with uow: