Files
charm-ceph-mon/actions/create_pool.py
James Page 4fd788d3a2 Updates for improved EC support
Sync charmhelpers and charms.openstack to pickup changes for
improved Erasure Coded pool support.

Update action code for EC profile creation for extended
option support and other charmhelpers changes.

Depends-On: I2547933964849f7af1c623b2fbc014fb332839ef
Change-Id: Iec4de19f7b39f0b08158d96c5cc1561b40aefa10
2020-08-07 15:24:59 +01:00

64 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python3
#
# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append('hooks')
from subprocess import CalledProcessError
from charmhelpers.core.hookenv import action_get, 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")
percent_data = action_get("percent-data") or 10
app_name = action_get("app-name") or 'unknown'
try:
if pool_type == "replicated":
replicas = action_get("replicas")
replicated_pool = ReplicatedPool(name=pool_name,
service='admin',
replicas=replicas,
app_name=app_name,
percent_data=float(percent_data),
)
replicated_pool.create()
elif pool_type in ("erasure", "erasure-coded"):
crush_profile_name = action_get("erasure-profile-name")
allow_ec_overwrites = action_get("allow-ec-overwrites")
erasure_pool = ErasurePool(name=pool_name,
erasure_code_profile=crush_profile_name,
service='admin',
app_name=app_name,
percent_data=float(percent_data),
allow_ec_overwrites=allow_ec_overwrites,
)
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()