Add cofig-assign and config-deploy to cds workflow
[demo.git] / heat / vFW_CNF_CDS / automation / so_db_adapter.py
1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2020 Orange
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # ============LICENSE_END=========================================================
17
18 from abc import ABC
19 from onapsdk.so.so_element import SoElement
20 from onapsdk.onap_service import OnapService
21 from onapsdk.utils.headers_creator import headers_so_creator
22
23
24 class SoDBUpdate(SoElement, ABC):
25
26     @classmethod
27     def add_region_to_so_db(cls,
28                             cloud_region_id: str,
29                             complex_id: str,
30                             identity_service_id: str = None,
31                             **kwargs
32                             ):
33         """Method to add cloud_site data with identity_service to SO db.
34
35         Args:
36             cloud_region_id: the name of cloud region
37             complex_id: name of complex
38             identity_service_id: optional - id of identity service
39             **kwargs: keyword arguments with parameters for identity service creation, like below
40
41         Important:
42             identity_services data will be overwrite, but in the same time
43             cloud_sites data will not (shouldn't) be overwrite!
44
45         Return:
46             response object
47         """
48
49         if not identity_service_id:
50             identity_service_id = 'Keystone_K8s'
51
52         # params for identity_service creation
53         orchestrator = kwargs.get('orchestrator', 'multicloud')
54         identity_url = kwargs.get('identity_url', "http://1.2.3.4:5000/v2.0")
55         mso_id = kwargs.get('mso_id', 'onapsdk_user')
56         mso_pass = kwargs.get('mso_pass', 'mso_pass_onapsdk')
57         project_domain_name = kwargs.get("project_domain_name", None)
58         user_domain_name = kwargs.get("user_domain_name", None)
59         member_role = kwargs.get('member_role', 'admin')
60         admin_tenant = kwargs.get('admin_tenant', 'service')
61         identity_server_type = kwargs.get('identity_server_type', 'KEYSTONE')
62         identity_authentication_type = kwargs.get('identity_authentication_type', 'USERNAME_PASSWORD')
63
64         data = {
65             "id": cloud_region_id,
66             "region_id": cloud_region_id,
67             "aic_version": "2.5",
68             "clli": complex_id,
69             "orchestrator": orchestrator,
70             "identityService": {
71                 "id": identity_service_id,
72                 "identityServerTypeAsString": "KEYSTONE",
73                 "hibernateLazyInitializer": {},
74                 "identity_url": identity_url,
75                 "mso_id": mso_id,
76                 "mso_pass": mso_pass,
77                 "project_domain_name": project_domain_name,
78                 "user_domain_name": user_domain_name,
79                 "admin_tenant": admin_tenant,
80                 "member_role": member_role,
81                 "tenant_metadata": True,
82                 "identity_server_type": identity_server_type,
83                 "identity_authentication_type": identity_authentication_type
84             }
85         }
86
87         response = cls.send_message(
88             "POST",
89             "Create a region in SO db",
90             f"{cls.base_url}/cloudSite",
91             json=data,
92             headers=headers_so_creator(OnapService.headers),
93             exception=ValueError)
94
95         return response