wip, ceilometer service & monitoring channel
diff --git a/xos/ceilometer/admin.py b/xos/ceilometer/admin.py
new file mode 100644
index 0000000..346a98e
--- /dev/null
+++ b/xos/ceilometer/admin.py
@@ -0,0 +1,82 @@
+from django.contrib import admin
+
+from ceilometer.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 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 CeilometerServiceAdmin(ReadOnlyAwareAdmin):
+    model = CeilometerService
+    verbose_name = "Ceilometer Service"
+    verbose_name_plural = "Ceilometer 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', 'Ceilometer Service Details'),
+        ('administration', 'Administration'),
+        ('slices','Slices'),
+        ('serviceattrs','Additional Attributes'),
+        ('serviceprivileges','Privileges'),
+    )
+
+    suit_form_includes = (('ceilometeradmin.html', 'top', 'administration'),
+                           )
+
+    def queryset(self, request):
+        return CeilometerService.get_service_objects_by_user(request.user)
+
+class MonitoringChannelForm(forms.ModelForm):
+    creator = forms.ModelChoiceField(queryset=User.objects.all())
+
+    def __init__(self,*args,**kwargs):

+        super (MonitoringChannelForm,self ).__init__(*args,**kwargs)

+        self.fields['kind'].default = CEILOMETER_KIND

+        self.fields['kind'].widget.attrs['readonly'] = True

+        self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()

+        if self.instance:

+            # fields for the attributes

+            self.fields['creator'].initial = self.instance.creator

+

+    def save(self, commit=True):

+        self.instance.creator = self.cleaned_data.get("creator")

+        return super(MonitoringChannelForm, self).save(commit=commit)

+

+    class Meta:

+        model = MonitoringChannel
+
+class MonitoringChannelAdmin(ReadOnlyAwareAdmin):
+    list_display = ('backend_status_icon', 'id', 'service_specific_id', )
+    list_display_links = ('backend_status_icon', 'id')
+    fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', # 'service_specific_id', # 'service_specific_attribute',
+                                     'creator'],
+                          'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', )
+    form = MonitoringChannelForm
+
+    suit_form_tabs = (('general','Details'),)
+
+    def queryset(self, request):
+        return MonitoringChannel.get_tenant_objects_by_user(request.user)
+
+admin.site.register(CeilometerService, CeilometerServiceAdmin)
+admin.site.register(MonitoringChannel, MonitoringChannelAdmin)
+
diff --git a/xos/ceilometer/models.py b/xos/ceilometer/models.py
new file mode 100644
index 0000000..3822809
--- /dev/null
+++ b/xos/ceilometer/models.py
@@ -0,0 +1,61 @@
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Sliver, 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 *
+
+CEILOMETER_KIND = "ceilometer"
+
+class CeilometerService(Service):
+    KIND = CEILOMETER_KIND
+
+    class Meta:
+        app_label = "ceilometer"
+        verbose_name = "Ceilometer Service"
+        proxy = True
+
+class MonitoringChannel(TenantWithContainer):   # aka 'CeilometerTenant'
+    class Meta:
+        proxy = True
+
+    KIND = CEILOMETER_KIND
+
+    default_attributes = {}
+    def __init__(self, *args, **kwargs):
+        ceilometer_services = CeilometerService.get_service_objects().all()
+        if ceilometer_services:
+            self._meta.get_field("provider_service").default = ceilometer_services[0].id
+        super(MonitoringChannel, self).__init__(*args, **kwargs)
+        self.sliver = None
+
+    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("MonitoringChannel's self.caller was not set")
+            self.creator = self.caller
+            if not self.creator:
+                raise XOSProgrammingError("MonitoringChannel's self.creator was not set")
+
+        super(MonitoringChannel, self).save(*args, **kwargs)
+        model_policy_monitoring_channel(self.pk)
+
+    def delete(self, *args, **kwargs):
+        self.cleanup_sliver()
+        super(MonitoringChannel, self).delete(*args, **kwargs)
+
+def model_policy_monitoring_channel(pk):
+    # TODO: this should be made in to a real model_policy
+    with transaction.atomic():
+        mc = MonitoringChannel.objects.select_for_update().filter(pk=pk)
+        if not mc:
+            return
+        mc = mc[0]
+        mc.manage_container()
+
+
diff --git a/xos/ceilometer/templates/ceilometeradmin.html b/xos/ceilometer/templates/ceilometeradmin.html
new file mode 100644
index 0000000..8149666
--- /dev/null
+++ b/xos/ceilometer/templates/ceilometeradmin.html
@@ -0,0 +1,6 @@
+<div class = "left-nav">
+<ul>
+<li><a href="/admin/ceilometer/monitoringchannel/">Monitoring Channels</a></li>
+</ul>
+</div>
+
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index dc8b781..96f62e8 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -148,6 +148,7 @@
     'core',
     'hpc',
     'cord',
+    'ceilometer',
     'requestrouter',
 #    'urlfilter',
 #    'servcomp',