Shutdown Source VM (PAUSED) on successfull migration + blackened all .py files
This commit is contained in:
parent
29e938dc74
commit
9bdf4d2180
31 changed files with 1307 additions and 638 deletions
|
|
@ -8,7 +8,7 @@ from functools import wraps
|
|||
|
||||
from . import logger
|
||||
|
||||
PseudoEtcdMeta = namedtuple('PseudoEtcdMeta', ['key'])
|
||||
PseudoEtcdMeta = namedtuple("PseudoEtcdMeta", ["key"])
|
||||
|
||||
|
||||
class EtcdEntry:
|
||||
|
|
@ -16,8 +16,8 @@ class EtcdEntry:
|
|||
# value: str
|
||||
|
||||
def __init__(self, meta, value, value_in_json=False):
|
||||
self.key = meta.key.decode('utf-8')
|
||||
self.value = value.decode('utf-8')
|
||||
self.key = meta.key.decode("utf-8")
|
||||
self.value = value.decode("utf-8")
|
||||
|
||||
if value_in_json:
|
||||
self.value = json.loads(self.value)
|
||||
|
|
@ -29,11 +29,18 @@ def readable_errors(func):
|
|||
try:
|
||||
return func(*args, **kwargs)
|
||||
except etcd3.exceptions.ConnectionFailedError as err:
|
||||
raise etcd3.exceptions.ConnectionFailedError('etcd connection failed.') from err
|
||||
raise etcd3.exceptions.ConnectionFailedError(
|
||||
"etcd connection failed."
|
||||
) from err
|
||||
except etcd3.exceptions.ConnectionTimeoutError as err:
|
||||
raise etcd3.exceptions.ConnectionTimeoutError('etcd connection timeout.') from err
|
||||
raise etcd3.exceptions.ConnectionTimeoutError(
|
||||
"etcd connection timeout."
|
||||
) from err
|
||||
except Exception:
|
||||
logger.exception('Some etcd error occured. See syslog for details.')
|
||||
logger.exception(
|
||||
"Some etcd error occured. See syslog for details."
|
||||
)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
|
|
@ -56,7 +63,7 @@ class Etcd3Wrapper:
|
|||
_value = json.dumps(_value)
|
||||
|
||||
if not isinstance(_key, str):
|
||||
_key = _key.decode('utf-8')
|
||||
_key = _key.decode("utf-8")
|
||||
|
||||
return self.client.put(_key, _value, **kwargs)
|
||||
|
||||
|
|
@ -70,18 +77,25 @@ class Etcd3Wrapper:
|
|||
|
||||
@readable_errors
|
||||
def watch_prefix(self, key, timeout=0, value_in_json=False):
|
||||
timeout_event = EtcdEntry(PseudoEtcdMeta(key=b'TIMEOUT'),
|
||||
value=str.encode(json.dumps({'status': 'TIMEOUT',
|
||||
'type': 'TIMEOUT'})),
|
||||
value_in_json=value_in_json)
|
||||
timeout_event = EtcdEntry(
|
||||
PseudoEtcdMeta(key=b"TIMEOUT"),
|
||||
value=str.encode(
|
||||
json.dumps({"status": "TIMEOUT", "type": "TIMEOUT"})
|
||||
),
|
||||
value_in_json=value_in_json,
|
||||
)
|
||||
|
||||
event_queue = queue.Queue()
|
||||
|
||||
def add_event_to_queue(event):
|
||||
if hasattr(event, 'events'):
|
||||
if hasattr(event, "events"):
|
||||
for e in event.events:
|
||||
if e.value:
|
||||
event_queue.put(EtcdEntry(e, e.value, value_in_json=value_in_json))
|
||||
event_queue.put(
|
||||
EtcdEntry(
|
||||
e, e.value, value_in_json=value_in_json
|
||||
)
|
||||
)
|
||||
|
||||
self.client.add_watch_prefix_callback(key, add_event_to_queue)
|
||||
|
||||
|
|
@ -96,4 +110,8 @@ class Etcd3Wrapper:
|
|||
|
||||
class PsuedoEtcdEntry(EtcdEntry):
|
||||
def __init__(self, key, value, value_in_json=False):
|
||||
super().__init__(PseudoEtcdMeta(key=key.encode('utf-8')), value, value_in_json=value_in_json)
|
||||
super().__init__(
|
||||
PseudoEtcdMeta(key=key.encode("utf-8")),
|
||||
value,
|
||||
value_in_json=value_in_json,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue