3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 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 Clamp Tosca Template module."""
26 from typing import Dict
27 from onapsdk.clamp.clamp_element import Clamp
29 class ClampToscaTemplate(Clamp):
30 """Onap Policy Clamp Tosca Template class."""
32 header = {"Accept": "application/json", "Content-Type": "application/json"}
34 def __init__(self, basic_auth: Dict[str, str]) -> None:
36 Initialize loop instance object.
39 basic_auth : basic auth
43 self.basic_auth = basic_auth
45 def get_template_instance(self) -> dict:
47 Get tosca template instance.
50 the tosca template instance
52 url = f"{self.base_url()}/toscaControlLoop/getToscaInstantiation"
53 template_instance = self.send_message_json('GET',
54 'Get tosca template instance',
56 basic_auth=self.basic_auth)
58 return template_instance
60 def upload_commission(self, tosca_template) -> dict:
62 Upload Tosca to commissioning.
65 tosca_template: the tosca template yaml
67 the response of the uploading action
70 url = f"{self.base_url()}/toscaControlLoop/commissionToscaTemplate"
71 response = self.send_message_json('POST',
72 'Upload Tosca to commissioning',
76 basic_auth=self.basic_auth)
79 def create_instance(self, tosca_instance_properties) -> dict:
81 Create Tosca instance.
84 tosca_instance_properties (str): the tosca template properties
86 the response of the creation action
88 url = f"{self.base_url()}/toscaControlLoop/postToscaInstanceProperties"
89 response = self.send_message_json('POST',
90 'Create Tosca instance',
92 data=tosca_instance_properties,
94 basic_auth=self.basic_auth)
97 def get_template_instance_status(self, name, version) -> dict:
99 Get tosca template instance status.
102 name (str): the name of the template instance
103 version (str): the version of the template instance
105 the template instance
107 url = f"{self.base_url()}/toscaControlLoop/getInstantiationOrderState?name={name}&version={version}"
108 template_instance = self.send_message_json('GET',
109 'Get tosca template instance',
111 basic_auth=self.basic_auth)
113 return template_instance
115 def change_instance_status(self, new_status, name, version) -> dict:
117 Update tosca instance status.
120 new_status (str): the new instance status
121 name (str): the new instance name
122 version (str): the new instance version
124 the updated template instance
126 body = '{"orderedState":"' + new_status + '","controlLoopIdentifierList":[{"name":"' + name + '","version":"' + version + '"}]}'
127 url = f"{self.base_url()}/toscaControlLoop/putToscaInstantiationStateChange"
128 response = self.send_message_json('PUT',
129 'Update tosca instance status',
133 basic_auth=self.basic_auth)
136 def delete_template_instance(self, name: str, version: str) -> dict:
138 Delete the tosca instance.
141 name (str): the instance name.
142 version (str): the instance version.
144 the response of the deletion action
146 url = f"{self.base_url()}/toscaControlLoop/deleteToscaInstanceProperties?name={name}&version={version}"
147 response = self.send_message_json('DELETE',
148 'Delete the tosca instance',
151 basic_auth=self.basic_auth)
154 def decommission_template(self, name: str, version: str) -> dict:
156 Decommission the tosca template.
159 name (str): the tosca template name.
160 version (str): the tosca template version.
162 the response of the decommission action
164 url = f"{self.base_url()}/toscaControlLoop/decommissionToscaTemplate?name={name}&version={version}"
165 response = self.send_message_json('DELETE',
166 'Decommission the tosca template',
169 basic_auth=self.basic_auth)