Providing Ceilometer PUB/SUB URL through configuration
diff --git a/xos/configurations/cord/ceilometer.yaml b/xos/configurations/cord/ceilometer.yaml
index 35922cf..6fcd132 100644
--- a/xos/configurations/cord/ceilometer.yaml
+++ b/xos/configurations/cord/ceilometer.yaml
@@ -58,6 +58,52 @@
               default: 33333
               description: sFlow publish subscribe api listening port
 
+    tosca.nodes.CeilometerService:
+        derived_from: tosca.nodes.Root
+        description: >
+            XOS Ceilometer Service
+        capabilities:
+            scalable:
+                type: tosca.capabilities.Scalable
+            service:
+                type: tosca.capabilities.xos.Service
+        properties:
+            kind:
+                type: string
+                default: generic
+                description: Type of service.
+            view_url:
+                type: string
+                required: false
+                description: URL to follow when icon is clicked in the Service Directory.
+            icon_url:
+                type: string
+                required: false
+                description: ICON to display in the Service Directory.
+            enabled:
+                type: boolean
+                default: true
+            published:
+                type: boolean
+                default: true
+                description: If True then display this Service in the Service Directory.
+            public_key:
+                type: string
+                required: false
+                description: Public key to install into Instances to allows Services to SSH into them.
+            private_key_fn:
+                type: string
+                required: false
+                description: Location of private key file
+            versionNumber:
+                type: string
+                required: false
+                description: Version number of Service.
+            ceilometer_pub_sub_url:
+                type: string
+                required: false
+                description: REST URL of ceilometer PUB/SUB component
+
     tosca.nodes.CeilometerTenant:
         derived_from: tosca.nodes.Root
         description: >
@@ -71,11 +117,12 @@
 topology_template:
   node_templates:
     service_ceilometer:
-      type: tosca.nodes.Service
+      type: tosca.nodes.CeilometerService
       requirements:
       properties:
           view_url: /admin/ceilometer/ceilometerservice/$id$/
           kind: ceilometer
+          ceilometer_pub_sub_url: http://10.11.10.1:4455/
 #          public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
 #      artifacts:
 #          pubkey: /opt/xos/synchronizers/vcpe/vcpe_public_key
diff --git a/xos/core/xoslib/methods/ceilometerview.py b/xos/core/xoslib/methods/ceilometerview.py
index b56065a..f26d84a 100644
--- a/xos/core/xoslib/methods/ceilometerview.py
+++ b/xos/core/xoslib/methods/ceilometerview.py
@@ -57,6 +57,9 @@
                 else:
                     logger.warn("SRIKANTH: Slice %(slice)s is not associated with any service" % {'slice':cs.slice.name})
                     tenantmap[cs.tenant_id]["service"] = "Other"
+    #TEMPORARY WORK AROUND: There are some resource in network like whitebox switches does not belong to a specific tenant.
+    #They are all associated with "default_admin_tenant" tenant
+    tenantmap["default_admin_tenant"] = {"slice": "default_admin_tenant", "service": "Other"}
     return tenantmap
 
 def build_url(path, q, params=None):
@@ -1263,8 +1266,7 @@
                 service_map[v['service']] = {}
                 service_map[v['service']]['service'] = v['service']
                 service_map[v['service']]['slices'] = []
-            slice_details['slice'] = v['slice']
-            slice_details['project_id'] = k
+            slice_details = {'slice':v['slice'], 'project_id':k}
             service_map[v['service']]['slices'].append(slice_details)
         return Response(service_map.values())
 
diff --git a/xos/services/ceilometer/admin.py b/xos/services/ceilometer/admin.py
index 73b205e..062a2ae 100644
--- a/xos/services/ceilometer/admin.py
+++ b/xos/services/ceilometer/admin.py
@@ -18,15 +18,32 @@
 from django.core.urlresolvers import reverse
 from django.contrib.admin.utils import quote
 
+class CeilometerServiceForm(forms.ModelForm):
+    ceilometer_pub_sub_url = forms.CharField(required=False, max_length=1024, help_text="REST URL of ceilometer PUB/SUB component in http://IP:port/ format")
+
+    def __init__(self,*args,**kwargs):
+        super (CeilometerServiceForm,self ).__init__(*args,**kwargs)
+        if self.instance:
+            # fields for the attributes
+            self.fields['ceilometer_pub_sub_url'].initial = self.instance.ceilometer_pub_sub_url
+
+    def save(self, commit=True):
+        self.instance.ceilometer_pub_sub_url = self.cleaned_data.get("ceilometer_pub_sub_url")
+        return super(CeilometerServiceForm, self).save(commit=commit)
+
+    class Meta:
+        model = CeilometerService
+
 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']})]
+    fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description','ceilometer_pub_sub_url', "view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', )
     inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
+    form = CeilometerServiceForm
 
     extracontext_registered_admins = True
 
diff --git a/xos/services/ceilometer/models.py b/xos/services/ceilometer/models.py
index 91d9716..42734de 100644
--- a/xos/services/ceilometer/models.py
+++ b/xos/services/ceilometer/models.py
@@ -22,6 +22,14 @@
         verbose_name = "Ceilometer Service"
         proxy = True
 
