Tosca changes for creating a default ceilometer tenant for admin user
diff --git a/xos/ceilometer/models.py b/xos/ceilometer/models.py
index fbfecd3..a838c4e 100644
--- a/xos/ceilometer/models.py
+++ b/xos/ceilometer/models.py
@@ -41,12 +41,18 @@
     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
+                # caller must be set when creating a monitoring channel 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")
 
+        if self.pk is None:
+            #Allow only one monitoring channel per user
+            channel_count = sum ( [1 for channel in MonitoringChannel.objects.filter(kind=CEILOMETER_KIND) if (channel.creator == self.creator)] )
+            if channel_count > 0:
+                raise XOSValidationError("Already %s channels exist for user Can only create max 1 MonitoringChannel instance per user" % str(channel_count))
+
         super(MonitoringChannel, self).save(*args, **kwargs)
         model_policy_monitoring_channel(self.pk)
 
diff --git a/xos/configurations/common/admin-openrc.sh b/xos/configurations/common/admin-openrc.sh
deleted file mode 100644
index e69de29..0000000
--- a/xos/configurations/common/admin-openrc.sh
+++ /dev/null
diff --git a/xos/configurations/cord/Makefile b/xos/configurations/cord/Makefile
index 40ff5a1..4c2e423 100644
--- a/xos/configurations/cord/Makefile
+++ b/xos/configurations/cord/Makefile
@@ -2,7 +2,7 @@
 RUNNING_CONTAINER:=$(shell sudo docker ps|grep "xos"|awk '{print $$NF}')
 LAST_CONTAINER=$(shell sudo docker ps -l -q)
 
-test: common_cloudlab
+test: common_cloudlab ceilometer_dashboard
 	echo "# Autogenerated -- do not edit" > Dockerfile
 	cat ../common/Dockerfile.common Dockerfile.cord >> Dockerfile
 	cd ../../..; sudo docker build -t xos -f xos/configurations/cord/Dockerfile .
@@ -12,6 +12,12 @@
 common_cloudlab:
 	make -C ../common -f Makefile.cloudlab
 
+ceilometer_dashboard:
+	#NOTE: The below dashboard install scripts assume 
+	#clouldlab openstack environment created using "OpenStack" profile
+	bash install_xos_ceilometer_dashboard.sh
+	bash install_ceilometer_vcpe_notification_listener.sh
+
 stop:
 	sudo docker stop $(RUNNING_CONTAINER)
 
diff --git a/xos/configurations/cord/ceilometer.yaml b/xos/configurations/cord/ceilometer.yaml
index 6e5e24f..73c18db 100644
--- a/xos/configurations/cord/ceilometer.yaml
+++ b/xos/configurations/cord/ceilometer.yaml
@@ -5,6 +5,17 @@
 imports:
    - custom_types/xos.yaml
 
+node_types:
+    tosca.nodes.CeilometerTenant:
+        derived_from: tosca.nodes.Root
+        description: >
+            CORD: A Tenant of the Ceilometer Service.
+        properties:
+            kind:
+                type: string
+                default: generic
+                description: Kind of tenant
+
 topology_template:
   node_templates:
     service_ceilometer:
@@ -51,6 +62,14 @@
               node: mysite
               relationship: tosca.relationships.MemberOfSite
 
+    my_ceilometer_tenant:
+      description: Ceilometer Service default Tenant
+      type: tosca.nodes.CeilometerTenant
+      requirements:
+          - provider_service:
+              node: service_ceilometer
+              relationship: tosca.relationships.MemberOfService
+       
     Ceilometer:
       type: tosca.nodes.DashboardView
       properties:
@@ -77,4 +96,4 @@
               relationship: tosca.relationships.UsesDashboard
           - ceilometer_dashboard:
               node: Ceilometer
