3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
24 """Onap Policy module."""
26 from dataclasses import dataclass
27 from typing import Dict
28 from onapsdk.onap_service import OnapService
29 from oransdk.configuration import settings
33 """PolicyType dataclass."""
39 class OranPolicy(OnapService):
40 """Onap Policy library."""
42 pap_url = settings.POLICY_PAP_URL
43 api_url = settings.POLICY_API_URL
44 header = {"Accept": "application/json", "Content-Type": "application/json"}
47 def get_components_status(cls,
48 basic_auth: Dict[str, str]) -> Dict:
50 Get status of Policy component.
53 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
56 the status of the Policy component
59 url = f"{cls.pap_url}/policy/pap/v1/components/healthcheck"
60 status = cls.send_message_json('GET',
61 'Get status of Policy component',
63 basic_auth=basic_auth)
67 def get_policy_status(cls,
68 basic_auth: Dict[str, str]) -> Dict:
70 Get status of all the policies.
73 the status of all the policies
76 url = f"{cls.pap_url}/policy/pap/v1/policies/status"
77 status = cls.send_message_json('GET',
78 'Get status of all the policies',
80 basic_auth=basic_auth)
85 policy_type: PolicyType,
88 basic_auth: Dict[str, str]) -> Dict:
93 policy_type: the policy type
94 policy_name: the policy name
95 policy_version: the version of the policy
96 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
102 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/versions/"\
103 + f"{policy_type.version}/policies/{policy_name}/versions/{policy_version}"
104 policy = cls.send_message_json('GET',
107 basic_auth=basic_auth)
111 def create_policy(cls,
112 policy_type: PolicyType,
114 basic_auth: Dict[str, str]) -> None:
119 policy_type: the policy type
120 type_version: the version of the policy type
121 policy_data: the policy to be created, in binary format
124 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/"\
125 + f"versions/{policy_type.version}/policies"
126 cls.send_message('POST',
131 basic_auth=basic_auth)
134 def deploy_policy(cls,
136 basic_auth: Dict[str, str]) -> None:
141 policy_data: the policy to be deployed, in binary format
144 url = f"{cls.pap_url}/policy/pap/v1/pdps/policies"
145 cls.send_message('POST',
150 basic_auth=basic_auth)