+    @property
+    def ceilometer_pub_sub_url(self):
+        return self.get_attribute("ceilometer_pub_sub_url", None)
+
+    @ceilometer_pub_sub_url.setter
+    def ceilometer_pub_sub_url(self, value):
+        self.set_attribute("ceilometer_pub_sub_url", value)
+
 class MonitoringChannel(TenantWithContainer):   # aka 'CeilometerTenant'
     class Meta:
         proxy = True
diff --git a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.py b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.py
index db7d318..2c0ba10 100644
--- a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.py
+++ b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.py
@@ -10,7 +10,7 @@
 from synchronizers.base.ansible import run_template_ssh
 from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
 from core.models import Service, Slice
-from services.ceilometer.models import MonitoringChannel
+from services.ceilometer.models import CeilometerService, MonitoringChannel
 from xos.logger import Logger, logging
 
 parentdir = os.path.join(os.path.dirname(__file__),"..")
@@ -42,6 +42,13 @@
         #   2) Ceilometer API service endpoint URL if running externally
         #   3) Credentials to access Ceilometer API service
 
+        ceilometer_services = CeilometerService.get_service_objects().filter(id=o.provider_service.id)
+        if not ceilometer_services:
+            raise "No associated Ceilometer service"
+        ceilometer_service = ceilometer_services[0]
+        ceilometer_pub_sub_url = ceilometer_service.ceilometer_pub_sub_url
+        if not ceilometer_pub_sub_url:
+            ceilometer_pub_sub_url = ''
         instance = self.get_instance(o)
 
         try:
@@ -55,6 +62,7 @@
                   "admin_user":instance.controller.admin_user,
                   "admin_password":instance.controller.admin_password,
                   "admin_tenant":instance.controller.admin_tenant,
+                  "ceilometer_pub_sub_url": ceilometer_pub_sub_url,
                   "full_setup": full_setup}
 
         return fields
diff --git a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
index cedf3a4..6cda511 100644
--- a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
+++ b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
@@ -16,6 +16,7 @@
       ceilometer_client_acess_ip: {{ ceilometer_ip }}
       ceilometer_client_acess_mac: {{ ceilometer_mac }}
       ceilometer_host_port: {{ ceilometer_port }}
+      ceilometer_pub_sub_url: {{ ceilometer_pub_sub_url }}
       allowed_tenant_ids:
         {% for allowed_tenant_id in allowed_tenant_ids %}
         - {{ allowed_tenant_id }}
diff --git a/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_config.j2 b/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_config.j2
index 4c712f1..bd6c521 100644
--- a/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_config.j2
+++ b/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_config.j2
@@ -7,6 +7,7 @@
 admin_user={{ admin_user }}
 admin_tenant={{ admin_tenant }}
 admin_password={{ admin_password }}
+ceilometer_pub_sub_url={{ ceilometer_pub_sub_url }}
 
 [allowed_tenants]
 {% if allowed_tenant_ids %}
diff --git a/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_server.py b/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_server.py
index 62f0804..c81b941 100644
--- a/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_server.py
+++ b/xos/synchronizers/monitoring_channel/templates/ceilometer_proxy_server.py
@@ -7,6 +7,7 @@
 import logging
 import urllib
 import urllib2
+from urlparse import urlparse
 from wsgilog import WsgiLog
 
 web.config.debug=False
@@ -252,6 +253,11 @@
     def POST(self):
         global config
         parse_ceilometer_proxy_config()
+        ceilometer_pub_sub_url = config.get('default', 'ceilometer_pub_sub_url')
+        url = urlparse(ceilometer_pub_sub_url)
+        if (not url.scheme) or (not url.netloc): 
+             raise Exception("Ceilometer PUB/SUB URL not set")
+        ceilometer_pub_sub_url = url.scheme + "://" + url.netloc + "/subscribe"
         data_str = unicode(web.data(),'iso-8859-1')
         post_data = json.loads(data_str)
         final_query=[]
@@ -262,7 +268,7 @@
              raise Exception("Not allowed to subscribe to any meters")
         post_data["query"] = final_query
         #TODO: The PUB/SUB url needs to be read from config
-        put_request = urllib2.Request("http://10.11.10.1:4455/subscribe", json.dumps(post_data))
+        put_request = urllib2.Request(ceilometer_pub_sub_url, json.dumps(post_data))
         put_request.get_method = lambda: 'SUB'
         put_request.add_header('Content-Type', 'application/json')
         response = urllib2.urlopen(put_request)
@@ -270,9 +276,14 @@
         return json.dumps(response_text)
 
     def DELETE(self):
+        ceilometer_pub_sub_url = config.get('default', 'ceilometer_pub_sub_url')
+        url = urlparse(ceilometer_pub_sub_url)
+        if (not url.scheme) or (not url.netloc): 
+             raise Exception("Ceilometer PUB/SUB URL not set")
+        ceilometer_pub_sub_url = url.scheme + "://" + url.netloc + "/unsubscribe"
         data_str = web.data()
         #TODO: The PUB/SUB url needs to be read from config
-        put_request = urllib2.Request("http://10.11.10.1:4455/unsubscribe", data_str)
+        put_request = urllib2.Request(ceilometer_pub_sub_url, data_str)
         put_request.get_method = lambda: 'UNSUB'
         put_request.add_header('Content-Type', 'application/json')
         response = urllib2.urlopen(put_request)