forked from p34709852/monkey
Island: add the ability to check if monkey document has parent and retrieve it from the model
This commit is contained in:
parent
4fdd3370ca
commit
6dfa34a133
|
@ -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
|
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):
|
class Monkey(Document):
|
||||||
"""
|
"""
|
||||||
This class has 2 main section:
|
This class has 2 main section:
|
||||||
|
@ -96,6 +100,18 @@ class Monkey(Document):
|
||||||
monkey_is_dead = True
|
monkey_is_dead = True
|
||||||
return monkey_is_dead
|
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):
|
def get_os(self):
|
||||||
os = "unknown"
|
os = "unknown"
|
||||||
if self.description.lower().find("linux") != -1:
|
if self.description.lower().find("linux") != -1:
|
||||||
|
|
Loading…
Reference in New Issue