Merge branch 'master' of git://git.planet-lab.org/plstackapi
diff --git a/planetstack/core/views/stats.py b/planetstack/core/views/stats.py
new file mode 100644
index 0000000..46ebe2e
--- /dev/null
+++ b/planetstack/core/views/stats.py
@@ -0,0 +1,11 @@
+from django.http import HttpResponse
+from monitor import driver
+import json
+
+def Stats(request):
+    model = request.GET['model_name']
+    pk = int(request.GET['pk'])
+    meter = int(request.GET['meter'])
+    
+    meters = monitor.get_meters(meter, model, pk)
+    return json.dumps(meters)
diff --git a/planetstack/monitor/monitordriver.py b/planetstack/monitor/monitordriver.py
index f7eb1b9..77e8bfd 100644
--- a/planetstack/monitor/monitordriver.py
+++ b/planetstack/monitor/monitordriver.py
@@ -15,5 +15,5 @@
     def __init__(self):
         pass
 
-    def get_meter(self, meter_name, credentials):
+    def get_meter(self, meter_name, obj, pk, credentials=None):
         pass
diff --git a/planetstack/openstack_observer/ceilometer.py b/planetstack/openstack_observer/ceilometer.py
index 11e9851..f93dc1a 100644
--- a/planetstack/openstack_observer/ceilometer.py
+++ b/planetstack/openstack_observer/ceilometer.py
@@ -8,7 +8,19 @@
 import datetime
 import time
 from monitor.monitordriver import *
+from core.models import *
 
+def object_to_filter(model_name, pk):
+	filter_dict = {
+		'Slice':[Slice, 'tenant_id', 'project_id'],
+		'Sliver':[Sliver, 'instance_id', 'resource_id'],
+		'Site':[Site, 'tenant_id', 'project_id']
+	}
+	
+	mod,field,tag = filter_dict[model_name]
+	obj = mod.objects.get(pk=pk)
+	return '%s=%s'%(tag,mod[field])
+	
 
 def cli_to_array(cli_query):
     '''This converts from the cli list of queries to what is required
@@ -70,24 +82,27 @@
                 
 
 class CeilometerDriver(MonitorDriver):
-    def get_meter(self, meter, object_filter, keystone):
+    def get_meter(self, meter, obj, pk, keystone=None):
         if (not keystone):
             keystone = {}
             keystone['username']=env['OS_USERNAME']
             keystone['password']=env['OS_PASSWORD']
             keystone['auth_url']=env['OS_AUTH_URL']
             keystone['tenant_name']=env['OS_TENANT_NAME']
+            keystone['os_cacert']=env['OS_CACERT']
 
         ceilometer_client = client._get_ksclient(**keystone)
         token = ceilometer_client.auth_token
 
         ceilo_endpoint = client._get_endpoint(ceilometer_client, **keystone)
+	#ceilometer = client.get_client(2, username=keystone['username'], password=keystone['password'], tenant_name=keystone['tenant_name'], auth_url=keystone['auth_url'])
 
         ceilometer = client.Client('2',endpoint = ceilo_endpoint, token = lambda: token)
 
         cur_ts = datetime.datetime.fromtimestamp(time.time()-86400)
         str_ts = cur_ts.strftime('%Y-%m-%dT%H:%M:%S')
         
+		object_filter = object_to_filter(obj, pk)
         filter=';'.join([object_filter,'timestamp>%s'%str_ts])
         #query = cli_to_array("project_id=124de34266b24f57957345cdb43cc9ff;timestamp>2014-12-11T00:00:00")
         query = cli_to_array(filter)