本文整理汇总了Python中ovs.extensions.storage.persistentfactory.PersistentFactory类的典型用法代码示例。如果您正苦于以下问题:Python PersistentFactory类的具体用法?Python PersistentFactory怎么用?Python PersistentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pks
def get_pks(namespace, name):
"""
This method will load the primary keys for a given namespace and name
"""
persistent = PersistentFactory.get_client()
prefix = '{0}_{1}_'.format(namespace, name)
return set([key.replace(prefix, '') for key in persistent.prefix(prefix, max_elements=-1)])
示例2: _set
def _set(key, value, raw):
key = EtcdConfiguration._coalesce_dashes(key=key)
data = value
if raw is False:
data = json.dumps(value)
# Unittests
if hasattr(unittest, 'running_tests') and getattr(unittest, 'running_tests') is True:
stripped_key = key.strip('/')
ut_data = EtcdConfiguration._unittest_data
for part in stripped_key.split('/')[:-1]:
if part not in ut_data:
ut_data[part] = {}
ut_data = ut_data[part]
ut_data[stripped_key.split('/')[-1]] = data
return
# Real implementation
client = EtcdConfiguration._get_client()
client.write(key, data)
try:
def _escape(*args, **kwargs):
_ = args, kwargs
raise RuntimeError()
from ovs.extensions.storage.persistentfactory import PersistentFactory
client = PersistentFactory.get_client()
signal.signal(signal.SIGALRM, _escape)
signal.alarm(0.5) # Wait only 0.5 seconds. This is a backup and should not slow down the system
client.set(key, value)
signal.alarm(0)
except:
pass
示例3: get_relation_set
def get_relation_set(remote_class, remote_key, own_class, own_key, own_guid):
"""
This method will get a DataList for a relation.
On a cache miss, the relation DataList will be rebuild and due to the nature of the full table scan, it will
update all relations in the mean time.
For below parameter information, use following example: We called "my_vmachine.vdisks".
:param remote_class: The class of the remote part of the relation (e.g. VDisk)
:param remote_key: The key in the remote_class that points to us (e.g. vmachine)
:param own_class: The class of the base object of the relation (e.g. VMachine)
:param own_key: The key in this class pointing to the remote classes (e.g. vdisks)
:param own_guid: The guid of this object instance (e.g. the guid of my_vmachine)
"""
# Example:
# * remote_class = VDisk
# * remote_key = vmachine
# * own_class = VMachine
# * own_key = vdisks
# Called to load the vMachine.vdisks list (resulting in a possible scan of vDisk objects)
# * own_guid = this vMachine object's guid
persistent = PersistentFactory.get_client()
own_name = own_class.__name__.lower()
datalist = DataList(remote_class, {}, '{0}_{1}_{2}'.format(own_name, own_guid, remote_key))
reverse_key = 'ovs_reverseindex_{0}_{1}|{2}|'.format(own_name, own_guid, own_key)
datalist._guids = [guid.replace(reverse_key, '') for guid in persistent.prefix(reverse_key)]
return datalist
示例4: __init__
def __init__(self, object_type, query, key=None):
"""
Initializes a DataList class with a given key (used for optional caching) and a given query
:param object_type: The type of the objects that have to be queried
:param query: The query to execute
:param key: A key under which the result must be cached
"""
super(DataList, self).__init__()
if key is not None:
self._key = '{0}_{1}'.format(DataList.NAMESPACE, key)
else:
identifier = copy.deepcopy(query)
identifier['object'] = object_type.__name__
self._key = '{0}_{1}'.format(DataList.NAMESPACE, hashlib.sha256(json.dumps(identifier)).hexdigest())
self._volatile = VolatileFactory.get_client()
self._persistent = PersistentFactory.get_client()
self._query = query
self._can_cache = True
self._object_type = object_type
self._data = {}
self._objects = {}
self._guids = None
self._executed = False
self._shallow_sort = True
self.from_cache = None
示例5: _get
def _get(key):
if key == 'ovs.core.storage.persistent':
return 'arakoon'
c = PersistentFactory.get_client()
if c.exists(key):
return c.get(key)
return None
示例6: get_pks
def get_pks(namespace, name):
"""
This method will load the primary keys for a given namespace and name
"""
persistent = PersistentFactory.get_client()
prefix = '{0}_{1}_'.format(namespace, name)
for key in persistent.prefix(prefix):
yield key.replace(prefix, '')
示例7: tearDownClass
def tearDownClass(cls):
"""
Clean up the unittest
"""
fakesleep.monkey_restore()
cls.volatile = VolatileFactory.get_client()
cls.volatile.clean()
cls.persistent = PersistentFactory.get_client()
cls.persistent.clean()
示例8: setUpClass
def setUpClass(cls):
"""
Sets up the unittest, mocking a certain set of 3rd party libraries and extensions.
This makes sure the unittests can be executed without those libraries installed
"""
cls.persistent = PersistentFactory.get_client()
cls.persistent.clean()
cls.volatile = VolatileFactory.get_client()
cls.volatile.clean()
示例9: __init__
def __init__(self):
self._works = False
self._getepoch = lambda: int(time.time())
self._begintime = self._getepoch()
self._waitlimit = 1800
self._client = PersistentFactory.get_client('arakoon')
self._key = 'ensureworks'
self._valueguid = str(uuid.uuid4())
self._value = '{0}{1}'
示例10: __init__
def __init__(self, *args, **kwargs):
"""
Initializes the distributed scheduler
"""
self._persistent = PersistentFactory.get_client()
self._namespace = 'ovs_celery_beat'
self._mutex = VolatileMutex('celery_beat')
self._has_lock = False
super(DistributedScheduler, self).__init__(*args, **kwargs)
logger.debug('DS init')
示例11: tearDownClass
def tearDownClass(cls):
"""
Tear down changes made during setUpClass
"""
Configuration._unittest_data = {}
cls.persistent = PersistentFactory.get_client()
cls.persistent.clean()
cls.volatile = VolatileFactory.get_client()
cls.volatile.clean()
示例12: __init__
def __init__(self, *args, **kwargs):
"""
Initializes the distributed scheduler
"""
self._logger = LogHandler.get('celery', name='celery beat')
self._persistent = PersistentFactory.get_client()
self._namespace = 'ovs_celery_beat'
self._mutex = volatile_mutex('celery_beat', 10)
self._schedule_info = {}
self._has_lock = False
super(DistributedScheduler, self).__init__(*args, **kwargs)
self._logger.debug('DS init')
示例13: _set
def _set(key, value, raw):
client = EtcdConfiguration._get_client()
data = value
if raw is False:
data = json.dumps(value)
client.write(key, data)
try:
from ovs.extensions.storage.persistentfactory import PersistentFactory
client = PersistentFactory.get_client()
client.set(key, value)
except:
pass
示例14: setUpClass
def setUpClass(cls):
"""
Sets up the unittest, mocking a certain set of 3rd party libraries and extensions.
This makes sure the unittests can be executed without those libraries installed
"""
cls.persistent = PersistentFactory.get_client()
cls.persistent.clean()
cls.volatile = VolatileFactory.get_client()
cls.volatile.clean()
StorageRouterClient.clean()
fakesleep.monkey_patch()
Configuration.set('/ovs/framework/arakoon_clusters|voldrv', 'voldrv')
Configuration.set('/ovs/framework/hosts/1/ports', {'arakoon': [10000, 10100]})
Configuration.set('/ovs/framework/rdma', False)
示例15: setUpClass
def setUpClass(cls):
"""
Sets up the unittest, mocking a certain set of 3rd party libraries and extensions.
This makes sure the unittests can be executed without those libraries installed
"""
cls.persistent = PersistentFactory.get_client()
cls.persistent.clean()
cls.volatile = VolatileFactory.get_client()
cls.volatile.clean()
StorageRouterClient.clean()
fakesleep.monkey_patch()
Configuration.set('/ovs/framework/storagedriver|mds_tlogs', 100)
Configuration.set('/ovs/framework/storagedriver|mds_maxload', 75)
Configuration.set('/ovs/framework/storagedriver|mds_safety', 2)