CORD-2184: Add Color and EmbeddedImage to exampleservice

Change-Id: I5e0f934a116cb44749b0cf3a2408e9b459d1dfd2
diff --git a/xos/attic/header.py b/xos/attic/header.py
index 3ee13a7..15d1329 100644
--- a/xos/attic/header.py
+++ b/xos/attic/header.py
@@ -16,7 +16,7 @@
 
 # models.py -  ExampleService Models
 
-from core.models import Service, TenantWithContainer
+from core.models import Service, TenantWithContainer, XOSBase
 from django.db import transaction
 from django.db.models import *
 
diff --git a/xos/examples/apply_tosca.sh b/xos/examples/apply_tosca.sh
new file mode 100644
index 0000000..337d01e
--- /dev/null
+++ b/xos/examples/apply_tosca.sh
@@ -0,0 +1,18 @@
+#! /bin/bash
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+PASSWORD=`cat /opt/credentials/xosadmin@opencord.org`
+curl -H "xos-username: xosadmin@opencord.org" -H "xos-password: $PASSWORD" -X POST --data-binary @exampleservice.yaml 127.0.0.1:9102/run
diff --git a/xos/examples/exampleservice.yaml b/xos/examples/exampleservice.yaml
new file mode 100644
index 0000000..0377afc
--- /dev/null
+++ b/xos/examples/exampleservice.yaml
@@ -0,0 +1,75 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+imports:
+   - custom_types/exampleservice.yaml
+   - custom_types/exampleserviceinstance.yaml
+   - custom_types/color.yaml
+   - custom_types/embeddedimage.yaml
+
+description: add colors and images to exampleservice demo
+
+topology_template:
+  node_templates:
+    red:
+      type: tosca.nodes.Color
+      properties:
+        name: red
+        html_code: "#FF0000"
+
+    green:
+      type: tosca.nodes.Color
+      properties:
+        name: green
+        html_code: "#00FF00"
+
+    blue:
+      type: tosca.nodes.Color
+      properties:
+        name: blue
+        html_code: "#0000FF"
+
+    exampleservice:
+      type: tosca.nodes.ExampleService
+      properties:
+        name: exampleservice
+        must-exist: true
+
+    exampletenant1:
+      type: tosca.nodes.ExampleServiceInstance
+      properties:
+        name: exampletenant1
+        tenant_message: world
+      requirements:
+        - owner:
+            node: exampleservice
+            relationship: tosca.relationships.BelongsToOne
+        - background_color:
+            node: red
+            relationship: tosca.relationships.BelongsToOne
+        - foreground_color:
+            node: blue
+            relationship: tosca.relationships.BelongsToOne
+
+    exampleimage:
+      type: tosca.nodes.EmbeddedImage
+      properties:
+        name: someimage
+        url: http://somesite.com/someimage.jpg
+      requirements:
+        - serviceinstance:
+            node: exampletenant1
+            relationship: tosca.relationships.BelongsToOne
diff --git a/xos/exampleservice.xproto b/xos/exampleservice.xproto
index 79ded4f..0820c9e 100644
--- a/xos/exampleservice.xproto
+++ b/xos/exampleservice.xproto
@@ -6,8 +6,22 @@
     required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False];
 }
 
+message Color (XOSBase){
+     option verbose_name = "Color";
+     required string name = 1 [help_text = "Name for this color", db_index = False, max_length = 256, null = False, blank = False];
+     required string html_code = 2 [help_text = "Code for this color", db_index = False, max_length = 256, null = False, blank = False];
+}
 
 message ExampleServiceInstance (TenantWithContainer){
      option verbose_name = "Example Service Instance";
      required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False];
+     optional manytoone foreground_color->Color:serviceinstance_foreground_colors = 3 [db_index = True, null = True, blank = True];
+     optional manytoone background_color->Color:serviceinstance_background_colors = 3 [db_index = True, null = True, blank = True];
+}
+
+message EmbeddedImage (XOSBase){
+     option verbose_name = "Embedded Image";
+     required string name = 1 [help_text = "Name for this image", db_index = False, max_length = 256, null = False, blank = False];
+     required string url = 2 [help_text = "URL for this image", db_index = False, max_length = 256, null = False, blank = False];
+     optional manytoone serviceinstance->ExampleServiceInstance:embedded_images = 3 [db_index = True, null = True, blank = True];
 }
diff --git a/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml b/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
index 5830815..88dfb01 100644
--- a/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
+++ b/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
@@ -25,6 +25,13 @@
   vars:
     - tenant_message: "{{ tenant_message }}"
     - service_message: "{{ service_message }}"
+    - foreground_color: "{{ foreground_color | default("#000000") }}"
+    - background_color: "{{ background_color | default("#FFFFFF") }}"
+    - images:
+        {% for image in images %}
+        - name: {{ image.name }}
+          url: {{ image.url }}
+        {% endfor %}
 
   roles:
     - install_apache
diff --git a/xos/synchronizer/steps/roles/create_index/templates/index.html.j2 b/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
index 2347792..d9833a0 100644
--- a/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
+++ b/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
@@ -15,8 +15,25 @@
 limitations under the License.
 #}
 
+<html>
+<body style="background-color:{{ background_color }};">
+<font color="{{ foreground_color }}">
 
-ExampleService
- Service Message: "{{ service_message }}"
- Tenant Message: "{{ tenant_message }}"
+<h1>ExampleService</h1>
 
+<ul>
+<li>Service Message: "{{ service_message }}"</li>
+<li>Tenant Message: "{{ tenant_message }}"</li>
+</ul>
+
+{% if images %}
+<h2>Some images</h2>
+{% for image in images %}
+<img name="{{ image.name }}" href="{{ image.url }}">
+{% endfor %}
+{% endif %}
+
+</font>
+
+</body>
+</html>
diff --git a/xos/synchronizer/steps/sync_exampleserviceinstance.py b/xos/synchronizer/steps/sync_exampleserviceinstance.py
index 3462960..373fb5e 100644
--- a/xos/synchronizer/steps/sync_exampleserviceinstance.py
+++ b/xos/synchronizer/steps/sync_exampleserviceinstance.py
@@ -60,6 +60,19 @@
         fields['tenant_message'] = o.tenant_message
         exampleservice = self.get_exampleservice(o)
         fields['service_message'] = exampleservice.service_message
+
+        if o.foreground_color:
+            fields["foreground_color"] = o.foreground_color.html_code
+
+        if o.background_color:
+            fields["background_color"] = o.background_color.html_code
+
+        images=[]
+        for image in o.embedded_images.all():
+            images.append({"name": image.name,
+                           "url": image.url})
+        fields["images"] = images
+
         return fields
 
     def delete_record(self, port):
diff --git a/xos/tosca/resources/exampleserviceinstance.py b/xos/tosca/resources/exampleserviceinstance.py
index 7b8f640..090f381 100644
--- a/xos/tosca/resources/exampleserviceinstance.py
+++ b/xos/tosca/resources/exampleserviceinstance.py
@@ -21,7 +21,6 @@
                 "tosca.nodes.ExampleTenant"            # deprecated
                 ]
     xos_model = ExampleServiceInstance
-    name_field = "service_specific_id"
     copyin_props = ("tenant_message",)
 
     def get_xos_args(self, throw_exception=True):
@@ -34,11 +33,6 @@
 
         return args
 
-    def get_existing_objs(self):
-        args = self.get_xos_args(throw_exception=False)
-        return ExampleServiceInstance.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
-        return []
-
     def can_delete(self, obj):
         return super(XOSExampleServiceInstance, self).can_delete(obj)