Commit cf217ce8 authored by Elena Grandi's avatar Elena Grandi

flake8

parent 186f3ca4
......@@ -8,6 +8,7 @@ class Event:
"""
Root class hierarchy for events
"""
__slots__ = ("timestamp", "source")
def __init__(self, source: Any, timestamp=None):
......@@ -39,14 +40,14 @@ class HostSeenEvent(HostEvent):
__slots__ = ("name", "ip", "mac", "registered")
def __init__(
self,
source: Any,
timestamp=None,
mac=None,
ip=None,
name=None,
registered=None,
):
self,
source: Any,
timestamp=None,
mac=None,
ip=None,
name=None,
registered=None,
):
super().__init__(source, timestamp=timestamp)
self.name = name
self.ip = ip
......@@ -72,13 +73,13 @@ class HostSeenEvent(HostEvent):
return res
def __str__(self):
return "HostSeenEvent(source={}, name={}, ip={}, mac={}, registered={})".format(
return "HostSeenEvent(source={}, name={}, ip={}, mac={}, registered={})".format( # noqa: E501
self.source.__class__.__name__,
repr(self.name),
repr(self.ip),
repr(self.mac),
repr(self.registered)
)
repr(self.registered),
)
def __repr__(self):
return self.__str__()
......@@ -88,13 +89,14 @@ class HostNewEvent(HostEvent):
__slots__ = ("name", "ip", "mac", "registered")
def __init__(
self,
source: Any,
timestamp=None,
mac=None,
ip=None,
name=None,
registered=None):
self,
source: Any,
timestamp=None,
mac=None,
ip=None,
name=None,
registered=None,
):
super().__init__(source, timestamp)
self.mac = mac
self.ip = ip
......@@ -160,7 +162,9 @@ class HostFactsEvent(HostEvent):
class HostFactsFailed(HostEvent):
__slots__ = ("name", "result", "details")
def __init__(self, source: Any, timestamp=None, name=None, result=None, details=None):
def __init__(
self, source: Any, timestamp=None, name=None, result=None, details=None
):
super().__init__(source, timestamp)
self.name = name
self.result = result
......@@ -177,7 +181,14 @@ class HostFactsFailed(HostEvent):
class HostPlaybookEvent(HostEvent):
__slots__ = ("name", "playbook", "playbook_id")
def __init__(self, source: Any, timestamp=None, name=None, playbook=None, playbook_id=None):
def __init__(
self,
source: Any,
timestamp=None,
name=None,
playbook=None,
playbook_id=None,
):
super().__init__(source, timestamp)
self.name = name
self.playbook = playbook
......@@ -220,13 +231,13 @@ class AnsiblePlaybookEvent(AnsibleEvent):
__slots__ = ("playbook", "playbook_id", "results")
def __init__(
self,
source: Any,
timestamp=None,
playbook=None,
playbook_id=None,
results=None,
):
self,
source: Any,
timestamp=None,
playbook=None,
playbook_id=None,
results=None,
):
super().__init__(source, timestamp)
self.playbook = playbook
self.playbook_id = playbook_id
......@@ -244,6 +255,7 @@ class Hub:
"""
Collect events and dispatch them to subscribers
"""
def __init__(self, event_log=None):
self.subscriptions = defaultdict(set)
self.event_log = event_log
......@@ -271,10 +283,10 @@ class Hub:
await asyncio.gather(*coros)
def subscribe(
self,
coro: Callable[[Event], None],
classes: Optional[Sequence[Type]] = None
):
self,
coro: Callable[[Event], None],
classes: Optional[Sequence[Type]] = None,
):
"""
Request to call the given function whenever an event is received that
is an instance of one of the given classes.
......@@ -290,10 +302,10 @@ class Hub:
self.subscriptions[c].add(coro)
def unsubscribe(
self,
coro: Callable[[Event], None],
classes: Optional[Sequence[Type]] = None
):
self,
coro: Callable[[Event], None],
classes: Optional[Sequence[Type]] = None,
):
"""
Stop calling the given coroutine on events.
......
......@@ -88,7 +88,7 @@ class Manager:
)
if not source.is_viable(self.config, dat_fname):
self.log.warn(
"ArpwatchDataSource: data source will not be started on %s",
"ArpwatchDataSource: data source will not be started on %s", # noqa: E501
dat_fname,
)
continue
......
......@@ -12,14 +12,19 @@ def permission_required(perm):
Decorator to be used on the execute method of an operation to check
that the current user has permissions to run that operation.
"""
def decorator(func):
@wraps(func)
def wrapper(op, manager):
if perms.has_permissions(op.user, perm, manager.config.permissions):
if perms.has_permissions(
op.user, perm, manager.config.permissions
):
return func(op, manager)
else:
raise OpPermissionDenied()
return wrapper
return decorator
......@@ -68,6 +73,7 @@ class Noop(Operation):
"""
Does nothing
"""
async def execute(self, manager: Manager):
pass
......@@ -76,6 +82,7 @@ class AddGroup(Operation):
"""
Associate a machine to a group
"""
def __init__(self, mac: str, group: str, **kw):
super().__init__(**kw)
self.mac = mac
......@@ -96,6 +103,7 @@ class DelGroup(Operation):
"""
Deassociate a machine from a group
"""
def __init__(self, mac: str, group: str, **kw):
super().__init__(**kw)
self.mac = mac
......@@ -109,16 +117,14 @@ class DelGroup(Operation):
@permission_required(perms.MachineGroupEdit)
async def execute(self, manager: Manager):
await manager.store.remove_machine_from_group(
self.mac,
self.group
)
await manager.store.remove_machine_from_group(self.mac, self.group)
class RunPlaybook(Operation):
"""
Run a playbook
"""
def __init__(self, hosts: str, playbook: str, **kw):
super().__init__(**kw)
self.hosts = hosts
......@@ -139,6 +145,7 @@ class RefreshFacts(Operation):
"""
Refresh facts for a machine or group of machines
"""
def __init__(self, hosts: str, **kw):
super().__init__(**kw)
self.hosts = hosts
......@@ -157,6 +164,7 @@ class WakeOnLan(Operation):
"""
Run a playbook
"""
def __init__(self, macs: List[str], **kw):
super().__init__(**kw)
self.macs = macs
......
try:
import django.core.signing
from django.core.signing import BadSignature, SignatureExpired
HAVE_SIGNING = True
except ModuleNotFoundError:
HAVE_SIGNING = False
......@@ -13,17 +14,25 @@ except ModuleNotFoundError:
if HAVE_SIGNING:
def loads(s, key, salt, max_age=None):
return django.core.signing.loads(s, key, salt, max_age=max_age)
def dumps(obj, key, salt, compress=False):
return django.core.signing.dumps(obj, key, salt, compress=False)
else:
def loads(s, key, salt, max_age=None):
raise NotImplementedError("This functionality requires django to be installed")
raise NotImplementedError(
"This functionality requires django to be installed"
)
def dumps(obj, key, salt, compress=False):
raise NotImplementedError("This functionality requires django to be installed")
raise NotImplementedError(
"This functionality requires django to be installed"
)
__all__ = ("BadSignature", "SignatureExpired", "loads", "dumps")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment