本文整理汇总了Python中charmhelpers.core.hookenv.action_get方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.action_get方法的具体用法?Python hookenv.action_get怎么用?Python hookenv.action_get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.hookenv
的用法示例。
在下文中一共展示了hookenv.action_get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_pool
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def create_pool():
pool_name = action_get("name")
pool_type = action_get("pool-type")
try:
if pool_type == "replicated":
replicas = action_get("replicas")
replicated_pool = ReplicatedPool(name=pool_name,
service='admin',
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='admin')
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)))
示例2: pool_stats
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def pool_stats():
try:
pool_name = action_get("pool-name")
cluster = connect()
ioctx = cluster.open_ioctx(pool_name)
stats = ioctx.get_stats()
ioctx.close()
cluster.shutdown()
return stats
except (rados.Error,
rados.IOError,
rados.ObjectNotFound,
rados.NoData,
rados.NoSpace,
rados.PermissionError) as e:
action_fail(str(e))
示例3: update_crushmap
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def update_crushmap():
try:
encoded_text = action_get("map")
json_map = base64.b64decode(encoded_text)
try:
# This needs json_map passed to it from stdin
crushtool = Popen(
["crushtool", "-o", "compiled_crushmap", "-m", "compile"],
stdin=PIPE)
crushtool_stdout, crushtool_stderr = crushtool.communicate(
input=json_map)
if crushtool_stderr is not None:
action_fail(
"Failed to compile json: {}".format(crushtool_stderr))
check_output(
["ceph", "osd", "setcrushmap", "-i", "compiled_crushmap"])
except (CalledProcessError, OSError) as err2:
action_fail("Crush compile or load failed with error: {}".format(
err2.output))
except TypeError as err:
action_fail(
"Unable to base64 decode: {}. Error: {}".format(encoded_text, err))
示例4: delete_cache_tier
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def delete_cache_tier():
backer_pool = action_get("backer-pool")
cache_pool = action_get("cache-pool")
# Pre flight checks
if not pool_exists('admin', backer_pool):
log("Backer pool {} must exist before calling this".format(
backer_pool))
action_fail("remove-cache-tier failed. Backer pool {} must exist "
"before calling this".format(backer_pool))
if not pool_exists('admin', cache_pool):
log("Cache pool {} must exist before calling this".format(
cache_pool))
action_fail("remove-cache-tier failed. Cache pool {} must exist "
"before calling this".format(cache_pool))
pool = Pool(service='admin', name=backer_pool)
try:
pool.remove_cache_tier(cache_pool=cache_pool)
except CalledProcessError as err:
log("Removing the cache tier failed with message: {}".format(str(err)))
action_fail("remove-cache-tier failed. Removing the cache tier failed "
"with message: {}".format(str(err)))
示例5: enable_volume_quota
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def enable_volume_quota():
"""
Enable quotas on the volume
"""
# Gather our action parameters
vol = action_get("volume")
usage_limit = action_get("usage-limit")
parsed_usage_limit = int(usage_limit)
path = action_get("path")
# Turn quotas on if not already enabled
quotas_enabled = volume.volume_quotas_enabled(vol)
if quotas_enabled.is_err():
action_fail("Enable quota failed: {}".format(quotas_enabled.value))
if not quotas_enabled.value:
try:
volume.volume_enable_quotas(vol)
except GlusterCmdException as e:
action_fail("Enable quotas failed: {}".format(e))
try:
volume.volume_add_quota(vol, path, parsed_usage_limit)
except GlusterCmdException as e:
action_fail("Add quota failed: {}".format(e))
示例6: list_volume_quotas
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def list_volume_quotas():
"""
List quotas on the volume
"""
vol = action_get("volume")
quotas_enabled = volume.volume_quotas_enabled(vol)
if quotas_enabled.is_err():
action_fail("List quota failed: {}".format(quotas_enabled.value))
if quotas_enabled.value:
quotas = volume.quota_list(vol)
if quotas.is_err():
action_fail(
"Failed to get volume quotas: {}".format(quotas.value))
quota_strings = []
for quota in quotas.value:
quota_string = "path:{} limit:{} used:{}".format(
quota.path,
quota.hard_limit,
quota.used)
quota_strings.append(quota_string)
action_set({"quotas": "\n".join(quota_strings)})
示例7: set_volume_options
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def set_volume_options():
"""
Set one or more options on the volume at once
"""
vol = action_get("volume")
# Gather all of the action parameters up at once. We don't know what
# the user wants to change.
options = action_get()
settings = []
for key in options:
if key != "volume":
settings.append(
volume.GlusterOption.from_str(key, options[key]))
volume.volume_set_options(vol, settings)
# Actions to function mapping, to allow for illegal python action names that
# can map to a python function.
示例8: pool_stats
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def pool_stats():
try:
pool_name = action_get("pool-name")
cluster = connect()
ioctx = cluster.open_ioctx(pool_name)
stats = ioctx.get_stats()
ioctx.close()
cluster.shutdown()
return stats
except (rados.Error,
rados.IOError,
rados.ObjectNotFound,
rados.NoData,
rados.NoSpace,
rados.PermissionError) as e:
action_fail(e.message)
示例9: delete_cache_tier
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def delete_cache_tier():
backer_pool = action_get("backer-pool")
cache_pool = action_get("cache-pool")
# Pre flight checks
if not pool_exists('admin', backer_pool):
log("Backer pool {} must exist before calling this".format(
backer_pool))
action_fail("remove-cache-tier failed. Backer pool {} must exist "
"before calling this".format(backer_pool))
if not pool_exists('admin', cache_pool):
log("Cache pool {} must exist before calling this".format(
cache_pool))
action_fail("remove-cache-tier failed. Cache pool {} must exist "
"before calling this".format(cache_pool))
pool = Pool(service='admin', name=backer_pool)
try:
pool.remove_cache_tier(cache_pool=cache_pool)
except CalledProcessError as err:
log("Removing the cache tier failed with message: {}".format(
err.message))
action_fail("remove-cache-tier failed. Removing the cache tier failed "
"with message: {}".format(err.message))
示例10: get_devices
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def get_devices():
"""Parse 'osd-devices' action parameter, returns list."""
devices = []
for path in hookenv.action_get('osd-devices').split(' '):
path = path.strip()
if not os.path.isabs(path):
raise Error('{}: Not absolute path.'.format(path))
devices.append(path)
return devices
示例11: get_devices
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def get_devices():
devices = []
for path in hookenv.action_get('osd-devices').split(' '):
path = path.strip()
if os.path.isabs(path):
devices.append(path)
return devices
示例12: delete_erasure_profile
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def delete_erasure_profile():
name = action_get("name")
try:
remove_erasure_profile(service='admin', profile_name=name)
except CalledProcessError as e:
log("Remove erasure profile failed with error {}".format(str(e)),
level="ERROR")
action_fail("Remove erasure profile failed with error: {}"
.format(str(e)))
示例13: pool_get
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def pool_get():
key = action_get("key")
pool_name = action_get("pool_name")
try:
value = (check_output(['ceph', 'osd', 'pool', 'get', pool_name, key])
.decode('UTF-8'))
return value
except CalledProcessError as e:
action_fail(str(e))
示例14: set_pool
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def set_pool():
key = action_get("key")
value = action_get("value")
pool_name = action_get("pool_name")
pool_set(service='ceph', pool_name=pool_name, key=key, value=value)
示例15: set_pool_max_bytes
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import action_get [as 别名]
def set_pool_max_bytes():
pool_name = action_get("pool-name")
max_bytes = action_get("max")
set_pool_quota(service='ceph',
pool_name=pool_name,
max_bytes=max_bytes)