Code Changes includes:
 1.Sychronizer for ceilometer service.
 2.Added files:
   i.xos/synchronizer/steps/sync_ceilometerservice.py(Ceilometer sychronizer )
   ii.xos/synchronizer/steps/sync_ceilometerservice.yaml(Ansible yaml file which will be run as part of sychronizer)
   iii.xos/synchronizer/templates/update-keystone-endpoints.py.j2 (to change endpoints in keystone)
 3.Modified init script of ceilometer service image for starting pub-sub module
 4. [api] default_api_return_limit = 1000 in README and ceilometer.conf.j2 for both mitaka-v2 and mitaka-v3

Change-Id: I2ab935c2fc507a00729d14cf87bae81990b75ed9
diff --git a/xos/models.py b/xos/models.py
index 4ab3c15..0960152 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -19,6 +19,8 @@
     LOOK_FOR_IMAGES=[ "ceilometer-service-trusty-server-multi-nic",
                     ]
 
+    sync_attributes = ("private_ip", "private_mac",
+                       "nat_ip", "nat_mac", )
     class Meta:
         app_label = "monitoring"
         verbose_name = "Ceilometer Service"
diff --git a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/README b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/README
index 76040e5..817816d 100644
--- a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/README
+++ b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/README
@@ -17,7 +17,8 @@
    ii.Update entry_point.txt:
        copy the contents of ceilometer_entry_points.txt to /usr/lib/python2.7/dist-packages/ceilometer-6.0.0.egg-info/entry_points.txt under [ceilometer.notification]
 9. Update /home/ubuntu/monitoring/xos/synchronizer/ceilometer/ceilometer_pub_sub/pub_sub.conf with proper IP and port numbers and rabbitmq credentials.
-10.update /etc/ceilmeter/pipeline.yaml with required publisher info for coressponding meters.
+10.
+  i.update /etc/ceilmeter/pipeline.yaml with required publisher info for coressponding meters.
    ex:
     sources:
     - name: meter_source
@@ -33,6 +34,9 @@
       publishers:
           - notifier://
           - kafka://localhost:9092?topic=ceilometer 
+  ii.Please set the following config in /etc/ceilometer/ceilometer.conf
+   [api]
+   default_api_return_limit = 1000
   
 11.This setup by default created ceilometer topic for kafka.If any other topic is needed to use in this setup please
    create the topic before using it wih the following command.
diff --git a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v2/templates/ceilometer.conf.j2 b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v2/templates/ceilometer.conf.j2
index b89a3d9..6deb9a4 100644
--- a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v2/templates/ceilometer.conf.j2
+++ b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v2/templates/ceilometer.conf.j2
@@ -958,3 +958,6 @@
 password = password
 interface = internalURL
 region_name = RegionOne
+
+[api]
+default_api_return_limit = 1000
diff --git a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v3/templates/ceilometer.conf.j2 b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v3/templates/ceilometer.conf.j2
index b89a3d9..6deb9a4 100644
--- a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v3/templates/ceilometer.conf.j2
+++ b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/mitaka-v3/templates/ceilometer.conf.j2
@@ -958,3 +958,6 @@
 password = password
 interface = internalURL
 region_name = RegionOne
+
+[api]
+default_api_return_limit = 1000
diff --git a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/startup-scripts/zxceilostartup.sh b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/startup-scripts/zxceilostartup.sh
index 3bb04e7..52a46d1 100755
--- a/xos/synchronizer/ceilometer/ceilometer_service_custom_image/startup-scripts/zxceilostartup.sh
+++ b/xos/synchronizer/ceilometer/ceilometer_service_custom_image/startup-scripts/zxceilostartup.sh
@@ -1,8 +1,5 @@
 #!/bin/sh
-sudo sed -i "s/.*127.0.0.1.*/127.0.0.1 localhost $(hostname)/" /etc/hosts
-STARTUP_PATH=/home/ubuntu/monitoring/xos/synchronizer/ceilometer/ceilometer_service_custom_image/startup-scripts
 PUB_SUB_PATH=/home/ubuntu/monitoring/xos/synchronizer/ceilometer/ceilometer_pub_sub
-$STARTUP_PATH/ceilometer_init_script.sh
 echo $PWD
 cd $PUB_SUB_PATH
 sleep 5
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
index 806c96c..9b9e144 100644
--- a/xos/synchronizer/manifest
+++ b/xos/synchronizer/manifest
@@ -11,6 +11,7 @@
 templates/monitoring-channel.conf.j2
 templates/ceilometer_proxy_server.py
 templates/start_ceilometer_proxy
+templates/update-keystone-endpoints.py.j2
 manifest
 run.sh
 monitoring_synchronizer_config
@@ -20,6 +21,8 @@
 steps/sync_monitoringchannel.py
 steps/sync_sflowservice.yaml
 steps/sync_sflowservice.py
+steps/sync_ceilometerservice.yaml
+steps/sync_ceilometerservice.py
 files/vm-resolv.conf
 files/docker.list
 model-deps
