[APACHE] Add Apache CNF use case files
[demo.git] / tutorials / ApacheCNF / automation / update_cba.py
1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2021 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 import logging
19 import os
20 import zipfile
21 from io import BytesIO
22
23 from onapsdk.cds import Blueprint
24
25 from config import Config, VariablesDict
26
27 logger = logging.getLogger()
28 logger.setLevel(logging.DEBUG)
29
30
31 def update_cba(file):
32     mypath = os.path.dirname(os.path.realpath(__file__))
33     file_path = os.path.join(mypath, file)
34     try:
35         with zipfile.ZipFile(file_path, 'r') as package:
36             cba_io = BytesIO(package.read("CBA.zip"))
37
38         blueprint = Blueprint(cba_io)
39         blueprint.deploy()
40     except FileNotFoundError:
41         logger.error("Error - File Not Found")
42         exit(1)
43
44
45 def main():
46     config = Config(env_dict=VariablesDict.env_variable)
47     for vnf in config.service_model["vnfs"]:
48         update_cba(vnf["vsp"]["vsp_file"])
49
50
51 if __name__ == "__main__":
52     sh = logging.StreamHandler()
53     sh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
54     sh.setFormatter(sh_formatter)
55     logger.addHandler(sh)
56
57     main()