Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/services/exampleservice/README.md b/xos/services/exampleservice/README.md
new file mode 100644
index 0000000..ce6210d
--- /dev/null
+++ b/xos/services/exampleservice/README.md
@@ -0,0 +1,8 @@
+# ExampleService
+
+This is an example XOS service, specifically the Django Model and Admin. 
+
+The Synchronizer corresponding to this service can be found in `../../synchronizers/exampleservice`.
+
+Documentation for this is located here: [XOS Guide : DevGuide : ExampleService](http://guide.xosproject.org/devguide/exampleservice/).
+
diff --git a/xos/services/exampleservice/__init__.py b/xos/services/exampleservice/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/xos/services/exampleservice/__init__.py
diff --git a/xos/services/exampleservice/admin.py b/xos/services/exampleservice/admin.py
new file mode 100644
index 0000000..d4f6248
--- /dev/null
+++ b/xos/services/exampleservice/admin.py
@@ -0,0 +1,101 @@
+# admin.py - ExampleService Django Admin
+
+from core.admin import ReadOnlyAwareAdmin, SliceInline
+from core.middleware import get_request
+from core.models import User
+
+from django import forms
+from django.contrib import admin
+
+from services.exampleservice.models import *
+
+class ExampleServiceAdmin(ReadOnlyAwareAdmin):
+
+    model = ExampleService
+    verbose_name = SERVICE_NAME_VERBOSE
+    verbose_name_plural = SERVICE_NAME_VERBOSE_PLURAL
+
+    list_display = ('backend_status_icon', 'name', 'enabled',)
+    list_display_links = ('backend_status_icon', 'name', )
+
+    fieldsets = [(None, {
+        'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',],
+        'classes':['suit-tab suit-tab-general',],
+        })]
+
+    readonly_fields = ('backend_status_text', )
+    user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
+
+    inlines = [SliceInline]
+
+    extracontext_registered_admins = True
+
+    suit_form_tabs = (
+        ('general', 'Example Service Details', ),
+        ('slices', 'Slices',),
+        )
+
+    suit_form_includes = ((
+        'top',
+        'administration'),
+        )
+
+    def queryset(self, request):
+        return ExampleService.get_service_objects_by_user(request.user)
+
+admin.site.register(ExampleService, ExampleServiceAdmin)
+
+class ExampleTenantForm(forms.ModelForm):
+
+    class Meta:
+        model = ExampleTenant
+
+    creator = forms.ModelChoiceField(queryset=User.objects.all())
+
+    def __init__(self, *args, **kwargs):
+        super(ExampleTenantForm, self).__init__(*args, **kwargs)
+
+        self.fields['kind'].widget.attrs['readonly'] = True
+        self.fields['kind'].initial = SERVICE_NAME
+
+        self.fields['provider_service'].queryset = ExampleService.get_service_objects().all()
+
+        if self.instance:
+            self.fields['creator'].initial = self.instance.creator
+            self.fields['tenant_message'].initial = self.instance.tenant_message
+
+        if (not self.instance) or (not self.instance.pk):
+            self.fields['creator'].initial = get_request().user
+            if ExampleService.get_service_objects().exists():
+                self.fields['provider_service'].initial = ExampleService.get_service_objects().all()[0]
+
+    def save(self, commit=True):
+        self.instance.creator = self.cleaned_data.get('creator')
+        self.instance.tenant_message = self.cleaned_data.get('tenant_message')
+        return super(ExampleTenantForm, self).save(commit=commit)
+
+
+class ExampleTenantAdmin(ReadOnlyAwareAdmin):
+
+    verbose_name = TENANT_NAME_VERBOSE
+    verbose_name_plural = TENANT_NAME_VERBOSE_PLURAL
+
+    list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message')
+    list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id')
+
+    fieldsets = [(None, {
+        'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message'],
+        'classes': ['suit-tab suit-tab-general'],
+        })]
+
+    readonly_fields = ('backend_status_text', 'instance',)
+
+    form = ExampleTenantForm
+
+    suit_form_tabs = (('general', 'Details'),)
+
+    def queryset(self, request):
+        return ExampleTenant.get_tenant_objects_by_user(request.user)
+
+admin.site.register(ExampleTenant, ExampleTenantAdmin)
+
diff --git a/xos/services/exampleservice/models.py b/xos/services/exampleservice/models.py
new file mode 100644
index 0000000..6305b54
--- /dev/null
+++ b/xos/services/exampleservice/models.py
@@ -0,0 +1,52 @@
+# models.py -  ExampleService Models
+
+from core.models import Service, TenantWithContainer
+from django.db import models, transaction
+
+SERVICE_NAME = 'exampleservice'
+SERVICE_NAME_VERBOSE = 'Example Service'
+SERVICE_NAME_VERBOSE_PLURAL = 'Example Services'
+TENANT_NAME_VERBOSE = 'Example Tenant'
+TENANT_NAME_VERBOSE_PLURAL = 'Example Tenants'
+
+class ExampleService(Service):
+
+    KIND = SERVICE_NAME
+
+    class Meta:
+        app_label = SERVICE_NAME
+        verbose_name = SERVICE_NAME_VERBOSE
+        proxy = True
+
+class ExampleTenant(TenantWithContainer):
+
+    KIND = SERVICE_NAME
+
+    class Meta:
+        verbose_name = TENANT_NAME_VERBOSE
+
+    tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display")
+
+    def __init__(self, *args, **kwargs):
+        exampleservice = ExampleService.get_service_objects().all()
+        if exampleservice:
+            self._meta.get_field('provider_service').default = exampleservice[0].id
+        super(ExampleTenant, self).__init__(*args, **kwargs)
+
+    def save(self, *args, **kwargs):
+        super(ExampleTenant, self).save(*args, **kwargs)
+        model_policy_exampletenant(self.pk)
+
+    def delete(self, *args, **kwargs):
+        self.cleanup_container()
+        super(ExampleTenant, self).delete(*args, **kwargs)
+
+
+def model_policy_exampletenant(pk):
+    with transaction.atomic():
+        tenant = ExampleTenant.objects.select_for_update().filter(pk=pk)
+        if not tenant:
+            return
+        tenant = tenant[0]
+        tenant.manage_container()
+
diff --git a/xos/synchronizers/exampleservice/exampleservice-synchronizer.py b/xos/synchronizers/exampleservice/exampleservice-synchronizer.py
new file mode 100644
index 0000000..90d2c98
--- /dev/null
+++ b/xos/synchronizers/exampleservice/exampleservice-synchronizer.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+# Runs the standard XOS synchronizer
+
+import importlib
+import os
+import sys
+
+synchronizer_path = os.path.join(os.path.dirname(
+    os.path.realpath(__file__)), "../../synchronizers/base")
+sys.path.append(synchronizer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
+
diff --git a/xos/synchronizers/exampleservice/exampleservice_config b/xos/synchronizers/exampleservice/exampleservice_config
new file mode 100644
index 0000000..7e59fdd
--- /dev/null
+++ b/xos/synchronizers/exampleservice/exampleservice_config
@@ -0,0 +1,24 @@
+# Required by XOS
+[db]
+name=xos
+user=postgres
+password=password
+host=localhost
+port=5432
+
+# Required by XOS
+[api]
+nova_enabled=True
+
+# Sets options for the synchronizer
+[observer]
+name=exampleservice
+dependency_graph=/opt/xos/synchronizers/exampleservice/model-deps
+steps_dir=/opt/xos/synchronizers/exampleservice/steps
+sys_dir=/opt/xos/synchronizers/exampleservice/sys
+logfile=/var/log/xos_backend.log
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=False
+
diff --git a/xos/synchronizers/exampleservice/model-deps b/xos/synchronizers/exampleservice/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/synchronizers/exampleservice/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/synchronizers/exampleservice/steps/exampletenant_playbook.yaml b/xos/synchronizers/exampleservice/steps/exampletenant_playbook.yaml
new file mode 100644
index 0000000..82a5af1
--- /dev/null
+++ b/xos/synchronizers/exampleservice/steps/exampletenant_playbook.yaml
@@ -0,0 +1,24 @@
+---
+- hosts: "{{ instance_name }}"
+  connection: ssh
+  user: ubuntu
+  sudo: yes
+  gather_facts: no
+
+  tasks:
+  - name: install apache
+    apt:
+      name=apache2
+      update_cache=yes
+    notify:
+      - restart apache
+
+  - name: write message
+    shell: echo "{{ tenant_message }}" > /var/www/html/index.html
+
+  handlers:
+  - name: restart apache
+    service:
+      name=apache2
+      state=restarted
+
diff --git a/xos/synchronizers/exampleservice/steps/sync_exampletenant.py b/xos/synchronizers/exampleservice/steps/sync_exampletenant.py
new file mode 100644
index 0000000..bc4169b
--- /dev/null
+++ b/xos/synchronizers/exampleservice/steps/sync_exampletenant.py
@@ -0,0 +1,40 @@
+import os
+import sys
+from django.db.models import Q, F
+from services.exampleservice.models import ExampleService, ExampleTenant
+from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncExampleTenant(SyncInstanceUsingAnsible):
+
+    provides = [ExampleTenant]
+
+    observes = ExampleTenant
+
+    requested_interval = 0
+
+    template_name = "exampletenant_playbook.yaml"
+
+    service_key_name = "/opt/xos/synchronizers/exampleservice/exampleservice_private_key"
+
+    def __init__(self, *args, **kwargs):
+        super(SyncExampleTenant, self).__init__(*args, **kwargs)
+
+    def fetch_pending(self, deleted):
+
+        if (not deleted):
+            objs = ExampleTenant.get_tenant_objects().filter(
+                Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+        else:
+            # If this is a deletion we get all of the deleted tenants..
+            objs = ExampleTenant.get_deleted_tenant_objects()
+
+        return objs
+
+    # Gets the attributes that are used by the Ansible template but are not
+    # part of the set of default attributes.
+    def get_extra_attributes(self, o):
+        return {"tenant_message": o.tenant_message}
+