blob: 9e020115a70a8179252fc295a92c67f4e0389edc [file] [log] [blame]
Matteo Scandolo9ce18252017-06-22 10:48:25 -07001import os
2from default import TOSCA_DEFS_DIR
3from xosgenx.generator import XOSGenerator
4from xosapi.xos_grpc_client import Empty
5
6class Args:
7 pass
8
9current_dir = os.path.dirname(os.path.realpath(__file__))
10
11class 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