44 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/python
#
# Copyright 2014 Canonical Ltd.
#
from charmhelpers.core.hookenv import (
log,
INFO,
ERROR
)
from charmhelpers.contrib.storage.linux.ceph import (
create_pool,
2014-11-07 15:26:58 +01:00
pool_exists
)
def process_requests(reqs):
"""Process a Ceph broker request from a ceph client."""
log("Processing %s ceph broker requests" % (len(reqs)), level=INFO)
for req in reqs:
op = req.get('op')
log("Processing op='%s'" % (op), level=INFO)
# Use admin client since we do not have other client key locations
# setup to use them for these operations.
svc = 'admin'
if op == "create_pool":
2014-11-08 20:15:17 +00:00
pool = req.get('name')
replicas = req.get('replicas')
if not all([pool, replicas]):
log("Missing parameter(s)", level=ERROR)
return 1
if not pool_exists(service=svc, name=pool):
2014-11-08 20:15:17 +00:00
log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
level=INFO)
create_pool(service=svc, name=pool, replicas=replicas)
else:
2014-11-08 20:15:17 +00:00
log("Pool '%s' already exists - skipping create" % (pool),
level=INFO)
else:
log("Unknown operation '%s'" % (op))
return 1
return 0