[CORD-1492] Adding tosca related functions in xosgenx jinja functions
Change-Id: I1ba1f5874a984a30645aa31a190dcd64d99b0938
diff --git a/containers/xos/pip_requirements.txt b/containers/xos/pip_requirements.txt
index afe761a..cb19c6c 100644
--- a/containers/xos/pip_requirements.txt
+++ b/containers/xos/pip_requirements.txt
@@ -152,7 +152,7 @@
structlog==16.1.0
supervisor==3.0b2
texttable==0.8.7
-tosca-parser==0.7.0
+tosca-parser==0.8.1
twisted==16.6.0
unicodecsv==0.14.1
uritemplate==0.6
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions.py b/lib/xos-genx/xosgenx/jinja2_extensions.py
index 8377d5a..f07aa14 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions.py
@@ -429,8 +429,18 @@
return options_str
-def xproto_tosca_required(blank):
- if blank == "False":
- return "true"
- return "false"
+def xproto_tosca_required(null, blank, default=None):
+
+ if null == 'True' or blank == 'True' or default != 'False':
+ return "false"
+ return "true"
+
+def xproto_tosca_field_type(type):
+ """
+ TOSCA requires fields of type 'bool' to be 'boolean'
+ """
+ if type == "bool":
+ return "boolean"
+ else:
+ return type
diff --git a/lib/xos-genx/xosgenx/targets/tosca.xtarget b/lib/xos-genx/xosgenx/targets/tosca.xtarget
deleted file mode 100644
index b5e51ae..0000000
--- a/lib/xos-genx/xosgenx/targets/tosca.xtarget
+++ /dev/null
@@ -1,31 +0,0 @@
-tosca_definitions_version: tosca_simple_yaml_1_0
-
-node_types:
-{% for m in proto.messages %}
- tosca.nodes.{{ m.name }}:
- derived_from: tosca.nodes.Root
- description: {{ m.name }}
- properties:
- no-delete:
- type: boolean
- default: false
- description: Do not allow Tosca to delete this object
- no-create:
- type: boolean
- default: false
- description: Do not allow Tosca to create this object
- no-update:
- type: boolean
- default: false
- description: Do not allow Tosca to update this object
- replaces:
- type: string
- required: false
- descrption: Replaces/renames this object
- {%- for f in m.fields %}
- {{ f.name }}:
- type: {{ f.type }}
- required: {{ xproto_tosca_required(f.options.blank) }}
- description: {{ f.options.help_text }}
- {%- endfor %}
-{%- endfor %}
\ No newline at end of file
diff --git a/xos/core/models/core.xproto b/xos/core/models/core.xproto
index 0f202fe..a91d4f5 100644
--- a/xos/core/models/core.xproto
+++ b/xos/core/models/core.xproto
@@ -21,6 +21,7 @@
message User (AbstractBaseUser,PlModelMixIn) {
option skip_django = True;
+ option tosca_description = "An XOS User";
required string email = 1 [db_index = True, max_length = 255, null = False, blank = False];
required string username = 2 [default = "Something", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False];