Matteo Scandolo | 920e8fd | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 17 | import os |
Matteo Scandolo | 1bd1076 | 2017-10-18 09:53:14 +0200 | [diff] [blame] | 18 | from default import TOSCA_DEFS_DIR, TOSCA_KEYS_DIR |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 19 | from xosgenx.generator import XOSProcessor |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 20 | from xosapi.xos_grpc_client import Empty |
| 21 | |
| 22 | class Args: |
| 23 | pass |
| 24 | |
| 25 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
| 26 | |
| 27 | class TOSCA_Generator: |
| 28 | |
Scott Baker | 3f7739c | 2018-02-20 20:17:34 -0800 | [diff] [blame] | 29 | def clean(self, dir=TOSCA_DEFS_DIR): |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 30 | filesToRemove = [f for f in os.listdir(dir)] |
| 31 | for f in filesToRemove: |
| 32 | if not f.startswith('.'): |
| 33 | os.remove(dir + '/' + f) |
| 34 | |
Scott Baker | 3f7739c | 2018-02-20 20:17:34 -0800 | [diff] [blame] | 35 | def clean_keys(self, dir=TOSCA_KEYS_DIR): |
| 36 | keys_fn = os.path.join(dir, "KEYS.py") |
| 37 | if os.path.exists(keys_fn): |
| 38 | os.remove(keys_fn) |
| 39 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 40 | def generate(self, client): |
| 41 | print "[XOS-TOSCA] Generating TOSCA" |
Matteo Scandolo | 2c1a001 | 2017-09-12 17:08:04 -0700 | [diff] [blame] | 42 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 43 | try: |
Matteo Scandolo | 2c1a001 | 2017-09-12 17:08:04 -0700 | [diff] [blame] | 44 | xproto = client.utility.GetXproto(Empty()) |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 45 | args = Args() |
| 46 | args.output = TOSCA_DEFS_DIR |
| 47 | args.inputs = str(xproto.xproto) |
| 48 | args.target = os.path.join(current_dir, 'xtarget/tosca.xtarget') |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 49 | args.write_to_file = 'target' |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 50 | XOSProcessor.process(args) |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 51 | print "[XOS-TOSCA] Recipes generated in %s" % args.output |
| 52 | except Exception as e: |
| 53 | print "[XOS-TOSCA] Failed to generate TOSCA" |
| 54 | print e |
| 55 | |
Matteo Scandolo | 1bd1076 | 2017-10-18 09:53:14 +0200 | [diff] [blame] | 56 | try: |
| 57 | xproto = client.utility.GetXproto(Empty()) |
| 58 | args = Args() |
| 59 | args.output = TOSCA_KEYS_DIR |
| 60 | args.inputs = str(xproto.xproto) |
| 61 | args.target = os.path.join(current_dir, 'xtarget/tosca_keys.xtarget') |
| 62 | args.write_to_file = 'single' |
| 63 | args.dest_file = 'KEYS.py' |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 64 | XOSProcessor.process(args) |
Matteo Scandolo | 1bd1076 | 2017-10-18 09:53:14 +0200 | [diff] [blame] | 65 | print "[XOS-TOSCA] TOSCA Keys generated in %s" % args.output |
| 66 | except Exception as e: |
| 67 | print "[XOS-TOSCA] Failed to generate TOSCA Keys" |
| 68 | print e |
| 69 | |