summaryrefslogtreecommitdiffstats
path: root/app/toscalib/utils/tosca_export.py
blob: c4399ef5a40c4715e7db65437c7ba14a04d0f6e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Author: Shu Shi
#emaiL: shushi@research.att.com


import yaml
import re
from toscalib.templates.constant import *

def _yaml_export(filename, content):    
    out_str = yaml.safe_dump(content,  default_flow_style=False, width=float("inf"))
    out_str = re.sub(YMO_PREFIX, '', out_str)
    if filename == 'WEB':
        return out_str
    with open(filename, 'w') as outfile:
        outfile.write(out_str)
    return out_str

def _heat_export(filename, content):
    heat_ver = YMO_PREFIX + 'heat_template_version'
    heat_content = content[YMO_TOPOLOGY]
    if heat_content is None:
        heat_content = {}
    heat_content[heat_ver] = '2013-05-23'
#    if heat_content.has_key(YMO_TOPO_OUTPUTS):
    if YMO_TOPO_OUTPUTS in heat_content:
        heat_content.pop(YMO_TOPO_OUTPUTS)
        
    out_str = yaml.dump(heat_content,  default_flow_style=False)
    out_str = re.sub(YMO_TOPO_INPUTS, YMO_PREFIX+'parameters', out_str)
    out_str = re.sub(YMO_TOPO_NODE_TEMPLATES, YMO_PREFIX+'resources', out_str)
    
    out_str = re.sub('get_input', 'get_param', out_str)
    out_str = re.sub('get_attribute', 'get_attr', out_str)
    out_str = re.sub('get_id', 'get_resource', out_str)
    out_str = re.sub('get_property', 'get_attr', out_str)
    out_str = re.sub('type: integer', 'type: number', out_str)
        
    out_str = re.sub(YMO_PREFIX, '', out_str)
    with open(filename, 'w') as outfile:
        outfile.write(out_str)