2 # -*- coding: utf-8 -*-
3 # SPDX-License-Identifier: Apache-2.0
4 """Onap Policy module."""
6 from dataclasses import dataclass
7 from typing import Dict
8 from oransdk.configuration import settings
9 from onapsdk.onap_service import OnapService
13 """PolicyType dataclass."""
19 class OranPolicy(OnapService):
20 """Onap Policy library."""
22 pap_url = settings.POLICY_PAP_URL
23 api_url = settings.POLICY_API_URL
24 header = {"Accept": "application/json", "Content-Type": "application/json"}
27 def get_components_status(cls,
28 basic_auth: Dict[str, str]) -> Dict:
30 Get status of Policy component.
33 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
36 the status of the Policy component
39 url = f"{cls.pap_url}/policy/pap/v1/components/healthcheck"
40 status = cls.send_message_json('GET',
41 'Get status of Policy component',
43 basic_auth=basic_auth)
47 def get_policy_status(cls,
48 basic_auth: Dict[str, str]) -> Dict:
50 Get status of all the policies.
53 the status of all the policies
56 url = f"{cls.pap_url}/policy/pap/v1/policies/status"
57 status = cls.send_message_json('GET',
58 'Get status of all the policies',
60 basic_auth=basic_auth)
65 policy_type: PolicyType,
68 basic_auth: Dict[str, str]) -> Dict:
73 policy_type: the policy type
74 policy_name: the policy name
75 policy_version: the version of the policy
76 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
82 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/versions/"\
83 + f"{policy_type.version}/policies/{policy_name}/versions/{policy_version}"
84 policy = cls.send_message_json('GET',
87 basic_auth=basic_auth)
91 def create_policy(cls,
92 policy_type: PolicyType,
94 basic_auth: Dict[str, str]) -> None:
99 policy_type: the policy type
100 type_version: the version of the policy type
101 policy_data: the policy to be created, in binary format
104 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/"\
105 + f"versions/{policy_type.version}/policies"
106 cls.send_message('POST',
111 basic_auth=basic_auth)
114 def deploy_policy(cls,
116 basic_auth: Dict[str, str]) -> None:
121 policy_data: the policy to be deployed, in binary format
124 url = f"{cls.pap_url}/policy/pap/v1/pdps/policies"
125 cls.send_message('POST',
130 basic_auth=basic_auth)