25458c62aac983e413a9ba6b879c7bfbd5e6cd11
[it/dep.git] / smo-install / test / pythonsdk / src / oransdk / a1policymanagement / a1policymanagement.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # SPDX-License-Identifier: Apache-2.0
4 """ONAP A1 Policy Management."""
5
6 from typing import Dict
7 from oransdk.configuration import settings
8 from onapsdk.onap_service import OnapService
9
10 class A1policymanagement(OnapService):
11     """A1 Policy Management library."""
12
13     base_url = settings.A1_POLICY_MANAGEMENT_URL
14     header = {"Accept":"application/json", "Content-Type":"application/json"}
15
16     @classmethod
17     def check_status(cls) -> str:
18         """
19         Get the status of the A1 policy management component.
20
21         Returns:
22             the status of the A1 policy management component
23
24         """
25         url = f"{cls.base_url}/status"
26         status = cls.send_message('GET',
27                                   'Get A1 policy management status',
28                                   url)
29         return status
30
31     @classmethod
32     def get_policy_types(cls) -> Dict:
33         """
34         Get all the policy types.
35
36         Returns:
37             the list of policy types
38
39         """
40         url = f"{cls.base_url}/policy_types"
41         policy_types = cls.send_message_json('GET',
42                                              'Get all the policy types',
43                                              url)
44         return policy_types
45
46     @classmethod
47     def get_policy_type_agent(cls) -> Dict:
48         """
49         Get all the policy types from policy agent.
50
51         Returns:
52             the list of policy types
53
54         """
55         url = f"{cls.base_url}/a1-policy/v2/policy-types"
56         policy_types = cls.send_message_json('GET',
57                                              'Get all the policy types from policy agent',
58                                              url)
59         return policy_types
60
61     @classmethod
62     def get_policy(cls, policy_id) -> Dict:
63         """
64         Get policy.
65
66         Args:
67            type: the policy id
68
69         Returns:
70             the details of the policy
71
72         """
73         url = f"{cls.base_url}/a1-policy/v2/policies/{policy_id}"
74         policy = cls.send_message_json('GET',
75                                        'Get the policy with policy id',
76                                        url)
77         return policy
78
79
80     @classmethod
81     def create_service(cls,
82                        service_data) -> None:
83         """
84         Create service.
85
86         Args:
87            service_data: the service data in binary format
88
89         """
90         url = f"{cls.base_url}/a1-policy/v2/services"
91         cls.send_message('PUT',
92                          'Create Service',
93                          url,
94                          data=service_data,
95                          headers=cls.header)
96
97     @classmethod
98     def create_policy(cls,
99                       policy_data) -> None:
100         """
101         Create policy.
102
103         Args:
104            policy_data: the policy data in binary format
105
106         """
107         url = f"{cls.base_url}/a1-policy/v2/policies"
108         cls.send_message('PUT',
109                          'Create Policy',
110                          url,
111                          data=policy_data,
112                          headers=cls.header)