vFW CNF CDS usecase automation scripts update
[demo.git] / heat / vFW_CNF_CDS / 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
26
27 logger = logging.getLogger("")
28 logger.setLevel(logging.DEBUG)
29 fh = logging.StreamHandler()
30 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
31 fh.setFormatter(fh_formatter)
32 logger.addHandler(fh)
33
34
35 def update_cba(file):
36     mypath = os.path.dirname(os.path.realpath(__file__))
37     file_path = os.path.join(mypath, file)
38     try:
39         with zipfile.ZipFile(file_path, 'r') as package:
40             cba_io = BytesIO(package.read("CBA.zip"))
41
42         blueprint = Blueprint(cba_io)
43         blueprint.publish()
44     except FileNotFoundError:
45         logger.error("Error - File Not Found")
46         exit(1)
47
48
49 def main():
50     update_cba(Config.VSPFILE)
51
52
53 if __name__ == "__main__":
54     main()