Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame^] | 1 | import os |
| 2 | from default import TOSCA_DEFS_DIR |
| 3 | from xosgenx.generator import XOSGenerator |
| 4 | from xosapi.xos_grpc_client import Empty |
| 5 | |
| 6 | class Args: |
| 7 | pass |
| 8 | |
| 9 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
| 10 | |
| 11 | class TOSCA_Generator: |
| 12 | |
| 13 | def _clean(self, dir=TOSCA_DEFS_DIR): |
| 14 | filesToRemove = [f for f in os.listdir(dir)] |
| 15 | for f in filesToRemove: |
| 16 | if not f.startswith('.'): |
| 17 | os.remove(dir + '/' + f) |
| 18 | |
| 19 | def generate(self, client): |
| 20 | print "[XOS-TOSCA] Generating TOSCA" |
| 21 | self._clean() |
| 22 | xproto = client.utility.GetXproto(Empty()) |
| 23 | |
| 24 | try: |
| 25 | args = Args() |
| 26 | args.output = TOSCA_DEFS_DIR |
| 27 | args.inputs = str(xproto.xproto) |
| 28 | args.target = os.path.join(current_dir, 'xtarget/tosca.xtarget') |
| 29 | args.write_to_file = 'model' |
| 30 | args.dest_extension = 'yaml' |
| 31 | XOSGenerator.generate(args) |
| 32 | print "[XOS-TOSCA] Recipes generated in %s" % args.output |
| 33 | except Exception as e: |
| 34 | print "[XOS-TOSCA] Failed to generate TOSCA" |
| 35 | print e |
| 36 | |