Island: add the ability to check if monkey document has parent and retrieve it from the model

This commit is contained in:
VakarisZ 2021-12-07 12:26:14 +02:00
parent 4fdd3370ca
commit 6dfa34a133
1 changed files with 16 additions and 0 deletions

View File

@ -21,6 +21,10 @@ from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURAT
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
class ParentNotFoundError(Exception):
"""Raise when trying to get a parent of monkey that doesn't have one"""
class Monkey(Document):
"""
This class has 2 main section:
@ -96,6 +100,18 @@ class Monkey(Document):
monkey_is_dead = True
return monkey_is_dead
def has_parent(self):
for p in self.parent:
if p[0] != self.guid:
return True
return False
def get_parent(self):
if self.has_parent():
Monkey.objects(guid=self.parent[0][0]).first()
else:
raise ParentNotFoundError
def get_os(self):
os = "unknown"
if self.description.lower().find("linux") != -1: