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 |
| 18 | from default import TOSCA_DEFS_DIR |
| 19 | from xosgenx.generator import XOSGenerator |
| 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 | |
| 29 | def _clean(self, dir=TOSCA_DEFS_DIR): |
| 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 | |
| 35 | def generate(self, client): |
| 36 | print "[XOS-TOSCA] Generating TOSCA" |
| 37 | self._clean() |
| 38 | xproto = client.utility.GetXproto(Empty()) |
| 39 | |
| 40 | try: |
| 41 | args = Args() |
| 42 | args.output = TOSCA_DEFS_DIR |
| 43 | args.inputs = str(xproto.xproto) |
| 44 | args.target = os.path.join(current_dir, 'xtarget/tosca.xtarget') |
| 45 | args.write_to_file = 'model' |
| 46 | args.dest_extension = 'yaml' |
| 47 | XOSGenerator.generate(args) |
| 48 | print "[XOS-TOSCA] Recipes generated in %s" % args.output |
| 49 | except Exception as e: |
| 50 | print "[XOS-TOSCA] Failed to generate TOSCA" |
| 51 | print e |
| 52 | |