Merge branch 'master' of https://github.com/open-cloud/xos into AddHelloWorldService
diff --git a/xos/helloworldservice/__init__.py b/xos/helloworldservice/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/xos/helloworldservice/__init__.py
diff --git a/xos/helloworldservice/admin.py b/xos/helloworldservice/admin.py
new file mode 100644
index 0000000..3e67855
--- /dev/null
+++ b/xos/helloworldservice/admin.py
@@ -0,0 +1,89 @@
+from django.contrib import admin
+
+from helloworldservice.models import *
+from django import forms
+from django.utils.safestring import mark_safe
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.admin.widgets import FilteredSelectMultiple
+from django.contrib.auth.forms import ReadOnlyPasswordHashField
+from django.contrib.auth.signals import user_logged_in
+from django.utils import timezone
+from django.contrib.contenttypes import generic
+from suit.widgets import LinkedSelect
+from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
+from core.middleware import get_request
+
+from functools import update_wrapper
+from django.contrib.admin.views.main import ChangeList
+from django.core.urlresolvers import reverse
+from django.contrib.admin.utils import quote
+
+class HelloWorldServiceAdmin(ReadOnlyAwareAdmin):
+    model = HelloWorldService
+    verbose_name = "Hello World Service"
+    verbose_name_plural = "Hello World Service"
+    list_display = ("backend_status_icon", "name", "enabled")
+    list_display_links = ('backend_status_icon', 'name', )
+    fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', )
+    inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
+
+    extracontext_registered_admins = True
+
+    user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
+
+    suit_form_tabs =(('general', 'Hello World Service Details'),
+        ('administration', 'Administration'),
+        ('slices','Slices'),
+        ('serviceattrs','Additional Attributes'),
+        ('serviceprivileges','Privileges'),
+    )
+
+    suit_form_includes = (('helloworldserviceadmin.html', 'top', 'administration'),
+                           )
+    def queryset(self, request):
+        return HelloWorldService.get_service_objects_by_user(request.user)
+
+class HelloWorldTenantForm(forms.ModelForm):
+    creator = forms.ModelChoiceField(queryset=User.objects.all())
+    display_message = forms.CharField(required=False)
+    def __init__(self,*args,**kwargs):
+        super (HelloWorldTenantForm,self ).__init__(*args,**kwargs)
+        self.fields['kind'].widget.attrs['readonly'] = True
+        self.fields['provider_service'].queryset = HelloWorldService.get_service_objects().all()
+        if self.instance:
+            # fields for the attributes
+            self.fields['creator'].initial = self.instance.creator
+	    self.fields['display_message'].initial = self.instance.display_message
+        if (not self.instance) or (not self.instance.pk):
+            # default fields for an 'add' form
+            self.fields['kind'].initial = HELLO_WORLD_KIND
+            self.fields['creator'].initial = get_request().user
+            if HelloWorldService.get_service_objects().exists():
+               self.fields["provider_service"].initial = HelloWorldService.get_service_objects().all()[0]
+
+
+    def save(self, commit=True):
+        self.instance.creator = self.cleaned_data.get("creator")
+	self.instance.display_message = self.cleaned_data.get("display_message")
+        return super(HelloWorldTenantForm, self).save(commit=commit)
+
+    class Meta:
+        model = HelloWorldTenant
+
+class HelloWorldTenantAdmin(ReadOnlyAwareAdmin):
+    list_display = ('backend_status_icon', 'id', )
+    list_display_links = ('backend_status_icon', 'id')
+    fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute',
+                                     'instance', 'creator', 'display_message'],
+                          'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute', )
+    form = HelloWorldTenantForm
+
+    suit_form_tabs = (('general','Details'),)
+
+    def queryset(self, request):
+        return HelloWorldTenant.get_tenant_objects_by_user(request.user)
+
+admin.site.register(HelloWorldService, HelloWorldServiceAdmin)
+admin.site.register(HelloWorldTenant, HelloWorldTenantAdmin)
diff --git a/xos/helloworldservice/models.py b/xos/helloworldservice/models.py
new file mode 100644
index 0000000..bb35f4c
--- /dev/null
+++ b/xos/helloworldservice/models.py
@@ -0,0 +1,60 @@
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber
+from core.models.plcorebase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+import traceback
+from xos.exceptions import *
+from core.models import SlicePrivilege, SitePrivilege
+from sets import Set
+from core.models.plcorebase import StrippedCharField
+
+
+HELLO_WORLD_KIND = "helloworldservice"
+
+class HelloWorldService(Service):
+    KIND = HELLO_WORLD_KIND
+
+    class Meta:
+	proxy = True
+        app_label = "helloworldservice"
+        verbose_name = "Hello World Service"
+
+class HelloWorldTenant(TenantWithContainer):
+    class Meta:
+        proxy = True
+
+    KIND = HELLO_WORLD_KIND
+    default_attributes = {'display_message': 'Hello World!'}
+    def __init__(self, *args, **kwargs):
+        hello_world_service_services = HelloWorldService.get_service_objects().all()
+        if hello_world_service_services:
+            self._meta.get_field("provider_service").default = hello_world_service_services[0].id
+        super(HelloWorldTenant, self).__init__(*args, **kwargs)
+
+    def save(self, *args, **kwargs):
+        if not self.creator:
+            if not getattr(self, "caller", None):
+                # caller must be set when creating a vCPE since it creates a slice
+                raise XOSProgrammingError("HelloWorldTennant's self.caller was not set")
+            self.creator = self.caller
+            if not self.creator:
+                raise XOSProgrammingError("HelloWorldTennant's self.creator was not set")
+        
+	super(HelloWorldTenant, self).save(*args, **kwargs)
+
+    def delete(self, *args, **kwargs):
+        self.cleanup_container()
+        super(HelloWorldTenant, self).delete(*args, **kwargs)
+
+    @property
+    def display_message(self):
+	return self.get_attribute("display_message", self.default_attributes['display_message'])
+
+    @display_message.setter
+    def display_message(self, value):
+        self.set_attribute("display_message", value)
+
diff --git a/xos/helloworldservice/templates/helloworldserviceadmin.html b/xos/helloworldservice/templates/helloworldserviceadmin.html
new file mode 100644
index 0000000..eb8ec35
--- /dev/null
+++ b/xos/helloworldservice/templates/helloworldserviceadmin.html
@@ -0,0 +1,5 @@
+<div class = "left-nav">
+<ul>
+<li><a href="/admin/helloworldservice/helloworldtenant/">Hello World Tenants</a></li>
+</ul>
+</div>
diff --git a/xos/scripts/opencloud b/xos/scripts/opencloud
index 6705b20..70b3d82 100755
--- a/xos/scripts/opencloud
+++ b/xos/scripts/opencloud
@@ -147,6 +147,7 @@
     python ./manage.py makemigrations syndicate_storage
     python ./manage.py makemigrations cord
     python ./manage.py makemigrations ceilometer
+    python ./manage.py makemigrations helloworldservice
     #python ./manage.py makemigrations servcomp
 }
 
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index ba5ff1d..eb6287f 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -148,6 +148,7 @@
     'core',
     'hpc',
     'cord',
+    'helloworldservice',
     'ceilometer',
     'requestrouter',
 #    'urlfilter',