Efforts to make ucloud a python package
This commit is contained in:
parent
bbe09667a6
commit
1e7300b56e
71 changed files with 241 additions and 1043 deletions
21
ucloud/common/counters.py
Normal file
21
ucloud/common/counters.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from etcd3_wrapper import Etcd3Wrapper
|
||||
|
||||
|
||||
def increment_etcd_counter(etcd_client: Etcd3Wrapper, key):
|
||||
kv = etcd_client.get(key)
|
||||
|
||||
if kv:
|
||||
counter = int(kv.value)
|
||||
counter = counter + 1
|
||||
else:
|
||||
counter = 1
|
||||
|
||||
etcd_client.put(key, str(counter))
|
||||
return counter
|
||||
|
||||
|
||||
def get_etcd_counter(etcd_client: Etcd3Wrapper, key):
|
||||
kv = etcd_client.get(key)
|
||||
if kv:
|
||||
return int(kv.value)
|
||||
return None
|
||||
Loading…
Add table
Add a link
Reference in a new issue