import collectd
from cinderclient.client import Client as CinderClient
from cinderclient import exceptions
import traceback

#== Our Own Functions go here: ==#
def configer(ObjConfiguration):
   collectd.debug('Configuring Stuff') 

def initer():
    collectd.debug('initing stuff')

def reader(input_data=None):
    metric = collectd.Values();
    metric.plugin = 'cinder_plugin'
    metric.type = 'volumes_count'

    client = CinderClient('2', ‘myuser’, ‘my password’, 'services', 'https://svl-fab7-lab1.cisco.com:5000/v
2.0')
    volumes_count = client.volumes.list()
    metric.values = [len(volumes_count)]
    metric.host = 'OverwritenHostname'
    total_count = len(volumes_count)
    metric.dispatch()
    metric.type = 'volume-snapshots-count'
    snapshots = client.volume_snapshots.list()
    total_snap = len(snapshots)
    metric.values = [len(snapshots)]
    metric.dispatch()

def write(val, data=None):
    '''Prepare value before writing '''
    client = CinderClient('2', ‘myuser’, ‘mypassword’, 'services', 'https://svl-fab7-lab1.cisco.com:5000/v
2.0')
    volumes_count = client.volumes.list()
#    data=volumes_count[1]
    for data in volumes_count[:]:
        collectd.info('skher: writing data (val=%r, data=%r)' % (val, data))
    for v in val.values:
        collectd.info("skher: writing %s (%s): %f" % (val.plugin, val.type, v))

#== Hook Callbacks, Order is important! ==#
collectd.register_config(configer)
collectd.register_init(initer)
collectd.register_read(reader)
collectd.register_write(write)