當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。