2020-01-09 19:03:10 +00:00
|
|
|
from uncloud.common.shared import shared
|
2019-11-18 17:39:57 +00:00
|
|
|
|
|
|
|
|
2020-01-09 19:03:10 +00:00
|
|
|
def increment_etcd_counter(key):
|
|
|
|
kv = shared.etcd_client.get(key)
|
2019-11-18 17:39:57 +00:00
|
|
|
|
|
|
|
if kv:
|
|
|
|
counter = int(kv.value)
|
|
|
|
counter = counter + 1
|
|
|
|
else:
|
|
|
|
counter = 1
|
|
|
|
|
2020-01-09 19:03:10 +00:00
|
|
|
shared.etcd_client.put(key, str(counter))
|
2019-11-18 17:39:57 +00:00
|
|
|
return counter
|
|
|
|
|
|
|
|
|
2020-01-09 19:03:10 +00:00
|
|
|
def get_etcd_counter(key):
|
|
|
|
kv = shared.etcd_client.get(key)
|
2019-11-18 17:39:57 +00:00
|
|
|
if kv:
|
|
|
|
return int(kv.value)
|
|
|
|
return None
|