-              relationship: tosca.relationships.UsesDashboard
\ No newline at end of file
+              relationship: tosca.relationships.UsesDashboard
diff --git a/xos/configurations/cord/ceilometer_vcpe_notification_agent.tar.gz b/xos/configurations/cord/ceilometer_vcpe_notification_agent.tar.gz
new file mode 100644
index 0000000..dcc6765
--- /dev/null
+++ b/xos/configurations/cord/ceilometer_vcpe_notification_agent.tar.gz
Binary files differ
diff --git a/xos/configurations/cord/etc_xos_metering.tar.gz b/xos/configurations/cord/etc_xos_metering.tar.gz
new file mode 100644
index 0000000..53689db
--- /dev/null
+++ b/xos/configurations/cord/etc_xos_metering.tar.gz
Binary files differ
diff --git a/xos/configurations/cord/install_ceilometer_vcpe_notification_listener.sh b/xos/configurations/cord/install_ceilometer_vcpe_notification_listener.sh
new file mode 100755
index 0000000..50a4132
--- /dev/null
+++ b/xos/configurations/cord/install_ceilometer_vcpe_notification_listener.sh
@@ -0,0 +1,16 @@
+if [ -d /usr/lib/python2.7/dist-packages/ceilometer/network/ext_services ]; then
+    echo "Seems VCPE notification listeners are already enabled in ceilometer... so exiting gracefully..."
+    exit 0
+fi
+echo "Verifying if all the required files are present"
+if [ ! -f ceilometer_vcpe_notification_agent.tar.gz ];
+then
+    echo "File ceilometer_vcpe_notification_agent.tar.gz not found"
+    exit 1
+fi
+echo "Copying the ceilometer vcpe notification agent files /usr/lib/python2.7/dist-packages/ceilometer"
+tar -xzf ceilometer_vcpe_notification_agent.tar.gz
+sudo mv ceilometer/network/ext_services /usr/lib/python2.7/dist-packages/ceilometer/network/
+sudo mv ceilometer-2015.1.1.egg-info/entry_points.txt /usr/lib/python2.7/dist-packages/ceilometer-2015.1.1.egg-info/
+echo "Restarting ceilometer-agent-notification"
+sudo service ceilometer-agent-notification restart
diff --git a/xos/configurations/cord/install_xos_ceilometer_dashboard.sh b/xos/configurations/cord/install_xos_ceilometer_dashboard.sh
new file mode 100755
index 0000000..ed72f54
--- /dev/null
+++ b/xos/configurations/cord/install_xos_ceilometer_dashboard.sh
@@ -0,0 +1,25 @@
+if [ -d /usr/share/xos-metering ]; then
+    echo "Seems xos ceilometer dashboard is already installed... so exiting gracefully..."
+    exit 0
+fi
+echo "Verifying if all the required files are present"
+if [ ! -f xos_metering_dashboard.tar.gz ];
+then
+    echo "File xos_metering_dashboard.tar.gz not found"
+    exit 1
+fi
+if [ ! -f etc_xos_metering.tar.gz ];
+then
+    echo "File etc_xos_metering.tar.gz not found"
+    exit 1
+fi
+echo "Copying the xos ceilometer dashboard files /usr/share/ and /etc/apache2/"
+tar -xzf xos_metering_dashboard.tar.gz
+sudo mv xos-metering /usr/share/
+tar -xzf etc_xos_metering.tar.gz
+sudo mv xos-metering /etc/
+sudo mv apache2/conf-available/xos-metering.conf /etc/apache2/conf-available/
+cd /etc/apache2/conf-enabled/
+sudo ln -s ../conf-available/xos-metering.conf xos-metering.conf
+echo "Restarting apache2"
+sudo service apache2 restart
diff --git a/xos/configurations/cord/xos_metering_dashboard.tar.gz b/xos/configurations/cord/xos_metering_dashboard.tar.gz
new file mode 100644
index 0000000..648f91a
--- /dev/null
+++ b/xos/configurations/cord/xos_metering_dashboard.tar.gz
Binary files differ
diff --git a/xos/tosca/resources/ceilometertenant.py b/xos/tosca/resources/ceilometertenant.py
new file mode 100644
index 0000000..6599f33
--- /dev/null
+++ b/xos/tosca/resources/ceilometertenant.py
@@ -0,0 +1,39 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from ceilometer.models import MonitoringChannel, CeilometerService
+
+from xosresource import XOSResource
+
+class XOSCeilometerTenant(XOSResource):
+    provides = "tosca.nodes.CeilometerTenant"
+    xos_model = MonitoringChannel
+    name_field = None
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSCeilometerTenant, self).get_xos_args()
+
+        provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+        if provider_name:
+            args["provider_service"] = self.get_xos_object(CeilometerService, throw_exception=throw_exception, name=provider_name)
+
+        return args
+
+    def get_existing_objs(self):
+        args = self.get_xos_args(throw_exception=False)
+        provider_service = args.get("provider", None)
+        if provider_service:
+            return [ self.get_xos_object(provider_service=provider_service) ]
+        return []
+
+    def postprocess(self, obj):
+        pass
+
+    def can_delete(self, obj):
+        return super(XOSCeilometerTenant, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/user.py b/xos/tosca/resources/user.py
index 2b2a787..724bc3d 100644
--- a/xos/tosca/resources/user.py
+++ b/xos/tosca/resources/user.py
@@ -46,6 +46,7 @@
                         sp.save()
                         self.info("Added site privilege on %s role %s for %s" % (str(dest), str(role), str(obj)))
 
+        dashboard_order = 10
         for reqs in self.nodetemplate.requirements:
             for (k,v) in reqs.items():
                 if (v["relationship"] == "tosca.relationships.UsesDashboard"):
@@ -56,7 +57,8 @@
                     if not udvs:
                         self.info("Adding UserDashboardView from %s to %s" % (obj, dashboard))
 
-                        udv = UserDashboardView(user=obj, dashboardView=dashboard)
+                        udv = UserDashboardView(user=obj, dashboardView=dashboard, order=dashboard_order)
+                        dashboard_order += 10
                         udv.save()
 
     def create(self):