blob: 6aa309c1bb72a44139d6669c62cde0666a28d933 [file] [log] [blame]
Matteo Scandolo920e8fd2017-08-08 13:05:24 -07001
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 Scandolo9ce18252017-06-22 10:48:25 -070017import os
Matteo Scandolo1bd10762017-10-18 09:53:14 +020018from default import TOSCA_DEFS_DIR, TOSCA_KEYS_DIR
Matteo Scandolo9ce18252017-06-22 10:48:25 -070019from xosgenx.generator import XOSGenerator
20from xosapi.xos_grpc_client import Empty
21
22class Args:
23 pass
24
25current_dir = os.path.dirname(os.path.realpath(__file__))
26
27class 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()
Matteo Scandolo2c1a0012017-09-12 17:08:04 -070038
Matteo Scandolo9ce18252017-06-22 10:48:25 -070039 try:
Matteo Scandolo2c1a0012017-09-12 17:08:04 -070040 xproto = client.utility.GetXproto(Empty())
Matteo Scandolo9ce18252017-06-22 10:48:25 -070041 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')
Matteo Scandolocb92e162017-10-03 13:12:30 -070045 args.write_to_file = 'target'
Matteo Scandolo9ce18252017-06-22 10:48:25 -070046 XOSGenerator.generate(args)
47 print "[XOS-TOSCA] Recipes generated in %s" % args.output
48 except Exception as e:
49 print "[XOS-TOSCA] Failed to generate TOSCA"
50 print e
51
Matteo Scandolo1bd10762017-10-18 09:53:14 +020052 try:
53 xproto = client.utility.GetXproto(Empty())
54 args = Args()
55 args.output = TOSCA_KEYS_DIR
56 args.inputs = str(xproto.xproto)
57 args.target = os.path.join(current_dir, 'xtarget/tosca_keys.xtarget')
58 args.write_to_file = 'single'
59 args.dest_file = 'KEYS.py'
60 XOSGenerator.generate(args)
61 print "[XOS-TOSCA] TOSCA Keys generated in %s" % args.output
62 except Exception as e:
63 print "[XOS-TOSCA] Failed to generate TOSCA Keys"
64 print e
65