summaryrefslogtreecommitdiffstats
path: root/adapters/policy/utils.py
diff options
context:
space:
mode:
authorAnkitkumar Patel <ankit@research.att.com>2018-02-11 17:51:13 -0500
committerAnkitkumar Patel <ankit@research.att.com>2018-02-11 17:52:51 -0500
commit0b855c08fd98fb8fa0f4bc40d8df430c897b4bad (patch)
treeefdd3c7ab31be64080dd71951a64d13f0ba493de /adapters/policy/utils.py
parentbb8471cae394aa6ff0af8ba3e5354f3b121c56fc (diff)
Re-org folders, onboard test folder, test config
Reorganized the folder structure. Onboarded testcases. Added test config. Issue-ID: OPTFRA-74 Change-Id: I97882a162a405a18ffd287495039e15ae9d0ad7b Signed-off-by: Ankitkumar Patel <ankit@research.att.com>
Diffstat (limited to 'adapters/policy/utils.py')
-rw-r--r--adapters/policy/utils.py58
1 files changed, 0 insertions, 58 deletions
diff --git a/adapters/policy/utils.py b/adapters/policy/utils.py
deleted file mode 100644
index a006f12..0000000
--- a/adapters/policy/utils.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# -------------------------------------------------------------------------
-# Copyright (c) 2015-2017 AT&T Intellectual Property
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# -------------------------------------------------------------------------
-#
-
-from collections import defaultdict
-
-
-def group_policies(flat_policies):
- """Filter policies using the following steps:
- 1. Apply prioritization among the policies that are sharing the same policy type and resource type
- 2. Remove redundant policies that may applicable across different types of resource
- 3. Filter policies based on type and return
- :param flat_policies: list of flat policies
- :return: Filtered policies
- """
- aggregated_policies = {}
- filter_policies = defaultdict(list)
- policy_name = []
- for policy in flat_policies:
- policy_type = policy['content']['type']
- if policy_type not in aggregated_policies:
- aggregated_policies[policy_type] = defaultdict(list)
- for resource in policy['content']['policyScope']['resourceInstanceType']:
- aggregated_policies[policy_type][resource].append(policy)
- for policy_type in aggregated_policies:
- for resource in aggregated_policies[policy_type]:
- if len(aggregated_policies[policy_type][resource]) > 0:
- aggregated_policies[policy_type][resource].sort(key=lambda x: x['priority'], reverse=True)
- policy = aggregated_policies[policy_type][resource][0]
- if policy['policyName'] not in policy_name:
- filter_policies[policy['content']['type']].append(policy)
- policy_name.append(policy['policyName'])
- return filter_policies
-
-
-def _regex_policy_name(policy_name):
- """Get the correct policy name as a regex
- (e.g. OOF_HAS_vCPE.cloudAttributePolicy ends up in policy as OOF_HAS_vCPE.Config_MS_cloudAttributePolicy.1.xml
- So, for now, we query it as OOF_HAS_vCPE..*aicAttributePolicy.*)
- :param policy_name: Example: OOF_HAS_vCPE.aicAttributePolicy
- :return: regexp for policy: Example: OOF_HAS_vCPE..*aicAttributePolicy.*
- """
- p = policy_name.partition('.')
- return p[0] + p[1] + ".*" + p[2] + ".*"