當前位置: 首頁>>代碼示例>>Python>>正文


Python unitdata.kv方法代碼示例

本文整理匯總了Python中charmhelpers.core.unitdata.kv方法的典型用法代碼示例。如果您正苦於以下問題:Python unitdata.kv方法的具體用法?Python unitdata.kv怎麽用?Python unitdata.kv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在charmhelpers.core.unitdata的用法示例。


在下文中一共展示了unitdata.kv方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_broker_action_done

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def is_broker_action_done(action, rid=None, unit=None):
    """Check whether broker action has completed yet.

    @param action: name of action to be performed
    @returns True if action complete otherwise False
    """
    rdata = relation_get(rid, unit) or {}
    broker_rsp = rdata.get(get_broker_rsp_key())
    if not broker_rsp:
        return False

    rsp = CephBrokerRsp(broker_rsp)
    unit_name = local_unit().partition('/')[2]
    key = "unit_{}_ceph_broker_action.{}".format(unit_name, action)
    kvstore = kv()
    val = kvstore.get(key=key)
    if val and val == rsp.request_id:
        return True

    return False 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:22,代碼來源:ceph.py

示例2: mark_broker_action_done

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def mark_broker_action_done(action, rid=None, unit=None):
    """Mark action as having been completed.

    @param action: name of action to be performed
    @returns None
    """
    rdata = relation_get(rid, unit) or {}
    broker_rsp = rdata.get(get_broker_rsp_key())
    if not broker_rsp:
        return

    rsp = CephBrokerRsp(broker_rsp)
    unit_name = local_unit().partition('/')[2]
    key = "unit_{}_ceph_broker_action.{}".format(unit_name, action)
    kvstore = kv()
    kvstore.set(key=key, value=rsp.request_id)
    kvstore.flush() 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:19,代碼來源:ceph.py

示例3: contents_match

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def contents_match(self, path):
        """Determines if the file content is the same.

        This is determined by comparing hashsum of the file contents and
        the saved hashsum. If there is no hashsum, then the content cannot
        be sure to be the same so treat them as if they are not the same.
        Otherwise, return True if the hashsums are the same, False if they
        are not the same.

        :param path: the file to check.
        """
        checksum = file_hash(path)

        kv = unitdata.kv()
        stored_checksum = kv.get('hardening:%s' % path)
        if not stored_checksum:
            # If the checksum hasn't been generated, return False to ensure
            # the file is written and the checksum stored.
            log('Checksum for %s has not been calculated.' % path, level=DEBUG)
            return False
        elif stored_checksum != checksum:
            log('Checksum mismatch for %s.' % path, level=DEBUG)
            return False

        return True 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:27,代碼來源:file.py

示例4: unitdata_cmd

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def unitdata_cmd(subparser):
    nested = subparser.add_subparsers()
    get_cmd = nested.add_parser('get', help='Retrieve data')
    get_cmd.add_argument('key', help='Key to retrieve the value of')
    get_cmd.set_defaults(action='get', value=None)
    set_cmd = nested.add_parser('set', help='Store data')
    set_cmd.add_argument('key', help='Key to set')
    set_cmd.add_argument('value', help='Value to store')
    set_cmd.set_defaults(action='set')

    def _unitdata_cmd(action, key, value):
        if action == 'get':
            return unitdata.kv().get(key)
        elif action == 'set':
            unitdata.kv().set(key, value)
            unitdata.kv().flush()
            return ''
    return _unitdata_cmd 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:20,代碼來源:unitdata.py

示例5: service_restart_handler

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def service_restart_handler(relation_id=None, unit=None,
                            default_service=None):
    '''Handler for detecting requests from subordinate
    charms for restarts of services'''
    restart_nonce = relation_get(attribute='restart-nonce',
                                 unit=unit,
                                 rid=relation_id)
    db = unitdata.kv()
    nonce_key = 'restart-nonce'
    if restart_nonce != db.get(nonce_key):
        if not is_unit_paused_set():
            service = relation_get(attribute='remote-service',
                                   unit=unit,
                                   rid=relation_id) or default_service
            if service:
                service_restart(service)
        db.set(nonce_key, restart_nonce)
        db.flush() 
開發者ID:openstack,項目名稱:charm-nova-compute,代碼行數:20,代碼來源:nova_compute_hooks.py

示例6: blacklist_remove

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def blacklist_remove():
    """
    Remove devices given in 'osd-devices' action parameter from
    unit-local devices blacklist.
    """
    db = unitdata.kv()
    blacklist = db.get(BLACKLIST_KEY, [])
    for device in get_devices():
        try:
            blacklist.remove(device)
        except ValueError:
            raise Error('{}: Device not in blacklist.'.format(device))
    db.set(BLACKLIST_KEY, blacklist)
    db.flush()


# A dictionary of all the defined actions to callables 
開發者ID:openstack,項目名稱:charm-ceph-osd,代碼行數:19,代碼來源:blacklist.py

示例7: reinstall_paste_ini

# 需要導入模塊: from charmhelpers.core import unitdata [as 別名]
# 或者: from charmhelpers.core.unitdata import kv [as 別名]
def reinstall_paste_ini():
    '''
    Re-install glance-{api,registry}-paste.ini file from packages

    Existing glance-{api,registry}-paste.ini file will be removed
    and the original files provided by the packages will be
    re-installed.

    This will only ever be performed once per unit.
    '''
    db = kv()
    if not db.get(PASTE_INI_MARKER):
        for paste_file in [GLANCE_REGISTRY_PASTE,
                           GLANCE_API_PASTE]:
            if os.path.exists(paste_file):
                os.remove(paste_file)
        apt_install(packages=['glance-api', 'glance-registry'],
                    options=REINSTALL_OPTIONS,
                    fatal=True)
        db.set(PASTE_INI_MARKER, True)
        db.flush() 
開發者ID:openstack,項目名稱:charm-glance,代碼行數:23,代碼來源:glance_utils.py


注:本文中的charmhelpers.core.unitdata.kv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。