diff --git a/xos/synchronizer/steps/sync_ceilometerservice.py b/xos/synchronizer/steps/sync_ceilometerservice.py
new file mode 100644
index 0000000..298e9d7
--- /dev/null
+++ b/xos/synchronizer/steps/sync_ceilometerservice.py
@@ -0,0 +1,69 @@
+import hashlib
+import os
+import socket
+import sys
+import base64
+import time
+#import threading
+import subprocess
+import random
+import tempfile
+#from sshtunnel import SSHTunnelForwarder
+from django.db.models import F, Q
+from xos.config import Config
+from synchronizers.base.syncstep import SyncStep
+from synchronizers.base.ansible import run_template_ssh
+from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from core.models import Service, Slice
+from services.monitoring.models import CeilometerService, MonitoringChannel
+from xos.logger import Logger, logging
+
+parentdir = os.path.join(os.path.dirname(__file__),"..")
+sys.path.insert(0,parentdir)
+
+logger = Logger(level=logging.INFO)
+
+class SyncCeilometerService(SyncInstanceUsingAnsible):
+    provides=[CeilometerService]
+    observes=CeilometerService
+    requested_interval=0
+    template_name = "sync_ceilometerservice.yaml"
+    service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
+
+    def __init__(self, *args, **kwargs):
+        super(SyncCeilometerService, self).__init__(*args, **kwargs)
+
+    def fetch_pending(self, deleted):
+        if (not deleted):
+            objs = CeilometerService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
+        else:
+            objs = CeilometerService.get_deleted_service_objects()
+
+        return objs
+
+    def get_instance(self, o):
+        return o.get_instance()
+
+    def get_extra_attributes(self, o):
+        fields={}
+        fields["instance_hostname"] = o.get_instance().instance_name.replace("_","-")
+        #fields = {"instance_hostname": o.get_instance().instance_name.replace("_","-"),
+        #          "instance_ip": o.get_instance().private_ip()}
+
+
+        return fields
+
+    def sync_fields(self, o, fields):
+        # the super causes the playbook to be run
+        super(SyncCeilometerService, self).sync_fields(o, fields)
+
+    def run_playbook(self, o, fields):
+        instance = self.get_instance(o)
+        #if (instance.isolation=="container"):
+            # If the instance is already a container, then we don't need to
+            # install ONOS.
+        #    return
+        super(SyncCeilometerService,self).run_playbook(o, fields)
+
+    def delete_record(self, m):
+        pass
diff --git a/xos/synchronizer/steps/sync_ceilometerservice.yaml b/xos/synchronizer/steps/sync_ceilometerservice.yaml
new file mode 100644
index 0000000..6b67e31
--- /dev/null
+++ b/xos/synchronizer/steps/sync_ceilometerservice.yaml
@@ -0,0 +1,30 @@
+---
+# ceilometer_service_playbook
+- hosts: "{{ instance_name }}"
+  gather_facts: False
+  connection: ssh
+  user: ubuntu
+  sudo: yes
+  vars: 
+      host_name: {{ instance_hostname }} 
+      host_private_ip: {{ private_ip }}
+      host_nat_ip: {{ nat_ip }} 
+  tasks:
+
+  - name: Fix /etc/hosts
+    lineinfile:
+      dest=/etc/hosts
+      regexp="127.0.0.1 localhost"
+      line="127.0.0.1 localhost {{ instance_hostname }}"
+
+  - name : Adding Rabbitmq user
+    shell : rabbitmqctl add_user openstack "password";rabbitmqctl set_permissions openstack ".*" ".*" ".*"
+
+  - name: Coping keystone endpoint script
+    template: src=/opt/xos/synchronizers/monitoring/templates/update-keystone-endpoints.py.j2 dest=/usr/local/bin/update-keystone-endpoints.py owner=root group=root mode=0777
+
+  - name: Changing keystone public endpoint in mysql
+    shell: update-keystone-endpoints.py --username root --password password --host localhost --endpoint {{ private_ip }} --endpoint-type public
+
+  - name: Changing keystone admin endpoint in mysql
+    shell: update-keystone-endpoints.py --username root --password password --host localhost --endpoint {{ private_ip }} --endpoint-type admin 
diff --git a/xos/synchronizer/templates/update-keystone-endpoints.py.j2 b/xos/synchronizer/templates/update-keystone-endpoints.py.j2
new file mode 100755
index 0000000..212be70
--- /dev/null
+++ b/xos/synchronizer/templates/update-keystone-endpoints.py.j2
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+"""
+Update the endpoints in a keystone db using mysql
+"""
+
+import MySQLdb
+import argparse
+import urlparse
+import sys
+
+def main(dbhost, username, password, new_endpoint, endpoint_type):
+    db = MySQLdb.connect(host=dbhost, user=username, passwd=password,
+            db="keystone")
+    cur = db.cursor()
+    cur.execute("select id, url from endpoint where interface='%s'" % endpoint_type)
+    for row in cur.fetchall():
+        url = str(row[1])
+        endpoint_id = str(row[0])
+        try:
+            u = urlparse.urlparse(url)
+            print "Changing %s to %s in URL %s" % (u.hostname,new_endpoint, url)
+            urlstring = "%s://%s:%s%s" % (u.scheme, new_endpoint, u.port,
+                u.path)
+            cur.execute("""UPDATE endpoint
+                            SET url=%s
+                            WHERE id=%s
+                            """, (urlstring, endpoint_id))
+        except Exception as e:
+            print "Could not parse URL, giving up: %s (%s)" % (url, e)
+            cur.close()
+            db.close()
+            sys.exit(1)
+    db.commit()
+    cur.close()
+    db.close()
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--username", help="database username", required=True)
+    parser.add_argument("--password", help="database password", required=True)
+    parser.add_argument("--host", help="database host", required=True)
+    parser.add_argument("--endpoint", help="endpoint to move the public endpoints to", required=True)
+    parser.add_argument("--endpoint-type", help="which type of endpoint to modify", required=True, choices=['public','internal','admin'])
+    args = parser.parse_args()
+    main(args.host, args.username, args.password, args.endpoint, args.endpoint_type)