当前位置: 首页>>代码示例>>Python>>正文


Python hookenv.action_get方法代码示例

本文整理汇总了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))) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:27,代码来源:create-pool.py

示例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)) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:18,代码来源:ceph_ops.py

示例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)) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:24,代码来源:crushmap-update.py

示例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))) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:26,代码来源:remove-cache-tier.py

示例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)) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:25,代码来源:actions.py

示例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)}) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:23,代码来源:actions.py

示例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. 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:22,代码来源:actions.py

示例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) 
开发者ID:openstack,项目名称:charm-ceph,代码行数:18,代码来源:ceph_ops.py

示例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)) 
开发者ID:openstack,项目名称:charm-ceph-proxy,代码行数:27,代码来源:remove-cache-tier.py

示例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 
开发者ID:openstack,项目名称:charm-ceph-osd,代码行数:11,代码来源:blacklist.py

示例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 
开发者ID:openstack,项目名称:charm-ceph-osd,代码行数:10,代码来源:add_disk.py

示例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))) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:12,代码来源:delete-erasure-profile.py

示例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)) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:11,代码来源:ceph_ops.py

示例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) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:7,代码来源:ceph_ops.py

示例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) 
开发者ID:openstack,项目名称:charm-ceph-mon,代码行数:8,代码来源:ceph_ops.py


注:本文中的charmhelpers.core.hookenv.action_get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。