charm-ceph-proxy/actions/create-pool
Chris MacNaughton 7359b981d6
Ensure that the actions use the configured admin user
Change-Id: I357b26fb585d68d2fbe9bbf21bbf9bfc52ac5050
Closes-Bug: #1893790
2020-09-04 16:58:24 +02:00

52 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import sys
_path = os.path.dirname(os.path.realpath(__file__))
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
_root = os.path.abspath(os.path.join(_path, '..'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_hooks)
_add_path(_root)
from subprocess import CalledProcessError
from charmhelpers.core.hookenv import action_get, config, log, action_fail
from charmhelpers.contrib.storage.linux.ceph import ErasurePool, ReplicatedPool
def create_pool():
pool_name = action_get("name")
pool_type = action_get("pool-type")
user = config('admin-user')
try:
if pool_type == "replicated":
replicas = action_get("replicas")
replicated_pool = ReplicatedPool(name=pool_name,
service=user,
replicas=replicas)
replicated_pool.create()
elif pool_type == "erasure":
crush_profile_name = action_get("erasure-profile-name")
erasure_pool = ErasurePool(name=pool_name,
erasure_code_profile=crush_profile_name,
service=user)
erasure_pool.create()
else:
log("Unknown pool type of {}. Only erasure or replicated is "
"allowed".format(pool_type))
action_fail("Unknown pool type of {}. Only erasure or replicated "
"is allowed".format(pool_type))
except CalledProcessError as e:
action_fail("Pool creation failed because of a failed process. "
"Ret Code: {} Message: {}".format(e.returncode, str(e)))
if __name__ == '__main__':
create_pool()